我在使用 PHP 生成 modbus CRC16 代码时遇到了很多麻烦。我在互联网上找到了很多不同的代码,但我已经尝试过,但由于某种原因我没有得到正确的结果。我找到了一个用于生成 CRC16-CCITT 的 PHP 代码。我已将查找表更改为 modbus CRC 对应表,但结果仍然不正确。代码如下。我还需要做什么才能将 CRC16-CCITT 代码转换为 CRC16-MODBUS 代码。
<?php
/*************************************************************************
* phpCrc16 v1.1 -- CRC16/CCITT implementation
*
* By Matteo Beccati <matteo@beccati.com>
*
* Original code by:
* Ashley Roll
* Digital Nemesis Pty Ltd
* www.digitalnemesis.com
* ash@digitalnemesis.com
*
* Test Vector: "123456789" (character string, no quotes)
* Generated CRC: 0x29B1
*
*************************************************************************/
/*
* Returns CRC16 of a string as int value
*/
function CRC16($str)
{
static $CRC16_Lookup = …Run Code Online (Sandbox Code Playgroud)