C# SerialDataReceivedEventHandler triggered without serialport connected

时间:2016-08-31 12:17:51

标签: c# serial-port

I'm implementing a GUI in order to transmit a command to a device and to recive feedback from it. Even if I have no device connected on the serial port, when I transmit data I get back the same data I've sent. That is, the SerialDataReceivedEventHandler is activated.

These are the serialPort.write() commands I use

 ......
 serialPort1.Write("on\r");
 Thread.Sleep(500);
 serialPort1.Write("GL\r");
 Thread.Sleep(500);
 serialPort1.Write("of\r"); 
 ......

And this is the associated EventHandler

this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);          

After each write, serialPort1_DataReceived is activated and with a serialPort1.ReadLine() I get the same data I have written to the serial port.

How is possible? It is like I'm sending data to myself. My PC has no device connected. When I connect the serial port to the device, I get back the real answer.

0 个答案:

没有答案