Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crc16 modbus giving wrong result #7

Open
johnwick03 opened this issue Dec 6, 2018 · 1 comment
Open

crc16 modbus giving wrong result #7

johnwick03 opened this issue Dec 6, 2018 · 1 comment

Comments

@johnwick03
Copy link

johnwick03 commented Dec 6, 2018

I tried getting crc for hex string 08000001 using crc16.ChecksumIBM. But instead of 84C3 it is giving me 3226. This is my code:
data := []byte("08000001")
checksum := crc16.ChecksumIBM(data)
fmt.Println("\n checksum:", checksum)

@johnwick03 johnwick03 changed the title crc16 modbus is giving wrong result crc16 modbus giving wrong result Dec 6, 2018
@aliakseiz
Copy link

aliakseiz commented Mar 11, 2019

Replace with checksum := ^crc16.ChecksumIBM(data)
Modbus checksum should be calculated without XOR out. Take a look at Modbus test in this repository.

But still you will not get 0x84C3, because you're building CRC of chars array.

d := []byte("08000001")
c := ^crc16.ChecksumIBM(d)
fmt.Printf("checksum:%X\n", c) // checksum:F365

d = []byte{0x08, 0x00, 0x00, 0x01}
c = ^crc16.ChecksumIBM(d)
fmt.Printf("checksum:%X\n", c) // checksum:84C3

s := "08000001"
d, err = hex.DecodeString(s)
c = ^crc16.ChecksumIBM(d)
fmt.Printf("checksum:%X\n", c) // checksum:84C3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants