saucekorn69
Member
Hi everyone,
I'm curently developing a driver under VB.NET using the DF1 protocol,
in order to communicate with an Allen Bradley's PLC.
I'm really stuck with the CRC Checksum. I've made a class which
calculate the CRC checksum, the protocol is giving me an example to
verify the validity of my CRC value but I'm not able to get it.
I'm talking about the CRC-16, having X^16 + X^15 + X^2 + X^0 for
plynomial value.
Here is the example of a sent packet (I don't even know if this is only Hexadecimal values) :
10 02 07 11 41 00 53 B9 00 00 00 00 00 00 00 00 00 00 00 00 10 03
According to the document, CRC value of this packet has to be 6B 4C.
Here is the class's main code:
--------------------------------------------------------------
Private CRC_Register As Long = &HFFFF
Private Const POLYNOMIAL_VALUE As Long = &HA001
Public Sub AddByte(ByVal ByteValue As Int16)
Dim sLowCRC As Short, sHighCRC As Short
Dim iEven As Integer
SplitLong(CRC_Register, sLowCRC, sHighCRC)
MakeLong(CRC_Register, (sLowCRC Xor ByteValue), sHighCRC)
For i As Integer = 1 To 8
iEven = CRC_Register Mod 2
CRC_Register = CRC_Register >> 1
If iEven = 1 Then
CRC_Register = CRC_Register Xor POLYNOMIAL_VALUE
End If
Next
End Sub
---------------------------------------------------------------
Can someone tell me what's wrong with this, I ca desperately not have the good solution...
Thank you for helping.
Nicolas Chaillou.
------------------------------ --------------------------------------------------
EXA System
Montréal QUEBEC
I'm curently developing a driver under VB.NET using the DF1 protocol,
in order to communicate with an Allen Bradley's PLC.
I'm really stuck with the CRC Checksum. I've made a class which
calculate the CRC checksum, the protocol is giving me an example to
verify the validity of my CRC value but I'm not able to get it.
I'm talking about the CRC-16, having X^16 + X^15 + X^2 + X^0 for
plynomial value.
Here is the example of a sent packet (I don't even know if this is only Hexadecimal values) :
10 02 07 11 41 00 53 B9 00 00 00 00 00 00 00 00 00 00 00 00 10 03
According to the document, CRC value of this packet has to be 6B 4C.
Here is the class's main code:
--------------------------------------------------------------
Private CRC_Register As Long = &HFFFF
Private Const POLYNOMIAL_VALUE As Long = &HA001
Public Sub AddByte(ByVal ByteValue As Int16)
Dim sLowCRC As Short, sHighCRC As Short
Dim iEven As Integer
SplitLong(CRC_Register, sLowCRC, sHighCRC)
MakeLong(CRC_Register, (sLowCRC Xor ByteValue), sHighCRC)
For i As Integer = 1 To 8
iEven = CRC_Register Mod 2
CRC_Register = CRC_Register >> 1
If iEven = 1 Then
CRC_Register = CRC_Register Xor POLYNOMIAL_VALUE
End If
Next
End Sub
---------------------------------------------------------------
Can someone tell me what's wrong with this, I ca desperately not have the good solution...
Thank you for helping.
Nicolas Chaillou.
------------------------------ --------------------------------------------------
EXA System
Montréal QUEBEC