RFID Reader - VB Source code

RFID Reader - VB Source code























Option Explicit

Private Sub Command1_Click()
Dim i&, j%, port&, baud&, buf1(200) As Byte, b1 As Byte, s1$
port = cb_ckh.ListIndex + 1
If (port = 0) Then
    lb_info.Caption = "Please select COM Port!"
End If
baud = CLng(cb_btl.Text)
If (baud = 0) Then
    lb_info.Caption = "Please select Baud rate!"
End If
'Open Port
i = rf_init_com(port, baud)
If (i <> 0) Then
    lb_info.Caption = "Open Port Fail!"
    Exit Sub
End If
'Request
i = rf_request(0, &H52, j)
If (i <> 0) Then
    lb_info.Caption = "Request Fail!"
    Exit Sub
End If
'Anticollision
i = rf_anticoll(0, 4, buf1(0), b1)
If (i <> 0) Then
    lb_info.Caption = "Anticollision Fail!"
    Exit Sub
End If
s1 = ""
For i = 0 To b1 - 1
    s1 = s1 & Right("00" & Hex(buf1(i)), 2)
Next i
tx_kh.Text = s1
'Select card
i = rf_select(0, buf1(0), 4, b1)
If (i <> 0) Then
    lb_info.Caption = "Select card fail!"
    Exit Sub
End If
lb_info.Caption = "Select card succeed!"
End Sub

Private Sub Command2_Click()
Dim i&, m&, buf1(200) As Byte, buf2(200) As Byte, s1$, b1 As Byte, b2 As Byte, b3 As Byte
s1 = Trim(tx_key.Text)
If (Len(s1) <> 12) Then
    lb_info.Caption = "Wrong Key Length!"
    tx_key.SetFocus
    Exit Sub
End If
For i = 0 To 5
    buf1(i) = Val("&H" & Mid(s1, i * 2 + 1, 2))
Next i
m = cb_kh.ListIndex
If (m = -1) Then
    lb_info.Caption = "Select Block Please!"
    Exit Sub
End If
If (op_a.Value) Then
   b1 = &H60
End If
If (op_b.Value) Then
   b1 = &H61
End If
b3 = CByte(m)
'Authentication
i = rf_M1_authentication2(0, b1, b3, buf1(0))
If (i <> 0) Then
    lb_info.Caption = "Authentication Fail£¡"
    Exit Sub
End If
'Read card
i = rf_M1_read(0, b3, buf2(0), b2)
If (i <> 0) Then
    lb_info.Caption = "Read Card Fail!"
    Exit Sub
End If
s1 = ""
For i = 0 To b2 - 1
    s1 = s1 & Right("00" & Hex(buf2(i)), 2)
Next i
tx_sj.Text = s1
lb_info.Caption = "Read Succeed!"
End Sub

Private Sub Command3_Click()
Dim i&, m&, buf1(200) As Byte, buf2(200) As Byte, s1$, b1 As Byte, b2 As Byte, b3 As Byte
s1 = Trim(tx_key.Text)
If (Len(s1) <> 12) Then
    lb_info.Caption = "Wrong Key Length!"
    tx_key.SetFocus
    Exit Sub
End If
For i = 0 To 5
    buf1(i) = Val("&H" & Mid(s1, i * 2 + 1, 2))
Next i
m = cb_kh.ListIndex
If (m = -1) Then
    lb_info.Caption = "Select Block Please!"
    Exit Sub
End If
If (op_a.Value) Then
   b1 = &H60
End If
If (op_b.Value) Then
   b1 = &H61
End If

s1 = Trim(tx_sj.Text)
If (Len(s1) <> 32) Then
    lb_info.Caption = "Wrong Data length "
    tx_sj.SetFocus
    Exit Sub
End If
For i = 0 To 15
    buf2(i) = Val("&H" & Mid(s1, i * 2 + 1, 2))
Next i
'Authentication
b3 = CByte(m)
i = rf_M1_authentication2(0, b1, b3, buf1(0))
If (i <> 0) Then
    lb_info.Caption = "Authentication Fail!"
    Exit Sub
End If
'Write card
i = rf_M1_write(0, b3, buf2(0))
If (i <> 0) Then
    lb_info.Caption = "Write Card Fail£¡"
    Exit Sub
End If

lb_info.Caption = "Write Succeed!"
End Sub

Private Sub Command4_Click()
Dim i&
i = rf_halt(0)
If (i <> 0) Then
    lb_info.Caption = "Halt Fail!"
    Exit Sub
End If
lb_info.Caption = "Halt Succeed"
End Sub

Private Sub Form_Load()
Dim i&
For i = 0 To 63
    cb_kh.AddItem CStr(i), i
Next i
cb_ckh.ListIndex = 0: cb_btl.ListIndex = 1: cb_kh.ListIndex = 4
End Sub

Download Source code


RFID on Ebay Store