in reply to CRC off-by-one

$crc = crc16($a, $a + 32, $crc); ... for ($adr = $startadr; $adr <= $endadr; $adr++) {
Fencepost error. Should be $a+31, or $addr < $endaddr. Whether this fixes your problem, I don't know.