0

I'm currently working with 4 devices:

  • 1 Flow Meter
  • 3 Particle Counter
  • 1 Analog/Digital Converter
  • and 1 USB/RS485 Converter.

The Flow Meter is connected to Analog/Digital Converter; Analog/Digital Converter and the 3 Particle Counter is connected to USB/RS485 Converter. I've using serialPort1 and written a small method to read the SerialPort.

The SerialPort being read!

But unfortunately, I need to separate the string the get Particles Counters. The devices send the string in this format: ?01,00000,00000,00000,n/a,n/a I try to capture the string to separate in the commas, however so capture the end of the string or "n/a".

How to capture the entire string to variable and treat this variable in another method?

My method:

private void serialPort1_DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e)
{
if(serialPort1.DataBits==8)
    {
    RxString=serialPort1.ReadExisting();
    this.Invoke(new EventHandler(DisplayText));
    }
}

private void DisplayText(object sender,EventArgs e)
{
textBox1.AppendText(RxString);
}
crthompson
  • 15,653
  • 6
  • 58
  • 80
Ocaccy Pontes
  • 257
  • 1
  • 5
  • 14
  • Why do you test for serialport1.databits? When you get data in the serialport buffer, you can use a stringbuilder object to build the string, then parse the string for the data. Or use a threadsafe FIFO queue and add the received characters as they arrive right into the queue, then dequeue the characters in a function, not worrying about locking. An example is here: http://stackoverflow.com/questions/16335690/serial-port-reading-threads-or-something-better/16345503#16345503 – user2019047 Oct 03 '13 at 17:03
  • I did tests with the code of the link that you gave me. We have activity on the serial port and to see the leds the USB/RS485 converter. However the data does not appear in textBox. while (serialDataQueue.TryDequeue(out ch)) { // do something with ch, add it to a textbox // for example to see that it actually works textboxDataReceived.Text += ch; } Put a breakpoint inside private void readSearialDataQueue(){}. Not the flow passes through here. If flow is not here, not will release data on textboxDataReceived. – Ocaccy Pontes Oct 04 '13 at 12:06
  • have you checked that the received data is indeed added to the queue? Maybe a breakpoint in the datareceived handler will show that. And as always, showing your code will ensure more people responding. – user2019047 Oct 04 '13 at 16:23
  • I put the code in this new Question, please. http://stackoverflow.com/questions/19204353/how-to-optimeze-the-mount-array-from-serialport1-readexisting-in-c-sharp – Ocaccy Pontes Oct 06 '13 at 01:08

0 Answers0