📄 读写卡机程序.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5310
ClientLeft = 60
ClientTop = 450
ClientWidth = 8310
LinkTopic = "Form1"
ScaleHeight = 5310
ScaleWidth = 8310
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 3120
TabIndex = 6
Text = "00005"
Top = 2520
Width = 2295
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 3120
TabIndex = 5
Top = 1440
Width = 2295
End
Begin VB.CommandButton Command3
Caption = "写卡片编号"
Height = 735
Left = 600
TabIndex = 4
Top = 2520
Width = 2295
End
Begin VB.CommandButton Command2
Caption = "读卡片编号"
Height = 855
Left = 600
TabIndex = 3
Top = 1320
Width = 2295
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 1440
TabIndex = 1
Top = 240
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "连接卡机"
Height = 615
Left = 3240
TabIndex = 0
Top = 240
Width = 2055
End
Begin VB.Label Label1
Caption = "卡机编号"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 0
TabIndex = 2
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
status = zlg500B_init(Text1, 19200) '联接串口
If status <> 0 Then
MsgBox "初始化读卡器失败"
Unload Me
Exit Sub
Else
status = zlg500B_buzzer(240, 25, 25, 1) '蜂鸣
End If
End Sub
Private Sub Command2_Click()
Dim status, i As Byte
Dim mode As Byte
Dim snr As Long
Dim tagtype As Byte
Dim data(100) As Byte
Dim size As Byte
Dim bcnt As Byte
Dim keynr, secnr, addr As Byte
Dim j As Integer
mode = 1
status = zlg500B_request(0, tagtype) '有效范围内是否有卡
If status = 1 Then
MsgBox "无卡"
Exit Sub
End If
bcnt = 0
status = zlg500B_anticoll(bcnt, snr)
status = zlg500B_select(snr, size) '读卡系列号
If status = 0 Then
Text = snr
End If
mode = 0
'If Combo4.Text = "B" Then
' mode = 4
'End If
Dim key(6) As Byte
secnr = 1
For i = 0 To 5
key(i) = Val("&h" + Mid(Trim("FFFFFFFFFFFF"), i * 2 + 1, 2))
Next i
status = zlg500B_load_key(mode, secnr, key(0)) '先装载密码
status = zlg500B_authentication(mode, secnr) ' 效验某块扇区的密码
If status = 1 Then
If secnr = 1 Then
MsgBox "密码错误"
End If
End If
Dim m&, buf1(200) As Byte, buf2(200) As Byte, s1$, b1 As Byte, b2 As Byte, b3 As Byte
status = zlg500B_read(4, buf2(0)) '读取卡的一个块的数据
first18 = ""
For i = 0 To 15
If Len(Hex(buf2(i))) = 1 Then
a1 = 0 & Hex(buf2(i))
Else
a1 = Hex(buf2(i))
End If
a1 = "&h" & a1
sb = ChrW(Val(a1))
first18 = first18 & sb
Next i
MsgBox "身份证号:" & first18
End Sub
Private Sub Command3_Click()
Text3.Text = Trim(Text3)
Text3 = Format$(Text3, "00000")
Dim cardtype As Integer
Dim szpwd(5) As Byte
Dim snr As Long
Dim size As Byte
Dim data(15) As Byte
'假设第0扇区密码都为0xff
szpwd(0) = &HFF
szpwd(1) = &HFF
szpwd(2) = &HFF
szpwd(3) = &HFF
szpwd(4) = &HFF
szpwd(5) = &HFF
mode = 1
status = zlg500B_request(0, tagtype) '有效范围内是否有卡
If status = 1 Then
' MsgBox "无卡"
Exit Sub
End If
bcnt = 0
status = zlg500B_anticoll(bcnt, snr)
status = zlg500B_select(snr, size) '读卡系列号
'If status = 0 Then
' Text = snr
'End If
mode = 0
'If Combo4.Text = "B" Then
' mode = 4
'End If
Dim key(6) As Byte
Dim m&, buf1(200) As Byte, buf2(200) As Byte, b1 As Byte, b2 As Byte, b3 As Byte
Dim v1 As String, v2 As String
ss = Text3
va1 = ""
For i = 1 To 5
va1 = va1 & numtos(Mid$(ss, i, 1))
Next i
cosex = "男"
comz = "汉族"
s1 = va1 & cosex & comz
v2 = ""
For i = 1 To 8
v1 = Mid$(s1, i, 1)
If v1 = "" Then
v1 = " "
Else
If locasum(v1) = 1 Then v1 = " " & v1
End If
v2 = v2 & v1
Next i
s1 = v2
ii = 1
For i = 1 To Len(s1)
v1 = Mid$(s1, i, 1)
If locasum(v1) = 2 Then
sa = Hex(AscW(v1))
buf2((ii - 1) * 2) = Val("&H" & Mid(sa, 1, 2))
buf2((ii - 1) * 2 + 1) = Val("&H" & Mid(sa, 3, 2))
Else
sa = Hex(AscW(v1))
buf2((ii - 1) * 2) = Val("&H" & Mid$(sa, 1, 2))
v1 = Mid$(s1, i + 1, 1)
sa = Hex(AscW(v1))
buf2((ii - 1) * 2 + 1) = Val("&H" & Mid$(sa, 1, 2))
i = i + 1
End If
ii = ii + 1
Next i
'写数字
s1 = Trim(Text3) & "00000000000"
v2 = ""
For i = 1 To 16
v1 = Mid$(s1, i, 1)
If v1 = "" Then v1 = " "
v2 = v2 & v1
Next i
s1 = v2 ' Mid$(v2, 1, 16)
'MsgBox "起" & s1 & "止"
ii = 1
For i = 1 To Len(s1)
v1 = Mid$(s1, i, 1)
sa = Hex(AscW(v1))
buf2(i - 1) = Val("&H" & sa)
Next i
secnr = 1 ' 写卡区的扇区号
status = zlg500B_load_key(mode, secnr, szpwd(0)) '先装载密码
status = zlg500B_authentication(mode, secnr) ' 效验某块扇区的密码
If status = 1 Then
If secnr = 1 Then
MsgBox "密码错误"
End If
End If
status = zlg500B_write(4, buf2(0)) '写数据
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
'If KeyAscii = -24157 Then KeyAscii = 46
If KeyAscii <> 8 Then If KeyAscii <> 46 Then If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -