vb编写activeX控件实现b/s架构上与硬件操作

时间:2022-12-19 21:05:06
 Private Declare Function openC Lib "YKTClient.dll" Alias _
"ykt_opencard" (ByVal nDeviceType As Long, ByVal nCom As Long, ByVal nBaud As Long, ByVal pRegion As String, ByVal pErrmsg As String) As Long
'读取尚未个人化的正式卡
Private Declare Function ykt_readcardno Lib "YKTClient.dll" Alias _
"ykt_readopeninitcardno" (ByVal pRegion As String, ByVal pDeptid As String, ByVal pDeptpass As String, ByVal pCardno As String, ByVal pCardtype As String, ByVal pErrmsg As String) As Long
Private Declare Function closeC Lib "YKTClient.dll" Alias _
"ykt_closecard" (ByVal pErrmsg As String) As Long
'读正式卡
Private Declare Function ykt_readcardno2 Lib "YKTClient.dll" Alias _
"ykt_readopencardno" (ByVal pRegion As String, ByVal pDeptid As String, ByVal pDeptpass As String, ByVal pCardno As String, ByVal pCardtype As String, ByVal pErrmsg As String) As Long
Public Function getcardtype() As String
   Dim status As Long
   Dim pRegion As String
   pRegion = Space$(2)
   pRegion = "XM"
   Dim pCardno As String
   pCardno = Space$(16)
   Dim pCardtype As String
   pCardtype = Space$(1)
   Dim pErrmsg As String
   pErrmsg = Space$(1024)
   status = ykt_readcardno(pRegion, "1111", "111111", pCardno, pCardtype, pErrmsg)
getcardtype = pCardtype
End Function
Public Function opencard() As Long
 
  Dim pErrmsg As String
   pErrmsg = Space$(1024)
   Dim pRegion As String
   pRegion = Space$(2)
   pRegion = "XM"
   Dim flag As Long
 
   flag = openC(10, 9, 3, pRegion, pErrmsg)

End Function
Public Function closecard() As Long
   Dim pErrmsg As String
   pErrmsg = Space$(1024)
   Dim flag As Long
   flag = closeC(pErrmsg)
End Function
Public Function read() As String
Dim card As String
Dim status As Long
status = opencard()
If status = 0 Then '卡具打开成功
   Dim pRegion As String
   pRegion = Space$(2)
   pRegion = "XM"
   Dim pCardno As String
   pCardno = Space$(16)
   Dim pCardtype As String
   pCardtype = Space$(1)
   Dim pErrmsg As String
   pErrmsg = Space$(1024)
   Dim type_ As String
  
   type_ = getcardtype()
   If type_ = "A" Then '正式卡
       status = ykt_readcardno(pRegion, "1111", "111111", pCardno, pCardtype, pErrmsg)
   ElseIf type_ = "B" Then '临时卡
  
   Else
       status = ykt_readcardno2(pRegion, "1111", "111111", pCardno, pCardtype, pErrmsg)
   End If
   status = closecard()  '否则关闭卡具
End If
read = pCardno
End Function