On C# - How to capture the Serial Port received data to Global Variable?

Hi Guys.
I've using serialPort and written a small method to read the SerialPort. The SerialPort being read!  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, but unfortunately, so capture the end of the string or "n/a". How to capture the entire string to global variable and treat this variable in another method?
Thanks in advance
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);
}

Open in new window

ocaccyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Minh Võ CôngCommented:
In serialPort1_DataReceived function you can implement like:

void loop(){
  if(Serial.available() > 0){
    int i = 0;
    unsigned char data = 0;
     while(Serial.available() > 0){
       data = Serial.read();
       if(i < buffersize){
        buffer[i] = data; //put all data into buffer until if fills
        i++;
       }
     }
     for(int j = 0; j < i; j++){
       Serial.print(buffer[j]); //print buffer characters
     }
  }
  //delay(10);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ocaccyAuthor Commented:
Thank you, this is the Best Solution!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.