计算实验室信息系统(LIS)框架的校验和 [英] Calculate checksum for Laboratory Information System (LIS) frames

查看:132
本文介绍了计算实验室信息系统(LIS)框架的校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为实验室信息系统开发一种仪器驱动程序。我想知道如何计算帧的校验和。

I'm developing an instrument driver for a Laboratory Information System. I want to know how to calculate the checksum of a frame.

校验和算法的解释:



  1. 由字符[0-9]和[AF]表示。

  1. Expressed by characters [0-9] and [A-F].

字符从[[ STX],直到[ETB]或[ETX](包括[ETB]或[ETX])以二进制形式添加。

Characters beginning from the character after [STX] and until [ETB] or [ETX] (including [ETB] or [ETX]) are added in binary.

2代表十六进制代码中最低有效8位的位数,已转换为ASCII字符[0-9]和
[AF]。

The 2-digit numbers, which represent the least significant 8 bits in hexadecimal code, are converted to ASCII characters [0-9] and [A-F].

最高有效位存储在CHK1中,最低有效位存储在CHK2中。

The most significant digit is stored in CHK1 and the least significant digit in CHK2.


我没有得到上面的第三和第四点。

I am not getting the 3rd and 4th points above.

这是一个示例框架:

<STX>2Q|1|2^1||||20011001153000<CR><ETX><CHK1><CHK2><CR><LF>

CHK1 CHK2 ?

推荐答案

最后我得到了答案,这是用于计算校验和的代码:

Finally I got answer, here is the code for calculating checksum:

private string CalculateChecksum(string dataToCalculate)
{
    byte[] byteToCalculate = Encoding.ASCII.GetBytes(dataToCalculate);
    int checksum = 0;
    foreach (byte chData in byteToCalculate)
    {
        checksum += chData;
    }
    checksum &= 0xff;
    return checksum.ToString("X2");
}

这篇关于计算实验室信息系统(LIS)框架的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆