Bit of Help with processing, splitting received serial string

I am trying to split data incoming from a sensor and send it to pachtube. The string that gets sent over serial for example would look like

25.00,40.00

I am trying to split this into 2 variables Humidity=25 and Temperature=40. Also sometimes when there is bad reception it sends garbled characters so i want it to ignore those. Only accepting serial inputs that are 11 characters long. I cant seem to get my code working though in processing, here is my code so far:

import processing.serial.*;
import cc.arduino.*;

import eeml.*;

Arduino arduino;
float myValue;
String inBuffer = null;  // one line of data from serial port

DataOut dOut;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);

dOut = new DataOut(this, 5210);

dOut.addData(0,"Humidity, Temperature");

}

void draw()
{
int[] dat; // array of numbers read in on one line from serial port

 // if (inBuffer != null) {  // wait for new data on the serial port
 if (inBuffer != '\n') {
  if (inBuffer.length == 11) {
    
    print("SERIAL:" + inBuffer);  // show the line of serial input
    dat = int(split(inBuffer, ','));  // parse comma-separated number string into numbers
    println("Humidity:" + dat[0] + "% Temperature:" + dat[1] + "C");
  }
}
 }
void onReceiveRequest(DataOut d){
d.update(0, myValue);
}

I am trying to split data incoming from a sensor and send it to pachtube. The string that gets sent over serial for example would look like

25.00,40.00

I am trying to split this into 2 variables Humidity=25 and Temperature=40.

But, 25.00 and 40.00 are not ints. They are floats.

Where do you actually receive serial data?

The serial code is from an example included with processing

/**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup() 
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  background(255);             // Set background to white
  if (val == 0) {              // If the serial value is 0,
    fill(0);                   // set fill to black
  } 
  else {                       // If the serial value is not 0,
    fill(204);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}

The code is simple and reads 1 or a 0 from the com port and changes the background depending which value is recieved. It should not be hard to change this code for my purposes instead of reinventing the wheel. However I am having problems going about the task of parsing the data recieved from the com port coming from my arduino mega.

I just need help splitting the string 25.00,40.00 into 2 strings of 25.00 and 40.00 and I can manage from there manipulating it into integers or floats. My main problem is sometimes the serial data looks like this: ( because of transmision errors (data is being collected by the mega over RF))

25.00,40.00
24.00,40.00
% 30.00 , 45.0 0
25.00,41.00

or something similar with a line of garbage here and there. I need a way to make the program discriminate the incoming serial data to reject lines that arent the proper lengths.

You could try something simple like below.

//zoomkat 11-8-11 simple delimited ',' string parce 
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 0022"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,
  while (Serial.available()) {
    delay(1);  //small delay to allow input buffer to fill
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      break; //breaks out of capture loop to print readstring
    }  
    readString += c; //makes the string readString
  }

  if (readString.length() ==5) {
    Serial.println(readString); //prints string to serial port out

    readString=""; //clears variable for new input
  }
}

I just need help splitting the string 25.00,40.00 into 2 strings of 25.00 and 40.00 and I can manage from there manipulating it into integers or floats. My main problem is sometimes the serial data looks like this: ( because of transmision errors (data is being collected by the mega over RF))

    dat = int(split(inBuffer, ','));  // parse comma-separated number string into numbers

The comment is right. The split function does just that. The resulting array of strings is then passed to the int function, which looks at "25.00" and says "Hmmm, not an int...", and it looks at "40.00" and says "Hmmm, not an int...".

Now it should not take a rocket scientist to look at that line of code and see what needs to be changed.

Now, that assumes that there is code that is not in your first post, like the serialEvent() handler. If that code doesn't exist, then you are never actually valuing inBuffer. You can use code from zoomkat's example, but the serial data collection actually belongs in a serialEvent(Serial pSerial) method, rather than draw(). The value collect in serialEvent() can be processed there, or in draw().