I don't frequent these forums - and I've just recently started working with Processing to work with Open Sound Control (OSC: oscP5 and netP5 libraries). I've done a search on these forums and I couldn't quite find any information that could help me resolve the issue I'm having. I hope someone has encountered something similar, as this is a little peculiar.
First I'll explain my setup. I am using a laptop running processing, which has 2 USB ports. On each USB port, I have an RGB controller circuit that I have created. The controllers read serial data (from FTDI driver), and controls an RGB led array accordingly. TouchOSC sends the OSC commands which tell my processing code which mode to select, and in turn which LEDs to turn on and how much. They are identical and both function properly.
On my TouchOSC layout, I have a slider that controls the red amount. So, whenever processing receives a red slider message:
...........
myPort.write(high nybble of red slider value);
myPort.write(low nybble of red slider value );
myPort2.write( high nybble of red slider value );
myPort2.write( low nybble of red slider value );
.....
Everything works fine for solid colors (i.e don't adjust the color percentage with a slider, just press a button and it sends a command for changing to a solid color).
However in this case - one of the RGB arrays changes brightness smoothly as I move the slider (as it should) , but the other one goes bezerk. It pulses at random brightness levels, but ends up at the same final desired brightness such that both arrays are at the same brightness level. The problem is not with the RGB controller. Switching ports causes the previously bad RGB array to function properly, and the one that used to work to go bezerk. I've also tried staggering the writes between ports, such that I write myPort(high) and myPort2(high), etc etc.
I am thinking this might be a problem caused by the two ports somehow sharing the same buffer, and the buffer not clearing out properly. I've tried myPort.clear() with no luck.
I have initialized the ports as follows:
import processing.serial.*;
myPort = new Serial(this, Serial.list()[2],9600);
myPort2 = new Serial(this, Serial.list()[3],9600);
Switching this to:
myPort = new Serial(this, Serial.list()[3],9600);
myPort2 = new Serial(this, Serial.list()[2],9600);
Causes the previously bad led array to function, and the other to operate as described above.
Do I need to run two separate instances of processing for this to function like I want it to? Or am I initializing/handling the serial buffer incorrectly? Or am I missing something extremely simple?