EmbDev.net

Forum: µC & Digital Electronics reading from micro-controller


von (unknown) (Guest)


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.

: Moved by Moderator
von Hmmm (Guest)


Rate this post
useful
not useful
What do the data packets sent by the controller look like?

ReadLine() expects a newline (0x0a) character at the end of the line.

von Hmmm (Guest)


Rate this post
useful
not useful
And why are you spamming a totally unrelated URL to your employer's 
website? Is that how marketing works in India?

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.