Public Shared Function AppendOneByteCheckSumToCmd(ByVal sourceCmd As Byte()) As Byte()
Dim num As Byte = CalcOneByteCheckSum(sourceCmd, 0, (sourceCmd.Length - 1))
Dim destinationArray As Byte() = New Byte((sourceCmd.Length + 1) - 1) {}
Array.Copy(sourceCmd, destinationArray, sourceCmd.Length)
destinationArray((destinationArray.Length - 1)) = num
Return destinationArray
End Function
Public Shared Function CalcOneByteCheckSum(ByVal cmd As Byte(), ByVal startIndex As Integer, ByVal endIndex As Integer) As Byte
Dim num As Integer = 0
Dim i As Integer = startIndex
Do While (i <= endIndex)
num = (num + cmd(i))
i += 1
Loop
Return CByte((num And &HFF))
End Function
Public Shared Function CalcTwoByteCheckSum(ByVal cmd As Byte(), ByVal startIndex As Integer, ByVal endIndex As Integer) As Integer
Dim num As Integer = 0
Dim i As Integer = startIndex
Do While (i <= endIndex)
If ((i Mod 2) = 0) Then
num = (num + cmd(i))
Else
num = (num + (cmd(i) << 8))
End If
i += 1
Loop
Return (num And &HFFFF)
End Function