ja so in etwa, nur mit CRC 16...
Die Daten für CRC sind Polynom &h1021, Initvalue: FFFF, Final XOR value: FFFF
DATA String: 010003GET
so ich poste hier mal den Code, evtl versteht ihr dann was ich meine:
Private Sub cmdCRC_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdCRC.Click
Dim varDaten As String = "010003GET" 'Datastring, contains destination
' adress, sender adress, length and GET
Dim varDatenByte(8) As Byte 'Array, used to save ASCI Byte values
Dim varI As Integer 'used for counting
Dim varJ As Integer 'used for counting
Dim varBIT(8) As String 'Array, for saveing binary value for each ASCII
' Byte value
Dim varDatenPaket As String = "" 'Datastring, contains binary
' translation of raw Data
Dim varPoly As String = "1000000100001" 'Polynom x^16+x^12+x^5+1
Dim varTeilwert As String 'Value divided by Polynom
Dim varXOR As String = "" 'Result of XOR divison
Dim varCRC As String 'Final CRC
varDatenByte = System.Text.Encoding.ASCII.GetBytes(varDaten) 'write the
' ASCII Byte value for each char of varDaten in a seperated
' varDatenByte of the Array; from left to right
For varI = 0 To 8 Step 1 'set each member of the varBIT array to "" ( _
empty, no chars)
varBIT(varI) = ""
Next
For varI = 0 To 8 Step 1 'For Next, increments the Counter
For varJ = 7 To 0 Step -1 'For Next, decrements the second Counter
'Divides each varDatenByte by 2^7 to 0, cuts everything after
' decimalpoint and inserts the result on last place in string
varBIT(varI) = varBIT(varI).Insert(varBIT(varI).Length, CType(( _
varDatenByte(varI) \ (2 ^ varJ)), String))
'Divides each varDatenByte by 2^7 to 0, deletes the old value
' of varDatenByte and sets it with the rest of division
varDatenByte(varI) = (varDatenByte(varI) Mod (2 ^ varJ))
Next
Next
'Finished Part 1, String into binary
For varI = 8 To 0 Step -1 'Puts all values of varBit array in one
' String --> varDatenPacket
varDatenPaket = varDatenPaket.Insert(0, CType(varBIT(varI), String))
Next
varDatenPaket = varDatenPaket & "1111111111111111" 'puts FFFF Init
' Value to the end of String
Do Until varDatenPaket.Substring(0, 1) <> "0" 'Deletes leading Zero
varDatenPaket = varDatenPaket.Remove(0, 1)
Loop
varTeilwert = varDatenPaket.Substring(0, 13) 'Puts first 14 Bits into
' Memory
varDatenPaket = varDatenPaket.Remove(0, 13) 'Cuts first 14 Bits from
' Original Data
Do Until varDatenPaket.Length = 0 'Does until all Bits are calculated
varXOR = "" 'Init/Clear XOR
For varI = 12 To 0 Step -1 'XOR for each of 16 Bits
varXOR = varXOR.Insert(0, CType((varTeilwert.Substring(varI, 1) _
Xor varPoly.Substring(varI, 1)), String))
Next
Do Until varXOR.Substring(0, 1) <> "0" 'Deletes leading Zero
varXOR = varXOR.Remove(0, 1)
Loop
Do Until varXOR.Length = 13 Or varDatenPaket.Length = 0
varXOR = varXOR.Insert(varXOR.Length, varDatenPaket.Substring( _
0, 1)) 'Fills XOR with new Data
varDatenPaket = varDatenPaket.Remove(0, 1) 'Removes moved Bits
' from original Data
Loop
If varDatenPaket.Length = 0 Then 'Cancels DO UNTIL if Datastring
' length is 0, expands XOR-Value to length 16
Do Until varXOR.Length = 16
varXOR = varXOR.Insert(0, "0")
Loop
Exit Do
End If
varTeilwert = varXOR 'Result of XOR to new Data
Loop
varTeilwert = varXOR 'Result of XOR to new Data
varXOR = "" 'Init/Clear XOR
varPoly = "1111111111111111" 'Final XOR value sets to FFFF
For varI = 15 To 0 Step -1 'Final XOR
varXOR = varXOR.Insert(0, CType((varTeilwert.Substring(varI, 1) Xor _
varPoly.Substring(varI, 1)), String))
Next
varCRC = varXOR 'Rest of XOR to CRC
Me.lblCRC.Text = varCRC 'Shows CRC
End Sub Sollte irgendwer die Lösung finden, sprech ich ihn heilig
Mfg
Parallax
Am morgen nen Joint und der Tag is dein Freund |