I have an Arduino microcontroller. The microcontroller works (I have an application that shows me that the microcontroller spits out data. The fact is that I implemented some code (from http://www.c-sharpcorner.com/uploadfile/eclipsed4utoo/serialportcommunication12082008111137am/serialportcommunication. aspx ):
Here I initialize SerialPort
_serialPort = new SerialPort("COM17", 19200, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
_serialPort.ReadTimeout = 1000;
_serialPort.WriteTimeout = 1000;
_serialPort.Open();
And here I have a listener:
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(1000);
string data = _serialPort.ReadLine();
this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
}
But I get this error: The operation has timed out.at string data = _serialPort.ReadLine();in the handler.
COM port COM17 and the port opens (the LED on the microcontroller is displayed). Any idea why the operation was timed?
i.e. The program downloaded to the microcontroller is configured to "take" data after 1 second.