?? 讀寫卡機程序.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 + -