c# - 计算实验室信息系统 (LIS) 帧的校验和

标签 c# checksum

我正在为 Laboratory Information System 开发仪器驱动程序.我想知道如何计算帧的校验和。

校验和算法的解释:

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

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

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

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

我没有得到上面的第 3 点和第 4 点。

这是一个示例框架:

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

CHK1CHK2 的值是多少?如何在 C# 中实现给定的算法?

最佳答案

终于得到答案,这里是计算校验和的代码:

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");
}

关于c# - 计算实验室信息系统 (LIS) 帧的校验和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947717/

相关文章:

c# - 调用 ReadPixels 以从系统帧缓冲区读取像素,而不是在绘图帧内。 UnityEngine.Texture2D :ReadPixels

c# - ldloc 还是 ldloca?

php - MySQL 行校验和

algorithm - rsync算法中的重叠 block

c++ - 计算一个点号的校验和

c# - ASP.NET MVC : How to close browser window instead of returning a view?

c# - 示例代码中是否需要 Task.WhenAll?

c# - 如何解压子目录中存在的所有 .tar.bz2 并创建所有文件的列表

java - 使用 Java 为大文件生成 MD5 非常慢

c - 弗莱彻校验和 : Is a modulo-255 sum really the same as a one's complement sum