Private Sub Read(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ReaderCount As Integer
Dim ReaderCount As Integer
Dim ctr As Integer
Dim sReaderList As String
Dim ctr As Integer
Dim sReaderList As String
For ctr = 0 To 255
sReaderList = sReaderList + vbNullChar
Next
ReaderCount = 255
' 1. Establish context and obtain hContext handle
retCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER, 0, 0, hContext)
' 2. List PC/SC card readers installed in the system
retCode = ModWinsCard.SCardListReaders(hContext, "", sReaderList, ReaderCount)
' Load Available Readers
Call LoadListToControl(cbReader, sReaderList)
cbReader.SelectedIndex = 0
If connActive Then
retCode = ModWinsCard.SCardDisconnect(hCard, ModWinsCard.SCARD_UNPOWER_CARD)
End If
' Shared Connection
retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0 Or ModWinsCard.SCARD_PROTOCOL_T1, hCard, Protocol)
connActive = True
Connect()
End Sub
Public Sub Connect()
Dim tmpStr As String
Dim indx As Integer
validATS = False
Call ClearBuffers()
SendBuff(0) = &HFF ' CLA
SendBuff(1) = &HCA ' INS
SendBuff(3) = &H0 ' P2
SendBuff(4) = &H0 ' Le : Full Length
SendLen = SendBuff(4) + 5
RecvLen = &HFF
retCode = SendAPDUandDisplay(3)
If retCode <> ModWinsCard.SCARD_S_SUCCESS Then
Exit Sub
End If
For indx = 0 To (RecvLen - 3)
tmpStr = tmpStr + Microsoft.VisualBasic.Right("00" & Hex(RecvBuff(indx)), 2) + " "
Next indx
cardUID = tmpStr
Attendace_Menu.Show()
Me.Hide()
End Sub
我的代码需要帮助。我希望它不仅在加载表单时读取智能卡的UID,而且在我取出卡并再次插入时也是如此。它只在我加载表单时读取卡片。我不知道该做什么,因为我是新手编程,这是我的学校项目。
答案 0 :(得分:0)
您可以使用WinSCard库的SCardGetStatusChange函数来观察后台工作线程的变化。