We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controP5 with serial won't load in browser applet
Page Index Toggle Pages: 1
controP5 with serial won't load in browser applet (Read 666 times)
controP5 with serial won't load in browser applet
Feb 26th, 2009, 12:45pm
 
Hiya,

Firstly, I'm soo new to this.

I've noticed that when I write sketches they run fine when I click the play button. But when I export them to web format, I just get a blank canvas?

Also when I click on the java executable it created it says..

can't find class program will exit.

Am I missing a vital step here?

Here is a copy of the sketch I am trying to export:


import processing.serial.*;

// The serial port:
Serial port;

import controlP5.*;

ControlP5 controlP5;

int myColorBackground = color(0,0,0);

void setup() {
 port = new Serial(this, Serial.list()[2], 9600);
 size(400,400);
 frameRate(30);
 controlP5 = new ControlP5(this);
 controlP5.addBang("bang",40,200,120,40);
 for(int i=0;i<4;i++) {
   controlP5.addBang("bang"+i,40+i*80,100,40,40).setId(i);
 }
 controlP5.controller("bang").setLabel("changeBackground");
}

void draw() {
 background(myColorBackground);
}

void bang() {
 int theColor = (int)random(255);
 myColorBackground = color(theColor);
 println("a bang event. setting background to "+theColor);
}

void controlEvent(ControlEvent theEvent) {

 if (theEvent.controller().id()== 0){
   println("hello!!!");
   port.write('A');              //send A to serial port
 }
 else
 {
   port.write('a');              //send a to serial port
 }
 println(
 "## controlEvent / id:"+theEvent.controller().id()+
   " / name:"+theEvent.controller().name()+
   " / label:"+theEvent.controller().label()+
   " / value:"+theEvent.controller().value()
   );
}



Thanks in advance,

Dan.

Re: controP5 with serial won't load in browser app
Reply #1 - Feb 26th, 2009, 1:00pm
 
I don't know for the export to application step (what is your system?), but even if you could export to applet, I am pretty sure it won't work: first, Java have probably security locks to access low level devices like that from the browser, second it is utterly non portable (what is connected on the serial port of the user? if even they still have a serial port!).
Re: controP5 with serial won't load in browser app
Reply #2 - Feb 26th, 2009, 1:16pm
 
Thanks for speedy reply! When I have my sketch loaded in the processing IDE, I click on the export button >|

Then it writes a whole bunch of stuff to a folder which I presume is the contents for a web page that will display your sketch.

When I click on the index.html document it loads up a web page which has info about my sketch and a big blank square which I would expect to show my applet (I think that's what it's called?)

(not that it helps but) Here is the address to the page on my local machine:
file:///C:/Documents%20and%20Settings/Daniel%20Thompson/My%20Documents/Processin
g/bang_to_serial_Example_v001_001_dt/applet/index.html

I am on windowsXP service pack 2. I'm sending serial info to my arduino card via USB.

As I mentioned before the application works fine when I run it from the IDE, just not from a browser?
Re: controP5 with serial won't load in browser app
Reply #3 - Feb 28th, 2009, 3:02am
 
Upon further investigation I discovered that the Serial command works only within an application and not for a web app Sad

It was this line in the code that was breaking the web app:
 port = new Serial(this, Serial.list()[2], 9600);

Then I went to read the docs. Yes I actually used my brain!
http://processing.org/reference/libraries/serial/Serial.html

Down the bottom of the page it says:
Usage  
Application

So I guess that means application only and not web? Can anyone confirm this for me?

Thanks,

Dan.
Re: controP5 with serial won't load in browser app
Reply #4 - Feb 28th, 2009, 9:50am
 
Again, why do you want to use in on the Web?
If people have the same device as you, they can probably download the jar and run it, no? Or even just run the sketch if they have Processing.

Perhaps you can make it run on the Web if that's really what you want, but like all applets using low level system services, the applet have to be signed. See the corresponding Hacks.
Re: controP5 with serial won't load in browser app
Reply #5 - Feb 28th, 2009, 12:36pm
 
Hey thanks for confirming. When I started this thread I wasn't sure what the problem was. When I finally figured out it was serial library, I thought crap I've probably posted this in the wrong place!

Then I searched through the Electronics,Serial post and found well, exactly what you just mentioned about signing. Sorry for being such a newb.

To be honest I wasn't really thinking about final application. I just saw that the export button wasn't doing what it should and jumped the gun to find out why.

Eventually I think it would be cool to make a gui for an iphone or touchscreen device to control Arduino. Not sure how these devices work with Java yet? Not even sure if serial is required for wireless transmission?

For now I'm just happy to have a simple GUI that sends arguments to my Arduino board's hardcode. That way I can get different results without having to hardcode the Arduino everytime I want to make a slight change.

Anyways, that's the long and the short of it really,

Thanks for your help!

Dan.
Page Index Toggle Pages: 1