I'm handling a caller id serial device and write the following program:
serialPort = new SerialPort("COM7", 19200, Parity.None, 8, StopBits.One);
serialPort.DataReceived += serialPort_DataReceived;
serialPort.RtsEnable = true;
serialPort.Encoding = Encoding.ASCII;
serialPort.Open();
void serialPort_DataReceived(object s, SerialDataReceivedEventArgs e)
{
byte[] data = new byte[serialPort.BytesToRead];
serialPort.Read(data, 0, data.Length);
Console.WriteLine(Encoding.ASCII.GetString(data));
}
At first that I receive a call, the event fires perfectly and the result is: "A0101181456926E"
The problem is the subsequent events... next time that I make a call, the event serialPort_DataReceived
fires a lot of times each one with 1 char.
Is there any property to set or method to invoke to solve this behaviour?
ps. If I comment the line serialPort.RtsEnable = true;
, I don't receive any subsequent event.