5 crc examples, 1 visual basic® 5/6, Found in – INFICON SQM-160 Thin Film Deposition Monitor User Manual

Page 72: Section 5.5, crc examples, on, 1 visual basic

Advertising
background image

5 - 12

IP

N 07

4-

51

1-

P1

C

SQM-160 Operating Manual

5.5 CRC Examples

In this section you will find examples of code for calculating the CRC in Visual
Basic, Java, and C++. Instructions for calculating the CRC are located in

section

5.3 on page 5-6

.

5.5.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

Advertising