Home > Back-end >  A serial port communication, please help!
A serial port communication, please help!

Time:09-30

Via a serial port debug tool to read the following five data respectively, among them (30,31,32,33,34) is a regular incremental, but,80,83,82,85 (81), don't know is how to calculate, warrior, please help, thanks a lot!

FA 80 31 30 30 30 34 05 00 01 30 81 FC
FA 80 31 30 30 30 34 05 00 01 31 80 FC
FA 80 31 30 30 30 34 05 00 32 83 FC 01
FA 80 31 30 30 30 34 05 00 33 82 FC 01
FA 80 31 30 30 30 34 05 00 01 85 FC

CodePudding user response:

Is the custom communication protocol? Or general agreement? A serial port communication is more CRC16 and accumulative and validation

CodePudding user response:

Should be to CRC, but backward agreement difficulty is a little big ~ ~ ~ ~

CodePudding user response:

Don't know what kind of communication protocol, there are many kinds of CRC protocol? If you have a lot, please use gm help me explain, CRC16 concrete is how to calculate out ah, thank you very much!

CodePudding user response:

Give you a sticker used CRC16 algorithm example see

///////////////////////////////////////////////////////////
//16 bit CRC: according to the calculation, the slowest, taking up space at least
//note: the data flow is high first
///////////////////////////////////////////////////////////
The function CalCRC16 (data, CRC, genpoly: Word) : Word;
Var I: Integer;
The begin
//method 1: from XMODEM protocol
CRC:=CRC xor data;//(data SHL 8);
For I:=0 to 7 do
If (CRC and $0001) & lt;> 0 then//tests only highest
The CRC: (1) CRC SHR xor genpoly=1//that high displacement and exclusive or processing
Else CRC: CRC SHR=1;//otherwise only shift (passenger 2)
Result:=CRC;
{
//method 2: algorithm is somewhat different, but the result is the same
Data:=data SHL 8;//move to the high byte
For I:=7 downto 0 do
The begin
If (data xor (CRC) and $8000) & lt;> 0 then//tests only highest
The CRC: (1) CRC SHL xor genpoly=1//that high displacement and exclusive or processing
Else CRC: CRC SHL=1;//otherwise only shift (passenger 2)
Data:=data SHL 1;//processing under a
end;
Result:=CRC;

//method 3: from & lt;
For I:=7 downto 0 do
The begin
If (CRC and $8000) & lt;> 0 then
CRC:=(CRC * 2) xor genpoly//remainder CRC multiplied by 2 to CRC
The else CRC:=CRC * 2;
If (data and SHL I) (1) & lt;> 0 then
CRC:=CRC xor genpoly;//plus standard CRC
end;
Result:=CRC;
}

CodePudding user response:

What do you want to ask?

CodePudding user response:

The experience is still less help hat with this respect

CodePudding user response:

Thanks for your reply
Please give to the c + + builder warrior can directly use the code, thank you very much!
Better data FA 80 31 30 30 30 to 34 05 00 01 30 81 FC, the red 81 calculated directly, other data through the algorithm, many thanks! Thank you very much!

CodePudding user response:

refer to 7th floor wangyjhaha response:
thanks for your reply
Please give to the c + + builder warrior can directly use the code, thank you very much!
Better data FA 80 31 30 30 30 to 34 05 00 01 30 81 FC, the red 81 calculated directly, other data through the algorithm, many thanks! Thank you very much!


In c + + builder directly compiled pas files are generated HPP is ok,

CodePudding user response:

Exclusive or check, will check all bytes: an exclusive or, code standard is very simple I don't write,

Validation:
Open the Windows 7 calculator, set to programmer mode, shown as a byte, copy down the calculator should get the results
80 ^ ^ ^ ^ 30 30 31 30 34 05 00 ^ ^ ^ ^ ^ 01=31

CodePudding user response:

FA 80 31 30 30 30 34 05 00 01 30 81 FC
FA 80 31 30 30 30 34 05 00 01 31 80 FC
FA 80 31 30 30 30 34 05 00 32 83 FC 01
FA 80 31 30 30 30 34 05 00 33 82 FC 01
FA 80 31 30 30 30 34 05 00 01 85 FC

FA 80 31 30 30 30 34 05 00 01 84 FC==35 & gt; ?

FA 80 31 30 30 30 34 05 00 01 36 87 FC==& gt;
FA 80 31 30 30 30 34 05 00 01 86 FC==37 & gt;

CodePudding user response:

CRC check has the seeds of a custom code, each is different, such as the genpoly hongss post code, is a seed code, algorithm is basically the same, but the premise is you must know how seed code is,
So other people can't be directly calculated results for you
  • Related