Re: Need a sysRPL CRC16 routine.



On Tue, 03 Apr 2007 13:46:00 -0500, dot wrote:

What type of object do you mean by "message"?

The CRC16 is needed to satisfy the modbus message protocol. There is
a string of hex digits (depending on the modbus message) which will
need to be processed, and the resulting CRC16 values added in big
endian fashion (least significant byte then most significant byte).
The modbus message string becomes one long hex string.

Isn't the built-in hardware CRC that very same CRC-16?

It does not seem to be. The test message "0207" yielded 5B04h
and the reverse string, "0702" yields 0CA9h.
I need to end up with 1241h for the valid test message CRC16.

What object type was each "message," how did you create it,
and what internal function did you use for CRC?
("yielded" means when you did what?)

Even if you constructed a proper 2-byte hex string as input
(which can't be done via UserRPL), neither the BYTES nor CRC
nor OCRC etc. commands can be used as-is, because they
start performing CRC on a *prefix* to those actual bytes
(BYTES starts at the prolog and goes to the end of the object;
CRC starts at the "length" field and stops 4 nibbles short
of the end of the object, if the AUR is correct -- the latter
seems to have been specially designed to compute a library CRC).

I suppose that all might be done upon hex strings
(very slowly), but it sure would be nice to have
a straightforward *ML* function for the CRC
of an arbitrary *string* (no prolog, no length,
just the string itself) -- in general, this should
also accommodate "odd-nibble" strings and general hex strings,
whose internal structures are all identical
[prolog, length in nibbles (including length field itself), data]

Note that "user" binary objects are also hex strings,
but are fixed-length (16d nibbles of data):

#123456789ABCDEF0h \->H ==> E4A20 51000 0FEDCBA987654321
#1234567h \->H ==> E4A20 51000 7654321000000000

OTOH, "ABC" BYTES DROP \->H ==> E4A20 90000 7DC9 [four nibbles only]

And of course "ABC" \->H ==> C2A20 B0000 142434

So, umm, would "ABC" in my computer have the same or different CRC-16?

[r->] [OFF]
.



Relevant Pages

  • Re: How can I convert an 8 character Hex word to binary for a look
    ... In Excel a hex string is evaluated as a text string because it contains both ... if you have hex strings of 8 chars and only need to do a lookup based on ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Generating a MAC using a pre-shared key
    ... not coming back the same as the third-party vendor's hmac result. ... When I am creating a MAC for a String, ... between byte arrays and hex strings. ...
    (comp.lang.java.security)
  • Re: sum of binary numbers
    ... And if 8.5 is not an option, use binary scan to get a string of hexadecimal digits, write yourself a little proc to sum the two hex strings, and binary format to turn it back into a binary number. ...
    (comp.lang.tcl)
  • Re: Shorter checksum than MD5
    ... CRC algorithms were ... within that arithmetic, the CRC of a string is ... def crc(s, salt): ... 'The probability of the changed dada having the same CRC32 is 1/2**32' ...
    (comp.lang.python)
  • Re: Module philosophy
    ... optionally add convenient methods to String and Fixnum too. ... but it's true that I might forget to remove that crc. ... CrcString and CrcSocket which returns CrcStrings. ... probably not going to extend if you include. ...
    (comp.lang.ruby)