title: Calculating CRC16 in Python for modbus
body: <p>Firstly, sorry! I am a beginner...</p>
  <p>I got the following byte sequence on a modbus: &quot;01 04 08 00 00 00 09 00 00 00 00 <strong>f8 0c</strong>&quot;. The CRC on bold on this byte sequence is correct. However, to check/create the CRC I have to follow the device especs that states:</p>
  <p><em>The error checking must be done using a 16 bit CRC implemented as two 8 bit bytes. The CRC is appended to the frame as the last field. The low order byte of the CRC is appended first, followed by the high order byte. Thus, the CRC high order byte is the last byte to be sent in the frame. The polynomial value used to generate the CRC must be 0xA001.</em></p>
  <p>Now, how can I check the CRC using crcmod?
  My code is:</p>
  <pre><code>import crcmod
  crc16 = crcmod.mkCrcFun(0x1A001, rev=True, initCrc=0xFFFF, xorOut=0x0000)
  print crc16(&quot;0104080000000900000000&quot;.decode(&quot;hex&quot;))
  </code></pre>
  <p>I tried everything but I can't get the &quot;f8 0C&quot; that is correct on the byte sequence...</p>