lukemeyers
New member
- Joined
- May 20, 2009
- Messages
- 3
- Programming Experience
- 1-3
Hello everybody
I'm new to this forum so please be kind
I'm currently writing a small application for a serial device and need a CRC-CCITT (inverted) for the outgoing data.
The following code works fine:
Is it somehow possible to change the input from String to an Bytearray? I tried it several times, but the line
lngCheck = Asc(Mid$(strInput, I, 1))
is making problems.
And how would you invert all bytes after the checksum is built?
Thanks for your help.
Luke
I'm new to this forum so please be kind

I'm currently writing a small application for a serial device and need a CRC-CCITT (inverted) for the outgoing data.
The following code works fine:
VB.NET:
Public Function getCRC16(ByVal strInput As String)
Dim lngCheck As Long
Dim Power(7) As Integer
Dim I As Integer
Dim J As Integer
Dim Poly As Long
Dim CRC As Long
Dim TestBit As Boolean
Dim TestBit1 As Boolean
Dim TestBit2 As Boolean
Poly = &H1021
CRC = &HFFFF
For J = 0 To 7
Power(J) = 2 ^ J
Next J
For I = 1 To Len(strInput)
lngCheck = Asc(Mid$(strInput, I, 1))
For J = 7 To 0 Step -1
If (CRC And 32768) = 32768 Then
TestBit1 = True
Else
TestBit1 = False
End If
If (lngCheck And Power(J)) = Power(J) Then
TestBit2 = True
Else
TestBit2 = False
End If
TestBit = TestBit1 Xor TestBit2
CRC = (CRC And 32767) * 2
If TestBit = True Then
CRC = CRC Xor Poly
End If
Next J
Next I
Dim tmp As String
tmp = Hex(CRC)
getCRC16 = tmp
End Function
Is it somehow possible to change the input from String to an Bytearray? I tried it several times, but the line
lngCheck = Asc(Mid$(strInput, I, 1))
is making problems.
And how would you invert all bytes after the checksum is built?
Thanks for your help.
Luke