Skip to main content

crc16

Project description

crc16

介绍

查表法实现crc16算法.参数模型是CRC-16/MODBUS 多项式是8005。

API

"""
计算校验和.参数模型是CRC-16/MODBUS 多项式是8005,返回值是高字节在前的16位校验值
"""
def checksum(data: bytearray) -> int

示例

class _UnitTest(unittest.TestCase):
    def test_case1(self):
        data = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9])
        self.assertEqual(crcmodbus.checksum(data), 0x0eb2)

    def test_case2(self):
        data = bytearray([3, 1, 4])
        self.assertEqual(crcmodbus.checksum(data), 0x8193)

    def test_case3(self):
        data = bytearray([0x19, 0x89, 0x56])
        self.assertEqual(crcmodbus.checksum(data), 0x47a9)


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(_UnitTest('test_case1'))
    suite.addTest(_UnitTest('test_case2'))
    suite.addTest(_UnitTest('test_case3'))
    runner = unittest.TextTestRunner()
    runner.run(suite)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crcmodbus-1.3.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file crcmodbus-1.3.tar.gz.

File metadata

  • Download URL: crcmodbus-1.3.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for crcmodbus-1.3.tar.gz
Algorithm Hash digest
SHA256 4d96b8e7304c1eecf8f2d918c9f918ca6c1de5eaa32f9afb65baa390fd478f4d
MD5 c710911e35c3abeaf25743c0c5852e78
BLAKE2b-256 69d002851471a63f7e84195e73390e7dfd5a69bb7b865569e88e82fc79ee1f87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page