Change serial ports during runtime.

Hi Id like to know if its possible to change serial ports during runtime, or as a menu selection before the program runs, Im unsure how to go about this but its something id like to implement in my program.
I thought about the usual dropdown box thats in countless programs, but that wont work in processing. How could I go about having com port selection in processing.

Kind Regard
DirtGambit

Do you want to change baudrate? just call Serial.begin() again,
Note: flush all buffers to prevent half bytes send at different speeds.

DirtGambit:
Hi Id like to know if its possible to change serial ports during runtime, or as a menu selection before the program runs, Im unsure how to go about this but its something id like to implement in my program.
I thought about the usual dropdown box thats in countless programs, but that wont work in processing. How could I go about having com port selection in processing.

Kind Regard
DirtGambit

Change baud rate in a PC Processing program, or change the baud rate inside a Arduino program?

If the latter then you can use the Serial.end() command and then reopen with Serial.begin(newBaudrate); command.

If using a mega board then the above applies to the first Serial port (the one that wires to the USB serial channel, but also you can use:

Arduino Mega only:
Serial1.end()
Serial2.end()
Serial3.end()

Lefty

Im not worried about the Baud rate, just restart the serial on another COM port like COM1 COM2 COM3 without coming out of the program.

You want one instance of the Processing application to be able to talk to more than one Arduino, but only one at a time?

If that is not the case, why would the com port that the Arduino is on change during the execution of the Processing app?

My friends computer has his arduino on COM4, if I start my program on his comp no data will come through as my processing app is looking for COM3, id like to change the com port to suit my friends computer without having to recompile and change COM3 to COM4 within the processing IDE. All id like to do is take my app to his house, run the exe select the com port then the data will come through. Sorry if my questions were a bit ambiguous.

In retrospect to the original post, it does include "How could I go about having com port selection in processing." which I think sums up what Im trying to do.

regards

In retrospect to the original post, it does include "How could I go about having com port selection in processing." which I think sums up what Im trying to do.

Would that then not be better asked on the Processing.org forum? http://forum.processing.org/

Lefty

Yeah Im going to go and register there and make a post, id like to have this ability in my application, its not like its a functional requirement or anything, its just going to make my app a bit more usable among friends who wont have the same configuration as me.

One thing you could do is have the Processing application try all available ports, until it gets a response. You'll need to wait long enough after opening the port for the Arduino to reset and it will need to send serial data in setup() to tell Processing it is ready.

Alternatively, you could create buttons for each port in the list, and have the user pick the correct button.