Programmare il Netduino con codice vb.net per calcolare il checksum del tag RFID
Per chi lavora con vb.net vi allego il codice scritto da Alberto De Luca che gentilmente mi ha concesso per condividerlo con voi. Il listato seguente esegue il calcolo del checksum
del tag acquisito con il lettore RFID ID-12 come spiegato nell’articolo precedente.
Public Shared Function VerifyCheckSum(b As Byte()) As Boolean
Dim RetValue As Boolean
Dim tag As [Byte]() = New [Byte](9) {}
Dim Hex01 As [Byte], Hex02 As [Byte], Hex03 As [Byte],
Hex04 As [Byte], Hex05 As [Byte], crc As [Byte]
Array.Copy(b, 1, tag, 0, 10)
Dim ValoriAsc As New [String](UTF8Encoding.UTF8.GetChars(tag))
Hex01 = ConvHexToByte(ValoriAsc.Substring(0, 2))
Hex02 = ConvHexToByte(ValoriAsc.Substring(2, 2))
Hex03 = ConvHexToByte(ValoriAsc.Substring(4, 2))
Hex04 = ConvHexToByte(ValoriAsc.Substring(6, 2))
Hex05 = ConvHexToByte(ValoriAsc.Substring(8, 2))
crc = CByte(Hex01 Xor Hex02 Xor Hex03 Xor Hex04 Xor Hex05)
Debug.Print(crc.ToString())
RetValue = (b(0) = &H2 AndAlso b(13) = &HD AndAlso b(14) = &HA AndAlso b(15) = &H3)
Return RetValue
End Function
Private Shared Function ConvHexToByte(Value As String) As Byte
If Value.Length = 2 Then
Dim str1 As [String] = Value.Substring(0, 1)
Dim str2 As [String] = Value.Substring(1, 1)
If str1.ToUpper() = "A" Then
str1 = "10"
End If
If str1.ToUpper() = "B" Then
str1 = "11"
End If
If str1.ToUpper() = "C" Then
str1 = "12"
End If
If str1.ToUpper() = "D" Then
str1 = "13"
End If
If str1.ToUpper() = "E" Then
str1 = "14"
End If
If str1.ToUpper() = "F" Then
str1 = "15"
End If
If str2.ToUpper() = "A" Then
str2 = "10"
End If
If str2.ToUpper() = "B" Then
str2 = "11"
End If
If str2.ToUpper() = "C" Then
str2 = "12"
End If
If str2.ToUpper() = "D" Then
str2 = "13"
End If
If str2.ToUpper() = "E" Then
str2 = "14"
End If
If str2.ToUpper() = "F" Then
str2 = "15"
End If
Dim b1 As [Byte] = [Byte].Parse(str1)
Dim b2 As [Byte] = [Byte].Parse(str2)
Dim cv As [Byte] = CByte(b1 * 16 + b2)
Return cv
End If
Return 0
End Function
Potete visitare il blog di Alberto ed il suo progetto di Rivelatore presenze con RFID.
Related posts
Articoli popolari
Sorry. No data so far.
.Net micro framework Arduino Arduino Webserver Domotica Flyport I2C IOT Netduino OpenPicus raspberry RTC Speed Test
