Filter löschen
Filter löschen

Modbus crc16 calculation

8 Ansichten (letzte 30 Tage)
Rohit Baranwal
Rohit Baranwal am 2 Jun. 2016
Kommentiert: John D'Errico am 2 Jun. 2016
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 Kommentar
John D'Errico
John D'Errico am 2 Jun. 2016
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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Modbus Communication finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by