I'm sure other people have had troubles with this in the past. So, I'm going to explain where I've gotten with the 633 and Visual Basic.
For the last 5 days I've been scratching my head trying to figure out how the hell to reporduce a CRC check. I took the test software for the 633 and looped it back into another program to get the code and then took my program and put that data back to the LCD. This worked. However, all I did was send a packet to a port monitor and duplicate that packet. Not going to do much for usefullness. But that meant that it worked through Visual Basic. Something I'd never been able to do.
It's like this.... The binary function of the MSComm control is crap. So, I had to use Ascii for the input property. So that meant I had to convert it from ascii to binary. Easy enough with this function I made:
Public Function TextToBinary(StringT As String) As String
Dim Ascii, FinalBinary$, GetNum&
FinalBinary$ = ""
For GetNum& = 1 To Len(StringT$)
Ascii = ChrAscii(Mid(StringT$, GetNum, 1))
' 128
If Ascii >= 128 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 128
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 64
If Ascii >= 64 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 64
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 32
If Ascii >= 32 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 32
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 16
If Ascii >= 16 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 16
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 8
If Ascii >= 8 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 8
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 4
If Ascii >= 4 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 4
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 2
If Ascii >= 2 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 2
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 1
If Ascii >= 1 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 1
Else
FinalBinary$ = FinalBinary$ & "0"
End If
If Mid(StringT$, GetNum + 1, 1) = Chr(32) Then
FinalBinary$ = FinalBinary$ '& " "
Else
FinalBinary$ = FinalBinary$ '& Chr(32)
End If
Next GetNum&
TextToBinary$ = FinalBinary$
End Function
Great. Now we have the binary of the packet that was sent to us. Now we have to change it from binary, to decimal. Easy enough with another function:
Public Function BinaryToDecimal(oString As String)
'Convert binary to decimal
Dim NewText As String
Dim i As Integer, count As Integer, BinaryString As String
Dim n As Integer, Character As String, Value As Integer
Dim CompletedString As String
'NewText is the text without spaces, this makes it
'Easier to count 8 characters then count again
'instead of counting 8 adding one etc.
'NewText = RemoveExtraSpaces(oString)
'Remove all spaces but don't show the text without them
NewText = RemoveChar(oString)
'Add a space
'txtNew.Text = txtNew.Text & vbCrLf
For i = 1 To Len(NewText)
'Get the 8 char long string
''debug.print "I: "; i & vbCrLf
BinaryString = BinaryString & Mid(NewText, i, 1)
''debug.print "BinaryString: "; BinaryString & vbCrLf
count = count + 1
If count = 8 Then
For n = 1 To Len(BinaryString)
Character = Mid(BinaryString, n, 1)
'debug.print "Character: "; Character & vbCrLf
If Val(Character) = 1 Then
If n = 1 Then
Value = Value + 128
ElseIf n = 2 Then
Value = Value + 64
ElseIf n = 3 Then
Value = Value + 32
ElseIf n = 4 Then
Value = Value + 16
ElseIf n = 5 Then
Value = Value + 8
ElseIf n = 6 Then
Value = Value + 4
ElseIf n = 7 Then
Value = Value + 2
ElseIf n = 8 Then
Value = Value + 1
End If
'debug.print "Value: "; Value & vbCrLf
End If
Next n
CompletedString = CompletedString & Value & " "
Value = 0
count = 0
BinaryString = ""
End If
Next i
'clear the counter and binary string
BinaryToDecimal = CompletedString
CompletedString = ""
End Function
Now we have our packet. We'll have to analyse this, to respond to what the display is sending us; however not right now, cause I havn't gotten to that part.
In order to SEND a packet.... we have to figure out what the packet is going to be.... I'm still working on this, however this is a start and should get you on you're way.
We have to create a CRC of the packet.
Let's say the packet should contain the following decimal numbers:
16 1 15
Which if you will notice will turn the reporting of all 4 fans on. We send this with the following command:
MSComm1.output = chr(16) & chr(1) & chr(15)
But we havn't gotten to the CRC check, so don't send it yet.
To do the CRC check we take our packet:
Packet = chr(16) & chr(1) & chr(15)
Then we create a CRC packet based on this packet, using a OCX that I found, this is relativly simple (webpage address to OCX is located at bottom of this post).
Function CalculateCRC(oString As String)
Dim crc As String
crc = VbCrC.CrcCalc(oString, CCITT)
'crc is now a decimal of the full 16 bit CRC.
'We have to convert that to two 8 bit CRC's for the display
crc = dec2bin(crc)
'Changed to binary.
crc = Format(crc, "0000000000000000")
'vbCRC will remove leading zero's, we have to add those back.
crc2 = Left(crc, 8)
'Get the left ones, this is the first crc, so it's reversed.
crc1 = Right(crc, 8)
'Grab second crc.
crc1 = BinaryToDecimal(Format(crc1, "00000000"))
'convert it from binary to decimal.
crc2 = BinaryToDecimal(Format(crc2, "00000000"))
'again.
CalculateCRC = Chr(crc1) & Chr(crc2)
'Spit it out.
End Function
Great. Now we have a function to get a CRC packet generated.
So, this will show you how to deal with those pesky CRC's.
I have not yet built a sub routine to determine if the packet sent has a accurate CRC. But that's coming soon.
I just wanted to get all this out so those who are currently working on the 633 and VB can get this part out of the way. I'm SURE many people can clean up my code and make it more efficient but this works and it's a step in the right direction for those who are stuck at this point.
Any questions are welcome!
vbCRC: http://www.iland.net/~jhaase/vbcrc/
For the last 5 days I've been scratching my head trying to figure out how the hell to reporduce a CRC check. I took the test software for the 633 and looped it back into another program to get the code and then took my program and put that data back to the LCD. This worked. However, all I did was send a packet to a port monitor and duplicate that packet. Not going to do much for usefullness. But that meant that it worked through Visual Basic. Something I'd never been able to do.
It's like this.... The binary function of the MSComm control is crap. So, I had to use Ascii for the input property. So that meant I had to convert it from ascii to binary. Easy enough with this function I made:
Public Function TextToBinary(StringT As String) As String
Dim Ascii, FinalBinary$, GetNum&
FinalBinary$ = ""
For GetNum& = 1 To Len(StringT$)
Ascii = ChrAscii(Mid(StringT$, GetNum, 1))
' 128
If Ascii >= 128 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 128
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 64
If Ascii >= 64 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 64
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 32
If Ascii >= 32 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 32
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 16
If Ascii >= 16 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 16
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 8
If Ascii >= 8 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 8
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 4
If Ascii >= 4 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 4
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 2
If Ascii >= 2 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 2
Else
FinalBinary$ = FinalBinary$ & "0"
End If
' 1
If Ascii >= 1 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 1
Else
FinalBinary$ = FinalBinary$ & "0"
End If
If Mid(StringT$, GetNum + 1, 1) = Chr(32) Then
FinalBinary$ = FinalBinary$ '& " "
Else
FinalBinary$ = FinalBinary$ '& Chr(32)
End If
Next GetNum&
TextToBinary$ = FinalBinary$
End Function
Great. Now we have the binary of the packet that was sent to us. Now we have to change it from binary, to decimal. Easy enough with another function:
Public Function BinaryToDecimal(oString As String)
'Convert binary to decimal
Dim NewText As String
Dim i As Integer, count As Integer, BinaryString As String
Dim n As Integer, Character As String, Value As Integer
Dim CompletedString As String
'NewText is the text without spaces, this makes it
'Easier to count 8 characters then count again
'instead of counting 8 adding one etc.
'NewText = RemoveExtraSpaces(oString)
'Remove all spaces but don't show the text without them
NewText = RemoveChar(oString)
'Add a space
'txtNew.Text = txtNew.Text & vbCrLf
For i = 1 To Len(NewText)
'Get the 8 char long string
''debug.print "I: "; i & vbCrLf
BinaryString = BinaryString & Mid(NewText, i, 1)
''debug.print "BinaryString: "; BinaryString & vbCrLf
count = count + 1
If count = 8 Then
For n = 1 To Len(BinaryString)
Character = Mid(BinaryString, n, 1)
'debug.print "Character: "; Character & vbCrLf
If Val(Character) = 1 Then
If n = 1 Then
Value = Value + 128
ElseIf n = 2 Then
Value = Value + 64
ElseIf n = 3 Then
Value = Value + 32
ElseIf n = 4 Then
Value = Value + 16
ElseIf n = 5 Then
Value = Value + 8
ElseIf n = 6 Then
Value = Value + 4
ElseIf n = 7 Then
Value = Value + 2
ElseIf n = 8 Then
Value = Value + 1
End If
'debug.print "Value: "; Value & vbCrLf
End If
Next n
CompletedString = CompletedString & Value & " "
Value = 0
count = 0
BinaryString = ""
End If
Next i
'clear the counter and binary string
BinaryToDecimal = CompletedString
CompletedString = ""
End Function
Now we have our packet. We'll have to analyse this, to respond to what the display is sending us; however not right now, cause I havn't gotten to that part.
In order to SEND a packet.... we have to figure out what the packet is going to be.... I'm still working on this, however this is a start and should get you on you're way.
We have to create a CRC of the packet.
Let's say the packet should contain the following decimal numbers:
16 1 15
Which if you will notice will turn the reporting of all 4 fans on. We send this with the following command:
MSComm1.output = chr(16) & chr(1) & chr(15)
But we havn't gotten to the CRC check, so don't send it yet.
To do the CRC check we take our packet:
Packet = chr(16) & chr(1) & chr(15)
Then we create a CRC packet based on this packet, using a OCX that I found, this is relativly simple (webpage address to OCX is located at bottom of this post).
Function CalculateCRC(oString As String)
Dim crc As String
crc = VbCrC.CrcCalc(oString, CCITT)
'crc is now a decimal of the full 16 bit CRC.
'We have to convert that to two 8 bit CRC's for the display
crc = dec2bin(crc)
'Changed to binary.
crc = Format(crc, "0000000000000000")
'vbCRC will remove leading zero's, we have to add those back.
crc2 = Left(crc, 8)
'Get the left ones, this is the first crc, so it's reversed.
crc1 = Right(crc, 8)
'Grab second crc.
crc1 = BinaryToDecimal(Format(crc1, "00000000"))
'convert it from binary to decimal.
crc2 = BinaryToDecimal(Format(crc2, "00000000"))
'again.
CalculateCRC = Chr(crc1) & Chr(crc2)
'Spit it out.
End Function
Great. Now we have a function to get a CRC packet generated.
So, this will show you how to deal with those pesky CRC's.
I have not yet built a sub routine to determine if the packet sent has a accurate CRC. But that's coming soon.
I just wanted to get all this out so those who are currently working on the 633 and VB can get this part out of the way. I'm SURE many people can clean up my code and make it more efficient but this works and it's a step in the right direction for those who are stuck at this point.
Any questions are welcome!
vbCRC: http://www.iland.net/~jhaase/vbcrc/
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.