从serialport接收数据 [英] receiving data from serialport
问题描述
从serialport接收excel表数据,当我收到它时,它显示完整的行。
接收数据的格式如下:
$ POST,T121,c123,raj,2000,200,12 / 11 / 2013,1800#$ POST,T122,c122,thilak,3000,300,12 / 10 / 2013,2700#$ POST,T123,c123,nagendra,2000,2000,11 / 09 / 2013,0#
但我需要逐行阅读。$ - >行开头# - >行结束
阅读后数据我需要放在另一张excel sheet的相应列中。这是分隔符
这里是代码:
am receiving excel sheet data from serialport, when i was received , it's displaying complete rows.
receiving data is in following format:
$ POST,T121,c123,raj,2000,200,12/11/2013,1800 # $ POST,T122,c122,thilak,3000,300,12/10/2013,2700 # $ POST,T123,c123,nagendra,2000,2000,11/09/2013,0 #
but i need to read row by row .$ -->start of row #-->end of row
After reading data i need to place in corresponding column of another excel sheet.here , is the delimeter
here is the code:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
Thread.Sleep(50);
byte[] buffer=new byte[serialPort1.BytesToRead];
serialPort1.Read(buffer,0,buffer.Length);
string s = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
MessageBox.Show(s);
}
推荐答案
POST,T121,c123,raj,2000,200,12 / 11 / 2013,1800#
POST,T121,c123,raj,2000,200,12/11/2013,1800 #
POST,T122,c122,thilak,3000,300,12 / 10 / 2013,2700#
POST,T122,c122,thilak,3000,300,12/10/2013,2700 #
POST,T123,c123,nagendra,2000 ,2000,11 / 09 / 2013,0#
但我需要逐行阅读。
POST,T123,c123,nagendra,2000,2000,11/09/2013,0 #
but i need to read row by row .
这篇关于从serialport接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!