LoginSignup
1
1

More than 5 years have passed since last update.

C++ | boost > CRC-16 (Modbus)

Last updated at Posted at 2017-08-25
動作環境
https://wandbox.org/
- gcc HEAD 8.0.0 2017
- Boost 1.64.0
- C++1z(GNU)
- no pedantic

CRC-16 (Modbus)に関して、@h_matsumuraさんに教えていただいたBoostの方法を試してみる。

参考

中国語のサイトです
https://www.amobbs.com/thread-5630500-1-1.html

xiè-xie nín

code

#include <iostream>
#include <boost/crc.hpp>

int main(void) {
    typedef boost::crc_optimal<16, 0x8005, 0xFFFF, 0, true, true> modbus_crc;
    char pdu[] = "123456789";

    modbus_crc crc;
    crc.process_bytes(pdu, 9);

    std::cout << std::hex << crc.checksum() << std::endl;
    return 0;
}
run
Start
4b37
0
Finish

https://www.lammertbies.nl/comm/info/crc-calculation.html
の結果「CRC-16 (Modbus)」0x4B37と同じになった。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1