adding crc to the binary data
claudegel opened this issue · comments
How to automatically append the crc at the end of the binary data.
ex. b'\x55\x00\x02\x0012' crc8 = 3b
need to get b'\x55\x00\x02\x0012\x3b'
Hi, can you try out this?
data = b'\x55\x00\x02\x0012'
crc = hash.digest()
data_with_hash = data + crc
If it works, it would be so great if you contributed the description to the README file as you know best how to formulate it for you.
Happy to hear from you :)
Le Sun, 17 Feb 2019 00:13:24 -0800
Nicco Kunzmann <notifications@github.com> a écrit:
Hi, can you try out this?
```
data = b'\x55\x00\x02\x0012'
crc = hash.digest()
data_with_hash = data + crc
```
If it works, it would be so great if you contributed the description
to the README file as you know best how to formulate it for you.
Happy to hear from you :)
Hi,
thank you. I finally got it to work. The crc is appended to the data
and sent to the device succesfully.
```
import crc8
def crc_count(bufer):
hash = crc8.crc8()
hash.update(bufer)
return hash.hexdigest()
#build the request
Pre = "\x55\x00"
length = "\x02"
data = "\x0012"
buf = Pre+length+data
binbuf = bytes(buf, 'ascii')
crc = binascii.unhexlify(bytes(crc_count(binbuf), 'ascii'))
send_ping = binbuf+crc
```
This send the correct binary data and the device reply.
Thank you
--
Claude Gélinas agr
Phyto Ressources Inc.
So, if this is fine with you, I close this. You can still comment if you like. You contribution to the documentation is still welcome 👍