The Modbus CRC Endianness Kerfuffle

Modbus is a quaint protocol. It’s one of my favourite protocols — it’s not very convenient to use, but it’s pretty convenient to implement and remarkably flexible for an otherwise pretty opinionated protocol. Its specs are very self-contained and easy to follow.

That being said, like all protocols that are a) from an entirely different era of computing and b) royalty-free, there are a lot of non-conforming devices out there. When you run into one, you quickly start to doubt the specs, your documentation, your code and eventually your sanity. My favourite stumbling block? The endianness of the CRC value.

It’s not so much that nobody gets it right — in fact, it’s the one thing that even non-conforming devices get right, because their developers end up swapping the bytes until they get the order right, otherwise the device can’t talk to anything. It’s just that a lot of people don’t understand why they got it right.

Continue reading The Modbus CRC Endianness Kerfuffle