📄 frm_main.frm
字号:
VERSION 5.00
Begin VB.Form frm_main
Caption = "VB DEMO"
ClientHeight = 7155
ClientLeft = 60
ClientTop = 345
ClientWidth = 7575
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 7155
ScaleWidth = 7575
StartUpPosition = 1 'CenterOwner
Begin VB.ComboBox cb_btl
Height = 360
ItemData = "frm_main.frx":0000
Left = 5430
List = "frm_main.frx":0010
Style = 2 'Dropdown List
TabIndex = 19
Top = 1230
Width = 1215
End
Begin VB.ComboBox cb_ckh
Height = 360
ItemData = "frm_main.frx":0030
Left = 2100
List = "frm_main.frx":004F
Style = 2 'Dropdown List
TabIndex = 18
Top = 1230
Width = 1275
End
Begin VB.CommandButton Command4
Caption = "休眠"
Height = 615
Left = 4800
TabIndex = 16
Top = 5280
Width = 1035
End
Begin VB.CommandButton Command3
Caption = "写卡"
Height = 615
Left = 3570
TabIndex = 15
Top = 5280
Width = 1035
End
Begin VB.CommandButton Command2
Caption = "读卡"
Height = 615
Left = 2190
TabIndex = 14
Top = 5280
Width = 1035
End
Begin VB.CommandButton Command1
Caption = "寻卡"
Height = 615
Left = 960
TabIndex = 13
Top = 5280
Width = 1035
End
Begin VB.TextBox tx_sj
Height = 360
Left = 1980
TabIndex = 12
Top = 4470
Width = 4515
End
Begin VB.ComboBox cb_kh
Height = 360
ItemData = "frm_main.frx":006E
Left = 2580
List = "frm_main.frx":0070
Style = 2 'Dropdown List
TabIndex = 10
Top = 3870
Width = 1515
End
Begin VB.Frame Frame1
Caption = "密钥选择"
Height = 975
Left = 930
TabIndex = 5
Top = 2700
Width = 5625
Begin VB.TextBox tx_key
Height = 360
Left = 2880
TabIndex = 8
Text = "FFFFFFFFFFFF"
Top = 360
Width = 2445
End
Begin VB.OptionButton op_b
Caption = "B密钥"
Height = 375
Left = 1590
TabIndex = 7
Top = 360
Width = 1035
End
Begin VB.OptionButton op_a
Caption = "A密钥"
Height = 255
Left = 210
TabIndex = 6
Top = 390
Value = -1 'True
Width = 1005
End
End
Begin VB.TextBox tx_kh
Height = 360
Left = 1980
TabIndex = 4
Top = 1920
Width = 2205
End
Begin VB.Label lb_info
Height = 465
Left = 840
TabIndex = 17
Top = 6330
Width = 6255
End
Begin VB.Label Label6
Caption = "数据:"
Height = 345
Left = 990
TabIndex = 11
Top = 4500
Width = 855
End
Begin VB.Label Label5
Caption = "绝对块号:"
Height = 345
Left = 990
TabIndex = 9
Top = 3900
Width = 1395
End
Begin VB.Label Label4
Caption = "序列号:"
Height = 405
Left = 900
TabIndex = 3
Top = 1950
Width = 975
End
Begin VB.Label Label3
Caption = "MIFARE ONE 读写程序"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 465
Left = 2040
TabIndex = 2
Top = 360
Width = 3465
End
Begin VB.Label Label2
Caption = "波特率:"
Height = 315
Left = 4290
TabIndex = 1
Top = 1260
Width = 1035
End
Begin VB.Label Label1
Caption = "串口号:"
Height = 315
Left = 930
TabIndex = 0
Top = 1260
Width = 1005
End
End
Attribute VB_Name = "frm_main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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 = "请选择串口号!"
End If
baud = CLng(cb_btl.Text)
If (baud = 0) Then
lb_info.Caption = "请选择波特率!"
End If
'打开串口
i = rf_init_com(port, baud)
If (i <> 0) Then
lb_info.Caption = "串口号打开失败!"
Exit Sub
End If
'寻卡
i = rf_request(0, &H52, j)
If (i <> 0) Then
lb_info.Caption = "寻卡失败!"
Exit Sub
End If
'防冲撞
i = rf_anticoll(0, 4, buf1(0), b1)
If (i <> 0) Then
lb_info.Caption = "防冲撞失败!"
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
'选卡
i = rf_select(0, buf1(0), 4, b1)
If (i <> 0) Then
lb_info.Caption = "选卡失败!"
Exit Sub
End If
lb_info.Caption = "选卡成功!"
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 = "密钥长度不对!"
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 = "请选择块号!"
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)
'验证密钥
i = rf_M1_authentication2(0, b1, b3, buf1(0))
If (i <> 0) Then
lb_info.Caption = "验证密钥失败!"
Exit Sub
End If
'读卡
i = rf_M1_read(0, b3, buf2(0), b2)
If (i <> 0) Then
lb_info.Caption = "读卡失败!"
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 = "读卡成功!"
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 = "密钥长度不对!"
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 = "请选择块号!"
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 = "数据长度不对! "
tx_sj.SetFocus
Exit Sub
End If
For i = 0 To 15
buf2(i) = Val("&H" & Mid(s1, i * 2 + 1, 2))
Next i
'验证密钥
b3 = CByte(m)
i = rf_M1_authentication2(0, b1, b3, buf1(0))
If (i <> 0) Then
lb_info.Caption = "验证密钥失败!"
Exit Sub
End If
'写卡
i = rf_M1_write(0, b3, buf2(0))
If (i <> 0) Then
lb_info.Caption = "写卡失败!"
Exit Sub
End If
lb_info.Caption = "写卡成功!"
End Sub
Private Sub Command4_Click()
Dim i&
i = rf_halt(0)
If (i <> 0) Then
lb_info.Caption = "卡休眠失败!"
Exit Sub
End If
lb_info.Caption = "卡休眠成功!"
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -