|
|
Calculating the checksum of an ASTM document |
Index |
Environment: C#, VB, C++ .NET
Using the ASTM protocol to communicate with a laboratory instrument can be an interesting
project, and one of the finer points of ASTM is calculating the checksum on transmitted
and received documents. Each segment (row or message) of data includes a checksum when
either the laboratory instrument or the LIS (Laboratory Information System) transmits
the document.
The benefits are obvious in a mission (life) critical application
to ensure what was sent is exactly what is received.
Following is an example of a segment of ASTM data transmitted from a laboratory
instrument:
5R|2|^^^1.0000+950+1.0|15|||^5^||V||34001637|20080516153540|20080516153602|34001637
3D
The segment starts with a STX
character (0x02) and ends with a
ETX character (0x03). All of the characters AFTER the STX and up
to and including the ETX character is the data used to calculate the checksum for
this message. The following C# method calculates the checksum by adding the
ASCII values of each character in the string and then performing a mod 256 calculation
on the total value for all characters in the ASTM message. The checksum is
then appended to the end of the message, and in this case the value is
3D. Remember that the value must be converted to it's HEX equivalent
before adding it to the message.
To use this method you must include the following classes in the project:
The class T above defines most of the control characters required to communicate
in ASTM protocol. The CheckSum class provides the return object containing
the calculated value and a valid indicator.

|
|
|