Processing of data received by the C#Serial Port

Asked

Viewed 163 times

1

When I read the data from the Serial port in C# and add in a String RxString i receive the following strings:

"??\u0002???? u0002???? u0002???? u0002???? u0002???? u0002????? u0002????..."

or

"???? ??? ??? ??? ???..".

The correct sequence would be integer numbers separated by space:

Example: "123 456 789 1023 0 12 02..."

Code where I receive the data from the Serial port:

string RxString;

private void Form1_Load(object sender, EventArgs e)
{
    SerialCOM.PortName = "COM6"; //comboBoxCOM.Text;
    SerialCOM.BaudRate = 9600; // Int32.Parse(comboBoxBR.Text);
    SerialCOM.Parity = Parity.None;
    SerialCOM.StopBits = StopBits.One;
    SerialCOM.DataBits = 8;
    SerialCOM.Open();        
    SerialCOM.DiscardOutBuffer();
    SerialCOM.DiscardInBuffer();
    timerDRAW.Enabled = true; //interval = 1ms
}

private void timerDRAW_Tick(object sender, EventArgs e)
{
    SerialCOM.DataReceived += new SerialDataReceivedEventHandler(SerialCOM_DataReceived);
}

private void SerialCOM_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort sData = (SerialPort)sender;
    {
        if(sData.BytesToRead >= 1) RxString += sData.ReadExisting();
        /...
    }
}

When I transmit the data of a Arduous for Serial port has some specific way of receiving the data?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.