添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
急躁的煎鸡蛋  ·  XMLHttpRequest·  2 月前    · 
玩滑板的黄花菜  ·  GitHub - ...·  2 月前    · 
火爆的电影票  ·  GitHub - ...·  2 月前    · 
悲伤的熊猫  ·  d3.js v3 vs d3.js ...·  2 天前    · 
眼睛小的盒饭  ·  Llama2 ...·  1 年前    · 
气宇轩昂的大海  ·  如何在fluent FFMPEG ...·  2 年前    · 
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; // Handler 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.
  •