Private Declare Function link_com Lib "ICbala32" _
(ByVal port As Long) As Long
Private Declare Function unlink_com Lib "ICbala32" _
(ByVal Code As Long) As Long
Private Declare Function power_on Lib "ICbala32" _
() As Long
Private Declare Function power_off Lib "ICbala32" _
() As Long
Private Declare Function inq_status Lib "ICbala32" _
(ByVal Status As String) As Long
Private Declare Function sel_card Lib "ICbala32" _
(ByVal CardType As Long) As Long
Private Declare Function sel_page Lib "ICbala32" _
(ByVal page As Long) As Long
Private Declare Function read_card Lib "ICbala32" _
(ByVal cmd As Long, ByVal addrh As Long, ByVal addrl As Long, _
ByVal length As Long, ByVal rece As String) As Long
Private Declare Function chk_secret Lib "ICbala32" _
(ByVal cmd As Long, ByVal secret As String) As Long
Private Declare Function write_card Lib "ICbala32" _
(ByVal cmd As Long, ByVal addrh As Long, ByVal addrl As Long, _
ByVal length As Long, ByVal send As String) As Long
Public lICHDc As Long
Public Enum ComConst
enCOM1 = 0
enCOM2 = 1
enCOM3 = 2
enCOM4 = 3
End Enum
Public Enum enICStateType
enInStatus = 0
enPowerStatus = 1
End Enum
Public Sub InitIC(pCom As ComConst)
lICHDc = link_com(pCom)
'Call SetICTypeNPage
End Sub
Public Sub ReleaseIC()
Dim lSuc As Long
lSuc = unlink_com(lICHDc)
If lSuc <> 0 Then
ERR.Raise 1001, , "端口资源释放错误,请检查!错误号:" + CStr(lSuc)
End If
End Sub
Public Sub PowerUpIC()
Dim lSuc As Long
lSuc = power_on()
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡加电错误,请检查!错误号:" + CStr(lSuc)
End If
End Sub
Public Sub PowerDownIC()
Dim lSuc As Long
lSuc = power_off()
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡断电错误,请检查!错误号:" + CStr(lSuc)
End If
End Sub
Public Sub SetICTypeNPage(Optional pCardType As Long = 13, _
Optional pPageNo As Long = 0)
Dim lSuc As Long
lSuc = sel_card(pCardType)
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡类型选择错误,请检查!错误号:" + CStr(lSuc)
End If
lSuc = sel_page(pPageNo)
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡页码选择错误,请检查!错误号:" + CStr(lSuc)
End If
End Sub
Public Function ReadStringFromIC(Optional pStartAddr As Long = 64, _
Optional pLength As Long = 6) As String
Dim tRece As String * 256
Dim cmd As Long
Dim addrh As Long
Dim lSuc As Long
Dim tStr As String
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡数据读取错误,请检查!错误号:" + CStr(lSuc)
Else
tStr = Left(tRece, pLength)
End If
ReadStringFromIC = tStr
End Function
Public Sub CheckICPwd(Optional pICPwd As String = OLD_PWD)
Dim lSuc As Long
Dim cmd As Long
Dim tPwd As String * 6
cmd = 2
tPwd = pICPwd
lSuc = chk_secret(cmd, tPwd)
If lSuc <> 0 Then
Call PowerDownIC
ERR.Raise 1001, , "IC卡密码检测错误,请检查。如果连续发生三次错误,本IC卡将报废!错误号:" + CStr(lSuc)
End If
End Sub
Public Sub WriteStringToIC(pString As String, Optional pStartAddr As Long = 64)
Dim cmd As Long
Dim addrh As Long
Dim tSend As String * 256
Dim tLen As Long
Dim lSuc As Long
If lSuc <> 0 Then
Call PowerDownIC
ERR.Raise 1001, , "IC卡数据写入错误,请检查!错误号:" + CStr(lSuc)
End If
End Sub
Public Function QueryICState(pType As enICStateType) As Boolean
Dim tStr As String * 8
Dim lSuc As Long
lSuc = inq_status(tStr)
If lSuc <> 0 Then
ERR.Raise 1001, , "读写器状态查询错误,请检查!错误号:" + CStr(lSuc)
Else
Select Case pType
Case enInStatus:
If Mid(tStr, 6, 1) = "1" Then
QueryICState = True
Else
QueryICState = False
End If
Case enPowerStatus:
If Mid(tStr, 8, 1) = "1" Then
QueryICState = True
Else
QueryICState = False
End If
End Select
End If
End Function
Public Function ReadICCode() As String
Dim lSuc As Long
Dim tStr As String * 6
lSuc = inq_status(tStr)
If lSuc <> 0 Then
ERR.Raise 1001, , "读写器状态查询错误,请检查!错误号:" + CStr(lSuc)
End If
If Mid(tStr, 6, 1) <> "1" Then
ERR.Raise 1001, , "读写器中无卡,请插入IC卡!"
End If
If Mid(tStr, 8, 1) <> "1" Then
lSuc = power_on()
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡加电错误,请检查!错误号:" + CStr(lSuc)
End If
End If
Call SetICTypeNPage
tStr = ReadStringFromIC()
lSuc = power_off
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡断电错误,请检查!错误号:" + CStr(lSuc)
End If
ReadICCode = tStr
End Function
Public Sub WriteICCode(pString As String)
Dim lSuc As Long
Dim tStr As String * 8
lSuc = inq_status(tStr)
If lSuc <> 0 Then
ERR.Raise 1001, , "读写器状态查询错误,请检查!错误号:" + CStr(lSuc)
End If
If Mid(tStr, 6, 1) <> "1" Then
ERR.Raise 1001, , "读写器中无卡,请插入IC卡!"
End If
If Mid(tStr, 8, 1) <> "1" Then
lSuc = power_on()
If lSuc <> 0 Then
ERR.Raise 1001, , "IC卡加电错误,请检查!错误号:" + CStr(lSuc)
End If
End If
Public Declare Function init_com Lib "sure32wc.dll" (ByVal port As Long) As Long
'初始化串行口: port=0 串行口1 , port=1 串行口2 返回值:0 成功,4 串行口错
Public Declare Function sele_card Lib "sure32wc.dll" (ByVal cardtype As Long) As Long
'选择卡的类型 cardtype =42 为 IC卡 返回值:0 成功
Public Declare Function power_on Lib "sure32wc.dll" () As Long
'给卡上电 返回值: 0成功 ,2无卡 ,4串行口错
'passwordpasswordpasswordpassword
Public Declare Function power_off Lib "sure32wc.dll" () As Long
'卡下电 自弹式读写机同时退卡 返回值:0成功,2无卡,4串行口错
Public Declare Function close_com Lib "sure32wc.dll" () As Long
'关闭串行口 返回值: 0 成功,4 串行口错
Public Declare Function rd_str Lib "sure32wc.dll" (ByVal apz As Long, ByVal address As Long, ByVal length As Long, ByVal buffers As String) As Long
Public Declare Function wr_str Lib "sure32wc.dll" (ByVal apz As Long, ByVal address As Long, ByVal length As Long, ByVal buffers As String) As Long
Public Declare Function rd_asc Lib "sure32wc.dll" (ByVal apz As Long, ByVal address As Long, ByVal length As Long, ByVal buffers As String) As Long
Public Declare Function wr_asc Lib "sure32wc.dll" (ByVal apz As Long, ByVal address As Long, ByVal length As Long, ByVal buffers As String) As Long
'读卡或写卡 :参数apz 为写卡的区域 0为公用区 1为应用数据区 address 为读取或写入的起始地址
'length 为读取或写入的字节数 buffers 为读写数据的缓冲区
Public Declare Function chk_sc Lib "sure32wc.dll" (ByVal i1 As Long, ByVal i2 As Long, ByVal STR As String) As Long
'核对密码 返回值:0 正确,11密码错
Public Declare Function wr_sc Lib "sure32wc.dll" (ByVal STR As String) As Long
'写入新的密码
Public Declare Function inquire Lib "sure32wc.dll" (ByVal STR As String) As Long
'读取读写器状态