c#串口接收到的数据怎么判断是完整的,然后提取出数据中我要用的数据。
privatevoidserialPort1_DataReceived(objectsender,System.IO.Ports.SerialDataReceivedEv...
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
byte[] a = new byte[1024];
//int Count;
int Count = this.serialPort1.Read(a, 0, 50);
//string s = serialPort1.ReadLine();
string data = null;
int i = 0;
for (i = 0; i < 8; i++)
{
data += a[i].ToString ("x")+ " ";
}
textBox2.Text = id +" "+ data;
a的数据里面有头有尾,头是两个oxaa,尾是一个oxaa,中间数据是要用的 展开
{
CheckForIllegalCrossThreadCalls = false;
byte[] a = new byte[1024];
//int Count;
int Count = this.serialPort1.Read(a, 0, 50);
//string s = serialPort1.ReadLine();
string data = null;
int i = 0;
for (i = 0; i < 8; i++)
{
data += a[i].ToString ("x")+ " ";
}
textBox2.Text = id +" "+ data;
a的数据里面有头有尾,头是两个oxaa,尾是一个oxaa,中间数据是要用的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询