1 visual basic® 5/6, 1 visual basic – INFICON SQC-310 Thin Film Deposition Controller User Manual
Page 99
5 - 19
IP
N 07
4-
55
0-
P1
B
SQC-310 Operating Manual
5.4.1 Visual Basic
®
5/6
Public Sub CalcChkSumByte(ByRef ByData() As Byte, ByRef byCRC() As
Byte)
Dim CRC As Integer
Dim TmpCRC As Integer
Dim LastIndex As Long
Dim i As Integer
Dim j As Integer
LastIndex = UBound(ByData())
' Avoid on length messages
If ByData(1) > 0 Then
' Set 14 bit CRC to all ones
CRC = &H3FFF
For j = 1 To LastIndex - 2
' XOR current character with CRC
CRC = CRC Xor ByData(j)
' Go thru lower 8 bits of CRC
For i = 1 To 8
' Save CRC before shift
TmpCRC = CRC
' Shift right one bit
CRC = Shri(CRC, 1)
If (TmpCRC And 1) = 1 Then
' If LSB is 0 (before shift), XOR with hex 2001
CRC = CRC Xor &H2001
End If
Next i
Next j
' Be sure we still have 14 bits
CRC = CRC And &H3FFF
byCRC(0) = (LoByte(CRC) And &H7F) + 34
byCRC(1) = (LoByte(Shri(CRC, 7)) And &H7F) + 34
Else
' Empty message
byCRC(0) = 0
byCRC(1) = 0
End If
End Sub
Public Function LoByte(ByVal intNumber As Integer) As Byte
' Comments : Returns the low byte of the passed integer
' Parameters: intNumber - integer value for which to return the low
byte
' Returns : byte