Home > Net >  [new turn] under the c # how to decode a machine to send data
[new turn] under the c # how to decode a machine to send data

Time:11-23

Machine will be 24 bits of data, through a serial port, eight at a time, divided into eight high, in the eight, low 8, a total of 3 times, sent to PC, each receiving data is similar to "zero e 2 f 68", how to restore after you receive the serial data into a single decimal?


 

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:

BitConvert

CodePudding 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 deal

CodePudding user response:

You are using a byte array receiving of [4] then use bitconvert. Toint32 (byte []) can be converted to data type int
  •  Tags:  
  • C#
  • Related