www.pudn.com > feijiechu_IC_card_reader.rar > frmDemo.frm
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmDemo
BorderStyle = 1 'Fixed Single
Caption = "非接触式IC卡接口函数演示"
ClientHeight = 6105
ClientLeft = 45
ClientTop = 330
ClientWidth = 7215
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6105
ScaleWidth = 7215
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.StatusBar InfoState
Align = 2 'Align Bottom
Height = 420
Left = 0
TabIndex = 24
Top = 5685
Width = 7215
_ExtentX = 12726
_ExtentY = 741
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 2
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 2646
MinWidth = 2646
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 10055
MinWidth = 10055
Text = "Winner Studio (0577)8848030 zhanghua@rocketmail.com"
TextSave = "Winner Studio (0577)8848030 zhanghua@rocketmail.com"
EndProperty
EndProperty
End
Begin VB.Frame fraParameter
Height = 2970
Left = 105
TabIndex = 1
Top = 150
Width = 5055
Begin VB.ComboBox comBlockNo
Height = 300
Left = 1410
TabIndex = 25
Top = 1200
Width = 1320
End
Begin VB.OptionButton optPassWordB
Caption = "B密码"
Height = 285
Left = 2460
TabIndex = 14
Top = 2520
Width = 750
End
Begin VB.OptionButton optPasswordA
Caption = "A密码"
Height = 180
Left = 1365
TabIndex = 13
Top = 2565
Value = -1 'True
Width = 855
End
Begin VB.TextBox txtPasswordB
Height = 300
Left = 1410
TabIndex = 12
Top = 2040
Width = 1305
End
Begin VB.TextBox txtPasswordA
Height = 300
Left = 1410
TabIndex = 11
Top = 1614
Width = 1305
End
Begin VB.TextBox txtSectorNo
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 300
Left = 1410
TabIndex = 6
Top = 768
Width = 1305
End
Begin VB.ComboBox comPort
Height = 300
ItemData = "frmDemo.frx":0000
Left = 1410
List = "frmDemo.frx":000A
TabIndex = 4
Top = 345
Width = 1305
End
Begin VB.Label Label1
Caption = "使用密码:"
Height = 210
Left = 330
TabIndex = 10
Top = 2580
Width = 885
End
Begin VB.Label lblPasswordB
Caption = "B密码:"
Height = 210
Left = 330
TabIndex = 9
Top = 2118
Width = 885
End
Begin VB.Label lblPasswordA
Caption = "A密码:"
Height = 210
Left = 330
TabIndex = 8
Top = 1686
Width = 885
End
Begin VB.Label lblBlockNo
Caption = "块号:"
Height = 210
Left = 330
TabIndex = 7
Top = 1254
Width = 885
End
Begin VB.Label lblSectorNo
Caption = "扇区号:"
Height = 210
Left = 330
TabIndex = 5
Top = 822
Width = 885
End
Begin VB.Label lblPort
Caption = "串口选择:"
Height = 210
Left = 330
TabIndex = 3
Top = 390
Width = 885
End
End
Begin VB.Frame fraResult
Height = 1890
Left = 75
TabIndex = 2
Top = 3150
Width = 7050
Begin VB.TextBox txtValue
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Enabled = 0 'False
Height = 315
Left = 1710
Locked = -1 'True
TabIndex = 22
Top = 1395
Width = 1395
End
Begin MSFlexGridLib.MSFlexGrid DisplayGrid
Height = 1170
Left = 60
TabIndex = 21
Top = 150
Width = 6945
_ExtentX = 12250
_ExtentY = 2064
_Version = 393216
Rows = 3
Cols = 17
RowHeightMin = 360
BackColor = 16777215
BackColorBkg = 12632256
ScrollBars = 0
FormatString = " |00|01|02|03|04|05|06|07|08|09|0A|0B|0C|0D|0E|0F;字节序号|内容(HEX)|内容(ASCII)"
End
Begin VB.Label lblValue
Caption = "数值块,计数单位:"
Enabled = 0 'False
Height = 240
Left = 135
TabIndex = 23
Top = 1440
Width = 1470
End
End
Begin VB.Frame fraMenu
Height = 2985
Left = 5235
TabIndex = 0
Top = 150
Width = 1875
Begin VB.CommandButton cmdMenu
Caption = "减少(数值块)"
Height = 360
Index = 6
Left = 180
TabIndex = 26
Top = 2580
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "增加(数值块)"
Height = 360
Index = 5
Left = 180
TabIndex = 20
Top = 2170
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "初始化(数值块)"
Height = 360
Index = 4
Left = 180
TabIndex = 19
Top = 1763
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "写卡操作"
Height = 360
Index = 3
Left = 180
TabIndex = 18
Top = 1356
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "读卡操作"
Height = 360
Index = 2
Left = 180
TabIndex = 17
Top = 949
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "扇区密码校对"
Height = 360
Index = 1
Left = 180
TabIndex = 16
Top = 542
Width = 1530
End
Begin VB.CommandButton cmdMenu
Caption = "装载密码"
Height = 360
Index = 0
Left = 180
TabIndex = 15
Top = 135
Width = 1530
End
End
End
Attribute VB_Name = "frmDemo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim I As Integer
Dim nRet As Integer
Dim readdata As String * 32
Dim strTempVal As String
Dim strTempAdr1 As String
Dim strTempAdr2 As String
Dim nValue As Long
Const Ka = 0
Const Kb = 4
Private Sub cmdMenu_Click(Index As Integer)
If Trim(txtSectorNo.Text) = "" Then
MsgBox "扇区号不能为空!"
Exit Sub
End If
nRet = OpenComm(comPort.ListIndex)
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "无法打开串口!"
Exit Sub
End If
Select Case Index
Case 0
If optPasswordA.value = True Then
If Trim(txtPasswordA.Text) = "" Then
MsgBox "密码A不能为空!"
Exit Sub
End If
End If
If optPassWordB.value = True Then
If Trim(txtPasswordB.Text) = "" Then
MsgBox "密码B不能为空!"
Exit Sub
End If
End If
InfoState.Panels(1).Text = "装载密码..."
Dim transportkey(1 To 16, 1 To 2) As String * 12
transportkey(1, 1) = "bdde6f378383"
transportkey(2, 1) = "148ac5e22828"
transportkey(3, 1) = "7d3e9f4f9595"
transportkey(4, 1) = "add66b35c8c8"
transportkey(5, 1) = "dfef77bbe4e4"
transportkey(6, 1) = "09844221bcbc"
transportkey(7, 1) = "5fafd7eba5a5"
transportkey(8, 1) = "29148ac59f9f"
transportkey(9, 1) = "fafdfe7fffff"
transportkey(10, 1) = "73399ccebebe"
transportkey(11, 1) = "fc7ebfdfbfbf"
transportkey(12, 1) = "cfe773395151"
transportkey(13, 1) = "f7fb7d3e5a5a"
transportkey(14, 1) = "f2793c1e8d8d"
transportkey(15, 1) = "cfe773394545"
transportkey(16, 1) = "b7db6db67d7d"
transportkey(1, 2) = "bdde6f378383"
transportkey(2, 2) = "148ac5e22828"
transportkey(3, 2) = "7d3e9f4f9595"
transportkey(4, 2) = "add66b35c8c8"
transportkey(5, 2) = "dfef77bbe4e4"
transportkey(6, 2) = "09844221bcbc"
transportkey(7, 2) = "5fafd7eba5a5"
transportkey(8, 2) = "29148ac59f9f"
transportkey(9, 2) = "fafdfe7fffff"
transportkey(10, 2) = "73399ccebebe"
transportkey(11, 2) = "fc7ebfdfbfbf"
transportkey(12, 2) = "cfe773395151"
transportkey(13, 2) = "f7fb7d3e5a5a"
transportkey(14, 2) = "f2793c1e8d8d"
transportkey(15, 2) = "cfe773394545"
transportkey(16, 2) = "b7db6db67d7d"
If optPasswordA.value = True Then
nRet = mif_load_key(Ka, CByte(txtSectorNo.Text), _
transportkey(CByte(txtSectorNo.Text) + 1, 1), _
txtPasswordA.Text)
Else
nRet = mif_load_key(Kb, CByte(txtSectorNo.Text), _
transportkey(CByte(txtSectorNo.Text) + 1, 2), _
txtPasswordB.Text)
End If
If nRet <> 0 Then
InfoState.Panels(1).Text = "密码加载错误!"
Else
InfoState.Panels(1).Text = "操作完成!"
End If
Case 1
InfoState.Panels(1).Text = "扇区密码校对..."
nSnr = 0
readdata = Space(32)
nRet = mif_reset(25)
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "模块复位错误!"
Exit Sub
End If
nRet = mif_request_2(All, tt)
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "无卡!"
Exit Sub
End If
nRet = mif_anticoll(0, nSnr)
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "碰撞检测错误!"
Exit Sub
End If
nRet = mif_select(nSnr, nSize)
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "卡选择错误!"
Exit Sub
End If
If optPasswordA.value = True Then
nRet = mif_authentication(Ka, CByte(txtSectorNo.Text))
Else
nRet = mif_authentication(Kb, CByte(txtSectorNo.Text))
End If
If (nRet <> 0) Then
Beep
InfoState.Panels(1).Text = "密码错误!"
Exit Sub
End If
InfoState.Panels(1).Text = "操作完成!"
Case 2
InfoState.Panels(1).Text = "读卡..."
nRet = mif_read(CByte(comBlockNo.Text), readdata)
If (nRet <> 0) Then
Beep
Beep
InfoState.Panels(1).Text = "读卡错误!"
Exit Sub
End If
Beep
With DisplayGrid
For I = 1 To 16
.TextMatrix(1, I) = Mid(readdata, 2 * I - 1, 2)
.TextMatrix(2, I) = Chr(CharToNum(Mid(readdata, 2 * I - 1, 1)) * 16 + CharToNum(Mid(readdata, 2 * I, 1)))
Next
End With
strTempVal = ""
strTempAdr1 = ""
strTempAdr2 = ""
For I = 9 To 16
strTempVal = strTempVal & NumToChar((15 - CharToNum(Mid(readdata, I, 1))))
Next
For I = 27 To 28
strTempAdr1 = strTempAdr1 & NumToChar((15 - CharToNum(Mid(readdata, I, 1))))
Next
For I = 31 To 32
strTempAdr2 = strTempAdr2 & NumToChar((15 - CharToNum(Mid(readdata, I, 1))))
Next
If Mid(readdata, 1, 8) = Mid(readdata, 17, 8) And _
Mid(readdata, 1, 8) = strTempVal And _
Mid(readdata, 25, 2) = Mid(readdata, 29, 2) And _
Mid(readdata, 27, 2) = Mid(readdata, 31, 2) And _
Mid(readdata, 25, 2) = strTempAdr1 And _
Mid(readdata, 29, 2) = strTempAdr2 Then
lblValue.Enabled = True
txtValue.Enabled = True
nValue = 0
For I = 1 To 4
nValue = nValue * 256 + CharToNum(Mid(readdata, 9 - 2 * I, 1)) * 16 + CharToNum(Mid(readdata, 10 - 2 * I, 1))
Next I
txtValue.Text = nValue
Else
lblValue.Enabled = False
txtValue.Enabled = False
End If
InfoState.Panels(1).Text = "操作完成!"
Case 3
Case 4
If Val(comBlockNo.Text) = Val(txtSectorNo.Text) * 4 + 3 Then
MsgBox "该块不能被初始化为数值块!"
Exit Sub
End If
strTempVal = ""
strTempVal = InputBox("请输入数值", "数值块初始化操作", 0)
If strTempVal = "" Then
Exit Sub
End If
If Not IsNumeric(strTempVal) Then
MsgBox "请正确输入数值!"
Exit Sub
End If
nRet = mif_initval(Val(comBlockNo.Text), CLng(Val(strTempVal)))
If nRet <> 0 Then
InfoState.Panels(1).Text = "初始化错误!"
Exit Sub
End If
Case 5
If Val(comBlockNo.Text) = Val(txtSectorNo.Text) * 4 + 3 Then
MsgBox "不能对该块进行增值操作!"
Exit Sub
End If
strTempVal = ""
strTempVal = InputBox("请输入数值", "数值块增值操作", 0)
If strTempVal = "" Then
Exit Sub
End If
If Not IsNumeric(strTempVal) Then
MsgBox "请正确输入数值!"
Exit Sub
End If
nRet = mif_increment(Val(comBlockNo.Text), CLng(Val(strTempVal)))
If nRet <> 0 Then
InfoState.Panels(1).Text = "增值操作错误!"
Exit Sub
End If
nRet = mif_transfer(Val(comBlockNo.Text))
If nRet <> 0 Then
InfoState.Panels(1).Text = "增值操作错误!"
Exit Sub
End If
cmdMenu_Click 2
Case 6
If Val(comBlockNo.Text) = Val(txtSectorNo.Text) * 4 + 3 Then
MsgBox "不能对该块进行减值操作!"
Exit Sub
End If
strTempVal = ""
strTempVal = InputBox("请输入数值", "数值减值操作", 0)
If strTempVal = "" Then
Exit Sub
End If
If Not IsNumeric(strTempVal) Then
MsgBox "请正确输入数值!"
Exit Sub
End If
nRet = mif_decrement(Val(comBlockNo.Text), CLng(Val(strTempVal)))
If nRet <> 0 Then
InfoState.Panels(1).Text = "减值操作错误!"
Exit Sub
End If
nRet = mif_transfer(Val(comBlockNo.Text))
If nRet <> 0 Then
InfoState.Panels(1).Text = "减值操作错误!"
Exit Sub
End If
cmdMenu_Click 2
End Select
End Sub
Private Sub Form_Load()
comPort.ListIndex = 0
Call IniGrid
End Sub
Private Sub IniGrid()
With DisplayGrid
.FormatString = " |^00|^01|^02|^03|^04|^05|^06|^07|^08|^09|^0A" _
& "|^0B|^0C|^0D|^0E|^0F;字节序号|内容(HEX)|内容(ASCII)"
Dim I As Integer
For I = .FixedCols To .Cols - 1
.ColWidth(I) = 367
Next
For I = 0 To .Rows - 1
Next
End With
End Sub
Private Sub txtSectorNo_Change()
If Trim(txtSectorNo.Text) = "" Then
Exit Sub
End If
If CByte(txtSectorNo.Text) < 0 Or CByte(txtSectorNo.Text) > 15 Then
MsgBox "扇区值无效!"
Exit Sub
End If
comBlockNo.Clear
comBlockNo.AddItem CByte(txtSectorNo.Text) * 4
comBlockNo.AddItem CByte(txtSectorNo.Text) * 4 + 1
comBlockNo.AddItem CByte(txtSectorNo.Text) * 4 + 2
comBlockNo.AddItem CByte(txtSectorNo.Text) * 4 + 3
comBlockNo.ListIndex = 0
End Sub
Private Sub txtSectorNo_KeyPress(KeyAscii As Integer)
KeyAscii = ValidText(KeyAscii, "0123456789", True)
End Sub