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 & HelpElectronics,  Serial Library › Connecting to serial port in the draw() phase
Page Index Toggle Pages: 1
Connecting to serial port in the draw() phase (Read 1283 times)
Connecting to serial port in the draw() phase
Dec 26th, 2009, 7:46pm
 
I've written two simple sketches, one were I connect to a Serial port through the setup() phase, and the other were I do some scans first, and then I connect to a serial port in the draw() phase.

In the first case, Processing waits for the connection to be successful before running the rest of the code, but in the second, it runs the rest of the code before it event got a steady connection.

How can I control this? How can I wait for a solid connection before running the rest of the code?
Re: Connecting to serial port in the draw() phase
Reply #1 - Dec 27th, 2009, 12:04am
 
At first thought, test if your serial object is null.
(keep in mind I am not trying this as I type)
Code:
void draw() {
 ...
 if (readyForSerial) {
   mySerial = new Serial(this, "COM#", 9600);
   readyForSerial = false; //don't reconnect every frame
 }
 ...
 if (mySerial != null) {
   //do stuff
 } //else don't do stuff
}
Page Index Toggle Pages: 1