Effacer les filtres
Effacer les filtres

Modbus crc16 calculation

8 vues (au cours des 30 derniers jours)
Rohit Baranwal
Rohit Baranwal le 2 Juin 2016
Commenté : John D'Errico le 2 Juin 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 commentaire
John D'Errico
John D'Errico le 2 Juin 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?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Modbus Communication dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by