reading from micro-controller

OP Guest #5395407
Rate this post
• ▲ useful
▼ not useful
I have a Arduino micro-controller . The micro-controller works(i have an 
app that shows me the the micro-controller 'spits' out data. The thing 
is that i have implemented some code ( from 
http://www.c-sharpcorner.com/uploadfile/eclipsed4utoo/serialportcommunication12082008111137am/serialportcommunication.aspx 
| https://mindmajix.com/emc-san-storage-training ) :

Here i initialize the 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 the listening handler :

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 .

The COM port is COM17 and the port opens ( a led on the micro-controller 
shows it ). Any idea why the operation timed out ?

i.e. The program loaded into the micro-controller is set to 'shoot' data 
at 1 second.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.