If you’ve worked with OmniServer to connect your non-standard devices in the past, you may be aware of the large number of pre-defined Error Detection Codes (EDC, also known as CRC, LRC and Checksums) available. However, as is the nature of custom protocols out there, it’s not uncommon to find an EDC that isn’t pre-defined due to some specialized handling by the device manufacturer.
To that end, OmniServer provides the flexibility to define your own custom EDCs in an OmniServer protocol. This post, the first of three on custom Error Detection Codes, will cover the basics of creating a simple custom checksum in OmniServer.
What is an Error Detection Code?
So, for those who aren’t familiar, an Error Detection Code (EDC) is an algorithm that, when applied to a sequence of characters in a message or data packet, returns a number that can be used by another process to check the validity of the data stream.
For example, a device may sum up the ASCII values of all the characters in a data stream and append that value as the EDC to the end of the message.
Data From the Device - <STX><ACK><ETX><11>
ASCII Equivalent - 2 6 3 11
Checksum Calculation - 2 + 6 + 3 = 11
The process or device (such as OmniServer) that receives the data stream then has to apply the same algorithm to the message and check the result against the EDC value appended to the end of the message.
Received Data - 2 6 3 11
Checksum Calculation - 2 +6 + 3 = 11 -> Matches <11> - All Good!
If the two numbers are the same, then the receiving process can be rather certain that there were no transmission errors. If the numbers are not the same, then some transmission error has occurred.
Received Data - 2 7 3 11
Checksum Calculation - 2 + 7 + 3 = 12 -> Doesn't Match <11> - No Good!
EDC is a blanket term for an entire class of such error detecting algorithms including checksums, LRCs and CRCs, amongst others.
- Checksums calculate an EDC based upon the sum of a data stream.
- LRCs (Longitudinal Redundancy Check - also referred to as BCC, or Block Check Character) usually use an XOR-type algorithm on the data stream.
- CRCs (Cyclic Redundancy Check) apply another type of algorithm to the data stream and will always include some form of polynomial used in the calculation.
Why do I need to know about Error Detection Codes?
Out of the gate, OmniServer comes with 19 pre-defined Error Detection Codes.
While this generally covers a majority of the possible EDCs you might see a device manufacturer using, it is definitely possible that a manufacturer's device will have some EDC implemented not pre-defined in OmniServer.
In that case, the Error Detection Code builder in OmniServer makes it possible to define your own new EDC for a protocol, allowing you to successfully communicate with that manufacturer’s device without needed to pay the typically expensive cost to build a custom server just to handle the EDC.
How can I define custom EDCs in OmniServer?
To create your own EDC, it’s first necessary to have a description of the code or calculation required from the manufacturer. In general, this sort of information can be found in a protocol document of some sort from the device’s manufacturer. Click here for our post on evaluating protocol documentation
For example, a protocol document states this:
“The checksum is calculated from the first character after the header character up to and including the End-of-Text character. Each byte is added together, a Modulo 65536 is applied, and the result is appended to the end of the message as a two-byte number.”
Looking at this excerpt from the protocol document, we know it's a checksum ("Each byte is added together"), and that the final number will be sixteen-bits in length ("Modulo 65536" and "two-byte number") - (Remember that one byte contains eight bits, so two bytes will have sixteen bits).
Once you have this information, you have all that’s needed to go into an OmniServer protocol and build your own custom checksum to handle the above calculation. For a detailed how-to on building the custom checksum in the above example and then using it in a protocol, click here.
As with other aspects of custom protocols, there can be a lot of variability regarding the type of error detection a device manufacturer has decided to implement, if any, including how they document the calculations required. For that reason, don’t forget that we do offer complimentary protocol reviews to help you determine compatibility of your protocol (including EDCs) with OmniServer and professional services where you’d prefer us to just handle the protocol and EDCs for you.
Don’t forget to subscribe to our blog so you don’t miss the rest of this series on designing custom EDCs in OmniServer and also other useful posts on addressing industrial automation challenges.