reading from micro-controller

OP Guest #5395407
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.
Guest
What do the data packets sent by the controller look like?

ReadLine() expects a newline (0x0a) character at the end of the line.
Guest
And why are you spamming a totally unrelated URL to your employer's 
website? Is that how marketing works in India?

Reply

A question of your own? This thread is over 8 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

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.