这些数据如何处理得到我想要的数据重量,假如我要取10个字节,开始为02 结束为31 如何处理这些数据,数据源源不断的来,我应该怎么弄?
本人有点笨,最好用代码说话!
本人代码:
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int count = serialPort1.BytesToRead;
//string Text = serialPort1.ReadExisting();
//int count = serialPort1.ReadBufferSize;
byte[] data = new byte[count];
int bytesRed= serialPort1.Read(data, 0, count);
foreach (byte item in data)
{
if (radioButton1.Checked)
{
s += Convert.ToChar(item);
}
else
{
s += ByteToHexString(item);
}
}
if(this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate{this.textBox1.Text=s;}));
}
else
{
this.textBox1.Text=s+" ";
}
text = DecimalDex(data);
}