Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Does anybody know how to calculate the 16 bit Dallas/Maxim crc value using perl and perhaps Digest::CRC?
I have a text string of hexadecimal bytes (e.g. "142C00040000AFBD5E83") where the first 8 bytes is data and the last 2 is the crc. The example is actual data recived from the device. I have recived the same string more than once, so the crc value is proberbly correct.
Thanks in advance
Kim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dallas/Maxim crc
by roboticus (Chancellor) on Mar 13, 2013 at 13:23 UTC | |
Googling "dallas maxim crc" turned up a few links, one of which http://arduino.cc/forum/index.php?topic=37648.0;wap2 offers:
Just translate it to perl, and you're done... ...roboticus When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] |
|
Re: Dallas/Maxim crc
by anita2R (Scribe) on Nov 28, 2013 at 04:47 UTC | |
I came upon this post when looking for a Perl script to calculate an 8 bit crc for a Dallas/Maxim scratchpad data read. Although this post is old, there was no 'answer' at least not in Perl, so having created scripts for calculating the crc's I decided to post anyway. I managed to create a script for the 8 bit crc, and to respond to this post I modified the code to work for the 16 bit crc. I have only tested this on the one data/crc combination given in the question so I can't be sure it's correct. Anyway here it is & any feedback is welcome:
I hope that this script is of some use. I will shortly post the code for the 8 bit crc. The method of calculating the crc is slightly different to the code from 'arduino.cc/forum code', but in it's 8 bit format it works consistently | [reply] [d/l] |
by anita2R (Scribe) on Nov 28, 2013 at 13:16 UTC | |
As a follow-up to the script for the 16 bit crc, here is a script for the Dallas/Maxim 8 bit crc. The sample data & crc comes from a DS1822 1-wire digital thermometer. I use the code in a slightly modified format as a function in a larger program, with data and transmitted crc passed to the function, which returns 'OK' or 'Error' back to the main program.
| [reply] [d/l] |