multiple arduinos, separate Processing scripts

Howdy folks,
I have several Arduinos sending serial streams that I want to log in separate Processing scripts on the same PC (using PrintWriter objects).

I've tried to set the serial COM ports on each Processing script to log serialEvent data from the different Arduinos/COM ports, which works when each Processing script is activated independently (i.e. one logs data from one Arduino and the other logs data from the other board).

However when one is running previously, the second starts intercepting serial data from the first after it is run.

Not good... ("Don't cross the streams!" I keep hearing...)

Anyone have any hints or alternative approaches?
Thanks!

eR

Not good... ("Don't cross the streams!" I keep hearing...)

Good one. ;D

I don't speak Processing, but I'm pretty sure some processing ghost buster may show up to help. Offer them a cookie.

Lefty

When Processing starts, it gets a list of serial ports that it can listen to. How are you making the Processing application choose which serial port to listen to? (Incorrectly, I'm guessing, or you wouldn't be posting here.)

Post your code.

@PaulS
Thanks for your reply!

Hmmm... I probably did make some mistake, but I thought I took care of port assignment when initializing the serial port in the setup with "myPort = new Serial(this, Serial.list()[3], 9600);"
And for the other Arduino board/Processing script I specify the serial port corresponding to the other Arduino.
Anyway, here's the basic code.

////////////////START///////////////////////////
import processing.serial.*;    // import the Processing serial library
PrintWriter output;    // initialize the PrintWriter Java object

Serial myPort;    // the serial port

long time=0;    // initialize variable for the current time since program started
String trigTime;  // initialize variable for serial data from Arduino

void setup()
{
  // Create a new file in the sketch directory
  output = createWriter("testText.txt");
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[3], 9600);
  myPort.bufferUntil('\n');
}

void draw() {      //draw() can be empty, everything's in SerialEvent
}

void serialEvent(Serial myPort) {  // use serialEvent() because of intermittent Arduino data
  time = millis();    // see how long it's been since program started

  if (time < 1200000)   // conditional for length of trial
  {
    if (myPort.available() > 0) {  // when serial data is sent from Arduino

      // read serial data of trigger times (since start of this script) from Arduino
      trigTime = myPort.readStringUntil('\n');  // use readStringUntil() to make sure we get entire serial package

      // Write the Arduino data to a file
      output.print(trigTime);  // write the output to .txt file as string (will just be number in text)
      print(trigTime);  // print trigger times to this display
    }
  }
 
  else {
  output.flush(); // Write the remaining data
  output.close(); // Finish the file
  println("END TRIAL");
  exit(); // Stop the program
  }
}
////////END//////////////

As stated above, the other Processing script is setup with a serial stream from the port corresponding to the other Arduino, and when each script is run alone, it reads from the correct Arduino. It is only when they are run together that the second one starts capturing the serial stream from both ports.

I've also tried naming the ports ("myPort1 vs myPort4") differently in the two scripts but this doesn't seem to help. Otherwise, all calls for information from serial in each script seems to refer back to the serial stream I defined in setup, so therefore I don't think I have to subsequently specify this (but maybe that's why this isn't working).

Thanks for your help!
eR