Hi Vasile,

In the virtual_wire library I do the following CRC calculation. A bit different 
from yours.

-- Calculate new crc over given data. Formula is:
-- Xexp16 + Xexp12 + Xexp5 + 1
function _vw_calc_crc(word in crc, byte in data) return word is
var word data_2
  data = data ^ byte(crc & 0x00ff)
  data = data ^ (data << 4)
  data_2 = word(data)
  return (((data_2 << 8) | (crc >> 8)) ^ (data_2 >> 4) ^ (data_2 << 3))
end function

Kind regards,

Rob

________________________________
Van: [email protected] <[email protected]> namens vsurducan 
<[email protected]>
Verzonden: dinsdag 6 augustus 2024 11:37
Aan: [email protected] <[email protected]>
Onderwerp: [jallib] CRC16 implementation?

Hi Rob,
Is there any CRC16 implementation example? DS18B20 library has a CRC8 
implemented, but only for bit checking.
I need a CRC16 computation for reading a  MODBUS slave. The polynomial 
generator is X16+X12+X2+1 and the value for computation 0xA0001.

The C implementation for CRC16 MODBUS seems to be this one:
https://www.modbustools.com/modbus_crc16.html
and an application library here:
https://github.com/mandulaj/PZEM-004T-v30/blob/master/src/PZEM004Tv30.cpp

The problem is that translating this C to jal seems very painful...
I can find each CRC value for each needed command by running a MODBUS software, 
but the CRC values will be different for each slave address and/or numbers of 
bytes to be read from one particular slave...which is inconvenient.

thank you,
Vasile
--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/CAM%2Bj4qvE3tUP%2BuKwiPNxNcWLpvi_4uR69fETm59z4cGFS_30zA%40mail.gmail.com<https://groups.google.com/d/msgid/jallib/CAM%2Bj4qvE3tUP%2BuKwiPNxNcWLpvi_4uR69fETm59z4cGFS_30zA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/GVXP195MB1637A05519FEAED5F5BE8E94E6BF2%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM.

Reply via email to