📄 frmdemo.frm
字号:
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -