Serial Port Communication Problem

  • Thread starter Thread starter MSA_Aydn
  • Start date Start date
M

MSA_Aydn

Guest
Hi everyone,

I am having a problem with serial port communication in c #. There is a gas meter that I communicate with.

when I send data to the device, a standard packet sends a reply. I get the response from serial port with datareceived event.

this datareceived function is shown below.

private void SerialPortFlowMeter_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
readNumberOfBytes = serialPortFlowMeter.Read(readBytesFromSerialPort, 0, 100);
this.BeginInvoke(new LineReceivedEvent(LineReceived), receivedData);

}

If I write the data to the serial port as a single line, the data is read from the serial port without problems. in that;

serialPortFlowMeter.Write("b\r");

but I have to send the data to the serial port one after another like this;

serialPortFlowMeter.Write("b\r");

serialPortFlowMeter.Write("c\r");

serialPortFlowMeter.Write("a\r");

When I send the data like this one after another, there is a corruption in the incoming data.

the problem persists when I add a small delay between each write function.

serialPortFlowMeter.Write("b\r"); Thread.Sleep(500);

serialPortFlowMeter.Write("c\r"); Thread.Sleep(500);

serialPortFlowMeter.Write("a\r");Thread.Sleep(500);

what can i do for solution.
Thank you from now.

M.A.

Continue reading...
 
Back
Top