Find out CRC or CHECKSUM of RS232 data

*爱你&永不变心* 提交于 2019-12-04 12:50:23

The answer was here: http://blog.sina.com.cn/s/blog_5a1d5bca0100bjvx.html

0xff - result from algorithm from above link and everything matches up. Took me 2 afternoons and the help I got here, but finally nailed it.

Of course I more or less understand what that code is doing thanks to the link posted by Gerhard. Thank you.

It is not a checksum or data XOR.
There are a few CRC options that you can try. The data you give does not give a positive result on any easy crc solutions.

Commmon 8 bit CRC are:
Name : poly : normal / reversed / reverse of reciprocal
CRC-8-CCITT : 0x8 + x2 + x + 1 : 0x07 / 0xE0 / 0x83
CRC-8-Dallas/Maxim (1-Wire bus) : x8 + x5 + x4 + 1 : 0x31 / 0x8C / 0x98
CRC-8 : x8 + x7 + x6 + x4 + x2 + 1 : 0xD5 / 0xAB / 0xEA
CRC-8-SAE : x8 + x4 + x3 + x2 + 1 : 0x1D / 0xB8 / 0x8E
CRC-8-WCDMA : x8 + x7 + x4 + x3 + x + 1 0x9B / 0xD9 / 0xCD

Implementation options to mix it up would be:
Normal or reverse data bytes, Initial value(0xff or 0x00), Final XOR on not and reverse CRC result before Final XOR.

For a CRC it must be on of these option unless they rolled their own.

To learn more A Painless Guide to CRC Error Detection Algorithms.

#Define CRCTBL1 0h005EBCE2613FDD83C29C7E20A3FD1F419DC3217FFCA2401E5F01E3BD3E6082DC
#Define CRCTBL2 0h237D9FC1421CFEA0E1BF5D0380DE3C62BEE0025CDF81633D7C22C09E1D43A1FF
#Define CRCTBL3 0h4618FAA427799BC584DA3866E5BB5907DB856739BAE406581947A5FB7826C49A
#Define CRCTBL4 0h653BD987045AB8E6A7F91B45C6987A24F8A6441A99C7257B3A6486D85B05E7B9
#Define CRCTBL5 0h8CD2306EEDB3510F4E10F2AC2F7193CD114FADF3702ECC92D38D6F31B2EC0E50
#Define CRCTBL6 0hAFF1134DCE90722C6D33D18F0C52B0EE326C8ED0530DEFB1F0AE4C1291CF2D73
#Define CRCTBL7 0hCA947628ABF517490856B4EA6937D58B5709EBB536688AD495CB2977F4AA4816
#Define CRCTBL8 0hE9B7550B88D6346A2B7597C94A14F6A8742AC896154BA9F7B6E80A54D7896B35
#Define CRCTBL0 CRCTBL1+CRCTBL2+CRCTBL3+CRCTBL4+CRCTBL5+CRCTBL6+CRCTBL7+CRCTBL8


Lparameters pcString

Local ;
    lnCRC8, ;
    lnIndex, ;
    lnx, ;
    lnByte

m.lnCRC8 = 0

For lnx = 1 To Len(m.pcString)
    m.lnByte  = Asc(Substr(m.pcString, m.lnx, 1))
    m.lnIndex = Bitxor(m.lnCRC8, m.lnByte)
    m.lnCRC8  = Asc(Substr(CRCTBL0, m.lnIndex + 1, 1))
Endfor

m.lnCRC8 = 0xff - m.lnCRC8

Return m.pcString + Chr(m.lnCRC8)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!