Calculate checksum for Laboratory Information System (LIS) frames

后端 未结 3 1369
走了就别回头了
走了就别回头了 2020-12-29 08:30

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

Explanation of the checksum algorit

相关标签:
3条回答
  • 2020-12-29 09:02

    You can do this in one line:

    return Encoding.ASCII.GetBytes(dataToCalculate).Aggregate((r, n) => r += n).ToString("X2");
    
    0 讨论(0)
  • 2020-12-29 09:10
    private bool CheckChecksum(string data)
    {
       bool isValid =false
    
       byte[] byteToCalculate = Encoding.ASCII.GetBytes(dataToCalculate);
       int checkSum = 0;
       for ( int i=i i<byteToCalculate.Length;i++)
       {
          checkSum += byteToCalculate[i];
       }
       checksum &= 0xff;
    
      if (checksum == byteToCalculate[ChecksumPlace]
      {
       return true
      }
      else
      {
      return  false
      }
    }
    
    0 讨论(0)
  • 2020-12-29 09:16

    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");
    }
    
    0 讨论(0)
提交回复
热议问题