********** (高手请进) 串口 返回数据 的解析问题, 急!!!急!!!!急!!!!
我写了一个串口通信的程序。
发出数据
private void Form1_Load(object sender, System.EventArgs e)
{
if(this.axMSComm1.PortOpen==false)
{
this.axMSComm1.PortOpen=true;
}
this.axMSComm1.RThreshold=18;//当接收缓冲区达到 18 个字符时,引发接收事件
this.axMSComm1.InputLen=18;//设置 由串口读入 的字符串长度
}
////*********** 以下为发数据 ************/////
byte[] sendByte = {0xFE,0xFE,0xFE,0xFE,0x68,0x01,0x00,0x01,0x01,0xB1,0x05,0x3C,0x00,0x00,0x00,0x00,0x00,0x16};
this.axMSComm1.Output=sendByte; //发送数据 ,单片机 收到数据后 原样返回。
//////********* 接收、解析数据 ***********/////
private void axMSComm1_OnComm(object sender, System.EventArgs e)
{
if(this.axMSComm1.CommEvent==2)//若返回 指定字符长度数时(此例制定为18) 激发此事件
{
//MessageBox.Show("收到返回数据 !!!");
}
}
**************************** 对于以上 收到的数据 this.axMSComm1.Input 的处理不知道该怎样做。
我使用 MessageBox.Show("返回数据的类型:"+this.axMSComm1.Input.GetType().ToString()); 得出 this.axMSComm1.Input 为string 型的。当使用 MessageBox.Show("返回数据的类型:"+this.axMSComm1.Input(1)) 时确报错。
大家帮忙想想 如何 对返回数据进行处理。。
相关信息请参考:
http://community.csdn.net/Expert/topic/4701/4701839.xml?temp=.2950251