Modbus crc16 calculation

8 次查看(过去 30 天)
Rohit Baranwal
Rohit Baranwal 2016-6-2
Hi, I have written a function to compute CRC16 checksum for Modbus messages. The function accepts a Modbus message in uint16 format and gives the checksum in uint16 format (without swapping low and high bytes). I have submitted it here: http://www.mathworks.com/matlabcentral/fileexchange/57479-modbus-crc--message-modbus-- I have used the procedure outlined in Appendix B, page 39/44 of 'MODBUS over serial line specification and implementation guide V1.02'. The results agree with the following calculator: http://www.lammertbies.nl/comm/info/crc-calculation.html
However, since I am processing uint16, this means that message must have even number of bytes. However, Modbus can have odd number of bytes in a message, correct? If true, then should the data input be of uint8 type rather than uint16? Please help.
  1 个评论
John D'Errico
John D'Errico 2016-6-2
This is YOUR code as you have written it, right? So the input can be whatever you choose to require it to be.
Nothing stops you from testing the input to determine the class of a variable, and even perhaps acting intelligently on what is passed in.
So what is your question?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modbus Communication 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by