Private void serialPort1_DataReceived (object sender, System. IO, Ports, SerialDataReceivedEventArgs e)
{
Byte [] data=https://bbs.csdn.net/topics/new byte [serialPort1 BytesToRead];//define the buffer, because a serial port event triggers that may receive more than one byte
SerialPort1. Read (data, 0, the data Length);
Form1_Paint (data);
}
CodePudding user response:
BitConvertCodePudding user response:
How to define protocol format?CodePudding user response:
Is to do a protocol analysis software, a detailed analysis of your agreement, find rules, such as your agreement on whether the message frame frame head, characters, etc., the first to understand,CodePudding user response:
Not set communication protocol, it is a simple three data coming together, and then need to take the first data * * 256 + 65536 + second data third data and then deposit the value to another in an array,CodePudding user response:
Data analysis is in accordance with the agreement, such as what you said "the first data * 65536 + the second data * 256 + third data and then deposit the value to another array" this is a dealCodePudding user response:
You are using a byte array receiving of [4] then use bitconvert. Toint32 (byte []) can be converted to data type int