Link to home
Start Free TrialLog in
Avatar of ocaccy
ocaccyFlag for Japan

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Thank you, this is the Best Solution!