I've a question to ask.
I'm wondering that the DataReceived event is automatically raised
whenever
a data comes from serialPort? I've read but couldn't find info here:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived.aspx
[
^
]
I've written a little program to read data every 3 seconds from serial port, but that doesn't work quiet well.
The code is below:
string
buffer;
SerialPort sp =
new
SerialPort(
"
COM1"
);
sp.BaudRate =
9600
;
sp.Handshake = Handshake.None;
sp.DataReceived +=
new
SerialDataReceivedEventHandler(DataReceivedHandler);
private
void
serialPort1_DataReceived(
object
sender, System.IO.Ports.SerialDataReceivedEventArgs e)
buffer= sp.ReadExisting();
I don't want to use Timer, because the data doesn't always arrive in 3 second intervals. So, I can't get precise datas.
I know this's a simple question, but I'm stuck...
Any idea how to read with intervals?
My best regards...
If you want to read at specific intervals, then use a Timer.
If you want to process data as it comes in, use DataRecieved.
But be aware that DataReceived is fired every time a byte arrives - so the data you read is likely to be a single character each time, and "buffer" will never hold an entire message if you overwrite it every time you handle the event.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.