⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contactlessdemovb.frm

📁 omnikey sample app with source
💻 FRM
📖 第 1 页 / 共 3 页
字号:
Private Sub Increment_Click()
Dim ucData(4) As Byte
Dim DataLen As Long
Dim BlockNr As Long


If fCardConnected = False Then
OutPutList.AddItem "Card is not Connected"
StatusText.Text = " ERROR"
GoTo EXITSUB
End If

BlockNr = HexStrToInt(BlockNrText.Text)
DataLen = StrToArray(ucData, 4, IncrementValText.Text)
rc = SCardCLMifareStdIncrementVal(hCard, BlockNr, ucData(LBound(ucData)), DataLen)
If rc = 0 Then
OutPutList.AddItem "Value has been incremented  Successfully"
StatusText.Text = " SUCCESS"

End If

If rc <> 0 Then
OutPutList.AddItem "Error in  SCardCLMifareStdIncrementVal"
OutPutList.AddItem HandleError(rc)
StatusText.Text = " ERROR"

End If

EXITSUB:

OutPutList.ListIndex = OutPutList.ListCount - 1
End Sub

Private Sub OptionKey_Click()
AuthenKeyNrText.Text = ""
End Sub

Private Sub OptionKeyNr_Click()
AuthenKeyNrText.Text = "00"
End Sub

Private Sub Read_Click()

Dim BlockNr As Long
Dim ucData(16) As Byte
Dim NumofDataLen As Long

If fCardConnected = False Then
OutPutList.AddItem " At first Card has to be connected"
StatusText.Text = " ERROR"
GoTo EXITSUB
End If



BlockNr = HexStrToInt(BlockNrText.Text)
NumofDataLen = 16
rc = SCardCLMifareStdRead(hCard, BlockNr, ucData(LBound(ucData)), 16, NumofDataLen)

If rc = 0 Then
OutPutList.AddItem "Reading has been done successfully"
StatusText.Text = " SUCCESS"
DataReadText = HexDump(ucData, NumofDataLen)
End If

If rc <> 0 Then
OutPutList.AddItem "Error in  SCardCLMifareStdRead"
OutPutList.AddItem HandleError(rc)
StatusText.Text = " ERROR"

End If

EXITSUB:
OutPutList.ListIndex = OutPutList.ListCount - 1
End Sub

Private Sub ReaderList_Click()
Dim i As Integer

OutPutList.AddItem "Selected Reader is "
OutPutList.AddItem ReaderList.Text
SelectedReader = ReaderList.Text
End Sub
Private Function GetCardName() As String

CardNameText = "UNKNOWN CARD"
' atr with old driver
If ATRLen = 17 Then
If ATR(1) = 15 Then
If ATR(16) = 17 Then
CardNameText = "Mifare Standard 1K"
End If
If ATR(16) = 33 Then
CardNameText = "Mifare Standard 4K"
End If
If ATR(16) = 49 Then
CardNameText = "Mifare Ultra Light"
End If
If ATR(16) = 22 Then
CardNameText = "AT88RF020"
End If
If ATR(16) = 38 Then
CardNameText = "AT88SC6416CRF"
End If
If ATR(16) = 229 Then
CardNameText = "STm SR176"
End If
If ATR(16) = 245 Then
CardNameText = "STm SRI X4K"
End If
If ATR(16) = 24 Then
CardNameText = "I.CODE 1"
End If
If ATR(16) = 131 Then
CardNameText = "iClass"
End If
If ATR(16) = 212 Then
CardNameText = "KSW TempSens"
End If
If ATR(16) = 20 Then
CardNameText = "SRF55V10P"
End If
If ATR(16) = 180 Then
CardNameText = "I.CODE SLI"
End If
If ATR(16) = 148 Then
CardNameText = "Tag It"
End If
If ATR(16) = 164 Then
CardNameText = "X-ident STm LRI 512"
End If
If ATR(16) = 195 Then
CardNameText = "iCLASS 2K"
End If
If ATR(16) = 147 Then
CardNameText = "iCLASS 2KS"
End If
If ATR(16) = 211 Then
CardNameText = "iCLASS 16K"
End If
If ATR(16) = 163 Then
CardNameText = "iCLASS 16KS"
End If
If ATR(16) = 227 Then
CardNameText = "iCLASS 8x2K"
End If
If ATR(16) = 179 Then
CardNameText = "iCLASS 8x2KS"
End If

End If
End If



' atr with new driver Pc/Sc

If ATRLen = 20 Then
If ATR(13) = 0 Then
If ATR(14) = 1 Then
CardNameText = "Mifare Standard 1K"
End If
If ATR(14) = 2 Then
CardNameText = "Mifare Standard 4K"
End If
If ATR(14) = 3 Then
CardNameText = "Mifare Ultra Light"
End If
If ATR(14) = 4 Then
CardNameText = "SLE55R_XXXX"
End If
If ATR(14) = 6 Then
CardNameText = "SR176"
End If
If ATR(14) = 7 Then
CardNameText = "SRI_X4K"
End If
If ATR(14) = 8 Then
CardNameText = "AT88RF020"
End If
If ATR(14) = 9 Then
CardNameText = "AT88SC0204CRF"
End If
If ATR(14) = 10 Then
CardNameText = "AT88SC0808CRF"
End If
If ATR(14) = 11 Then
CardNameText = "AT88SC1616RF"
End If
If ATR(14) = 12 Then
CardNameText = "AT88SC3216CRF"
End If
If ATR(14) = 13 Then
CardNameText = "AT88SC6416CRF"
End If
If ATR(14) = 14 Then
CardNameText = "SRF55V10P"
End If
If ATR(14) = 15 Then
CardNameText = "SRF55V02P"
End If
If ATR(14) = 16 Then
CardNameText = "SRF55V10S"
End If
If ATR(14) = 17 Then
CardNameText = "SRF55V02S"
End If
If ATR(14) = 18 Then
CardNameText = "TAG_IT"
End If
If ATR(14) = 19 Then
CardNameText = "LRI512"
End If
If ATR(14) = 20 Then
CardNameText = "ICODE.SII"
End If
If ATR(14) = 21 Then
CardNameText = "TEMPSENS"
End If
If ATR(14) = 22 Then
CardNameText = "i.CODE1"
End If
If ATR(14) = 24 Then
CardNameText = "iCLASS2KS"
End If
If ATR(14) = 26 Then
CardNameText = "iCLASS16KS"
End If
If ATR(14) = 28 Then
CardNameText = "iCLASS8x2KS"
End If
If ATR(14) = 29 Then
CardNameText = "iCLASS32KS_16_16"
End If
If ATR(14) = 30 Then
CardNameText = "iCLASS32KS_16_8x2"
End If
If ATR(14) = 31 Then
CardNameText = "iCLASS32KS_8x2_16"
End If
If ATR(14) = 32 Then
CardNameText = "iCLASS32KS_8x2_8x2"
End If

End If
End If

GetCardName = CardNameText
End Function


Private Sub RefreshOutput_Click()
OutPutList.Clear

End Sub

Private Sub Write_Click()

Dim BlockNr As Long
Dim ucData(16) As Byte
Dim DataLen As Long
BlockNr = HexStrToInt(BlockNrText.Text)

If fCardConnected = False Then
OutPutList.AddItem " At first Card has to be connected"
StatusText.Text = " ERROR"
GoTo EXITSUB
End If

If BlockNr < 128 Then
If ((BlockNr + 1) Mod 4) = 0 Then
OutPutList.AddItem " Sector block cannot be written with this applpication"
StatusText.Text = " ERROR"
GoTo EXITSUB
End If
End If
If BlockNr > 128 Then
If ((BlockNr + 1) Mod 16) = 0 Then
OutPutList.AddItem " Sector block cannot be written with this applpication "
StatusText.Text = " ERROR"
GoTo EXITSUB
End If
End If


DataLen = StrToArray(ucData, 16, DataWriteText.Text)

rc = SCardCLMifareStdWrite(hCard, BlockNr, ucData(LBound(ucData)), DataLen)
If rc = 0 Then
OutPutList.AddItem " Data has been written successfully"
StatusText.Text = " SUCCESS"
End If
If rc <> 0 Then
OutPutList.AddItem " Error in writting Data "
StatusText.Text = " ERROR"
OutPutList.AddItem HandleError(rc)
End If

EXITSUB:
OutPutList.ListIndex = OutPutList.ListCount - 1

End Sub

Private Sub WriteMifKeyToReader_Click()
Dim MifKeyToReader(6) As Byte
Dim MifKeyNr As Long
Dim KeyLen As Long

MifKeyNr = HexStrToInt(MifKeyToReaderNrText.Text)
KeyLen = StrToArray(MifKeyToReader, 6, MifareKeyToReaderText.Text)

rc = SCardCLWriteMifareKeyToReader(hCard, hContext, SelectedReader, MifKeyNr, KeyLen, MifKeyToReader(LBound(MifKeyToReader)), False, 0)

If rc = 0 Then
OutPutList.AddItem " Mifare key has been writen to the reader successfully"
StatusText.Text = " SUCCESS"
End If
If rc <> 0 Then
OutPutList.AddItem " Error in writting Mifare key to the reader "
OutPutList.AddItem HandleError(rc)
StatusText.Text = " ERROR"
End If

OutPutList.ListIndex = OutPutList.ListCount - 1
End Sub

Private Function HandleError(ByVal rc As Long) As String

HandleError = "Unknown Error"
If rc = OKERR_OK Then HandleError = "No Error"
If rc = OKERR_SCARD__E_CANCELLED Then HandleError = "The action was cancelled by an SCardCancel request"
If rc = OKERR_SCARD__E_INVALID_HANDLE Then HandleError = "The supplied handle was invalid"
If rc = OKERR_SCARD__E_INVALID_PARAMETER Then HandleError = "One or more of the supplied parameters could not be properly interpreted"
If rc = OKERR_SCARD__E_INVALID_TARGET Then HandleError = "Registry startup information is missing or invalid"
If rc = OKERR_SCARD__E_NO_MEMORY Then HandleError = "Not enough memory available to complete this command"
If rc = OKERR_SCARD__F_WAITED_TOO_LONG Then HandleError = "An internal consistency timer has expired"
If rc = OKERR_SCARD__E_INSUFFICIENT_BUFFER Then HandleError = "The data buffer to receive returned data is too small for the returned data"
If rc = OKERR_SCARD__E_UNKNOWN_READER Then HandleError = "The specified reader name is not recognized"
If rc = OKERR_SCARD__E_TIMEOUT Then HandleError = "The user-specified timeout value has expired"
If rc = OKERR_SCARD__E_SHARING_VIOLATION Then HandleError = "The smart card cannot be accessed because of other connections outstanding"
If rc = OKERR_SCARD__E_NO_SMARTCARD Then HandleError = "The operation requires a Smart Card, but no Smart Card is currently in the device"
If rc = OKERR_SCARD__E_UNKNOWN_CARD Then HandleError = "The specified smart card name is not recognized"
If rc = OKERR_SCARD__E_CANT_DISPOSE Then HandleError = "The system could not dispose of the media in the requested manner"
If rc = OKERR_SCARD__E_PROTO_MISMATCH Then HandleError = "The requested protocols are incompatible with the protocol currently in use with the smart card"
If rc = OKERR_SCARD__E_NOT_READY Then HandleError = "The reader or smart card is not ready to accept commands"
If rc = OKERR_SCARD__E_INVALID_VALUE Then HandleError = "One or more of the supplied parameters values could not be properly interpreted"
If rc = OKERR_SCARD__E_SYSTEM_CANCELLED Then HandleError = "The action was cancelled by the system, presumably to log off or shut down"
If rc = OKERR_SCARD__F_COMM_ERROR Then HandleError = "An internal communications error has been detected"
If rc = OKERR_SCARD__F_UNKNOWN_ERROR Then HandleError = "An internal error has been detected, but the source is unknown"
If rc = OKERR_SCARD__E_INVALID_ATR Then HandleError = "An ATR obtained from the registry is not a valid ATR string"
If rc = OKERR_SCARD__E_NOT_TRANSACTED Then HandleError = "An attempt was made to end a non-existent transaction"
If rc = OKERR_SCARD__E_READER_UNAVAILABLE Then HandleError = "The specified reader is not currently available for use"
If rc = OKERR_SCARD__P_SHUTDOWN Then HandleError = "The operation has been aborted to allow the server application to exit"
If rc = OKERR_SCARD__E_PCI_TOO_SMALL Then HandleError = "The PCI Receive buffer was too small"
If rc = OKERR_SCARD__E_READER_UNSUPPORTED Then HandleError = "The reader driver does not meet minimal requirements for support"
If rc = OKERR_SCARD__E_DUPLICATE_READER Then HandleError = "The reader driver did not produce a unique reader name"
If rc = OKERR_SCARD__E_CARD_UNSUPPORTED Then HandleError = "The smart card does not meet minimal requirements for support"
If rc = OKERR_SCARD__E_NO_SERVICE Then HandleError = "The Smart card resource manager is not running"
If rc = OKERR_SCARD__E_SERVICE_STOPPED Then HandleError = "The Smart card resource manager has shut down"
If rc = OKERR_SCARD__E_UNEXPECTED Then HandleError = "An unexpected card error has occurred"
If rc = OKERR_SCARD__E_ICC_INSTALLATION Then HandleError = "No Primary Provider can be found for the smart card"
If rc = OKERR_SCARD__E_ICC_CREATEORDER Then HandleError = "The requested order of object creation is not supported"
If rc = OKERR_SCARD__E_UNSUPPORTED_FEATURE Then HandleError = "This smart card does not support the requested feature"
If rc = OKERR_SCARD__E_DIR_NOT_FOUND Then HandleError = "The identified directory does not exist in the smart card"
If rc = OKERR_SCARD__E_FILE_NOT_FOUND Then HandleError = "The identified file does not exist in the smart card"
If rc = OKERR_SCARD__E_NO_DIR Then HandleError = "The supplied path does not represent a smart card directory"
If rc = OKERR_SCARD__E_NO_FILE Then HandleError = "The supplied path does not represent a smart card file"
If rc = OKERR_SCARD__E_NO_ACCESS Then HandleError = "Access is denied to this file"
If rc = OKERR_SCARD__E_WRITE_TOO_MANY Then HandleError = "An attempt was made to write more data than would fit in the target object"
If rc = OKERR_SCARD__E_BAD_SEEK Then HandleError = "There was an error trying to set the smart card file object pointer"
If rc = OKERR_SCARD__E_INVALID_CHV Then HandleError = "The supplied PIN is incorrect"
If rc = OKERR_SCARD__E_UNKNOWN_RES_MNG Then HandleError = "An unrecognized error code was returned from a layered component"
If rc = OKERR_SCARD__E_NO_SUCH_CERTIFICATE Then HandleError = "The requested certificate does not exist"
If rc = OKERR_SCARD__E_CERTIFICATE_UNAVAILABLE Then HandleError = "The requested certificate could not be obtained"
If rc = OKERR_SCARD__E_NO_READERS_AVAILABLE Then HandleError = "Cannot find a smart card reader"
If rc = OKERR_SCARD__E_COMM_DATA_LOST Then HandleError = "A communications error with the smart card has been detected"
If rc = OKERR_SCARD__W_UNSUPPORTED_CARD Then HandleError = "The reader cannot communicate with the smart card, due to ATR configuration conflicts"
If rc = OKERR_SCARD__W_UNRESPONSIVE_CARD Then HandleError = "The smart card is not responding to a reset"
If rc = OKERR_SCARD__W_UNPOWERED_CARD Then HandleError = "Power has been removed from the smart card, so that further communication is not possible"
If rc = OKERR_SCARD__W_RESET_CARD Then HandleError = "The smart card has been reset, so any shared state information is invalid"
If rc = OKERR_SCARD__W_REMOVED_CARD Then HandleError = "The smart card has been removed, so that further communication is not possible"
If rc = OKERR_SCARD__W_SECURITY_VIOLATION Then HandleError = "Access was denied because of a security violation"
If rc = OKERR_SCARD__W_WRONG_CHV Then HandleError = "The card cannot be accessed because the wrong PIN was presented"
If rc = OKERR_SCARD__W_CHV_BLOCKED Then HandleError = "The card cannot be accessed because the maximum number of PIN entry attempts has been reached"
If rc = OKERR_SCARD__W_EOF Then HandleError = "The end of the smart card file has been reached"
If rc = OKERR_SCARD__W_CANCELLED_BY_USER Then HandleError = "The action was cancelled by the user"

If rc = OKERR_PARM1 Then HandleError = "Error in parameter 1"
If rc = OKERR_PARM2 Then HandleError = "Error in parameter 2"
If rc = OKERR_PARM3 Then HandleError = "Error in parameter 3"
If rc = OKERR_PARM4 Then HandleError = "Error in parameter 4"
If rc = OKERR_PARM5 Then HandleError = "Error in parameter 5"
If rc = OKERR_PARM6 Then HandleError = "Error in parameter 6"
If rc = OKERR_PARM7 Then HandleError = "Error in parameter 7"
If rc = OKERR_PARM8 Then HandleError = "Error in parameter 8"
If rc = OKERR_PARM9 Then HandleError = "Error in parameter 9"
If rc = OKERR_PARM10 Then HandleError = "Error in parameter 10"
If rc = OKERR_PARM11 Then HandleError = "Error in parameter 11"
If rc = OKERR_PARM12 Then HandleError = "Error in parameter 12"
If rc = OKERR_PARM13 Then HandleError = "Error in parameter 13"
If rc = OKERR_PARM14 Then HandleError = "Error in parameter 14"
If rc = OKERR_PARM15 Then HandleError = "Error in parameter 15"
If rc = OKERR_PARM16 Then HandleError = "Error in parameter 16"
If rc = OKERR_PARM17 Then HandleError = "Error in parameter 17"
If rc = OKERR_PARM18 Then HandleError = "Error in parameter 18"
If rc = OKERR_PARM19 Then HandleError = "Error in parameter 19"
If rc = OKERR_INSUFFICIENT_PRIV Then HandleError = "You currently do not have the rights to execute the requested action. Usually a password has to be presented in advance."
If rc = OKERR_PW_WRONG Then HandleError = "The presented password is wrong"
If rc = OKERR_PW_LOCKED Then HandleError = "The password has been presented several times wrong and is therefore locked. Usually use some administrator tool to unblock it."
If rc = OKERR_PW_TOO_SHORT Then HandleError = "The lenght of the password was too short."
If rc = OKERR_PW_TOO_LONG Then HandleError = "The length of the password was too long."
If rc = OKERR_PW_NOT_LOCKED Then HandleError = "The password is not locked"
If rc = OKERR_ITEM_NOT_FOUND Then HandleError = "An item (e.g. a key of a specific name) could not be found"
If rc = OKERR_ITEMS_LEFT Then HandleError = "There are still items left, therefore e.g. the directory / structure etc. can't be deleted."
If rc = OKERR_INVALID_CFG_FILE Then HandleError = "Invalid configuration file"
If rc = OKERR_SECTION_NOT_FOUND Then HandleError = "Section not found"
If rc = OKERR_ENTRY_NOT_FOUND Then HandleError = "Entry not found"
If rc = OKERR_NO_MORE_SECTIONS Then HandleError = "No more sections"
If rc = OKERR_ITEM_ALREADY_EXISTS Then HandleError = "The specified item alread exists."
If rc = OKERR_ITEM_EXPIRED Then HandleError = "Some item (e.g. a certificate) has expired."
If rc = OKERR_UNEXPECTED_RET_VALUE Then HandleError = "Unexpected return value"
If rc = OKERR_COMMUNICATE Then HandleError = "General communication error"
If rc = OKERR_NOT_ENOUGH_MEMORY Then HandleError = "Not enough memory"
If rc = OKERR_BUFFER_OVERFLOW Then HandleError = "Buffer overflow"
If rc = OKERR_TIMEOUT Then HandleError = "A timeout has occurred"
If rc = OKERR_NOT_SUPPORTED Then HandleError = "The requested functionality is not supported at this time / under this OS / in this situation etc."
If rc = OKERR_ILLEGAL_ARGUMENT Then HandleError = "Illegal argument"
If rc = OKERR_READ_FIO Then HandleError = "File IO read error"
If rc = OKERR_WRITE_FIO Then HandleError = "File IO write error"
If rc = OKERR_INVALID_HANDLE Then HandleError = "Invalid handle"
If rc = OKERR_GENERAL_FAILURE Then HandleError = "General failure."
If rc = OKERR_FILE_NOT_FOUND Then HandleError = "File not found"
If rc = OKERR_OPEN_FILE Then HandleError = "File opening failed"
If rc = OKERR_SEM_USED Then HandleError = "The semaphore is currently use by an other process"
If rc = OKERR_NOP Then HandleError = "No operation done"
If rc = OKERR_NOK Then HandleError = "Function not executed"
If rc = OKERR_FWBUG Then HandleError = "Internal error detected"
If rc = OKERR_INIT Then HandleError = "Module not initialized"
If rc = OKERR_FIO Then HandleError = "File IO error detected"
If rc = OKERR_ALLOC Then HandleError = "Cannot allocate memory"
If rc = OKERR_SESSION_ERR Then HandleError = "General error"
If rc = OKERR_ACCESS_ERR Then HandleError = "Access not allowed"
If rc = OKERR_OPEN_FAILURE Then HandleError = "An open command was not successful"
If rc = OKERR_CARD_NOT_POWERED Then HandleError = "Card is not powered"
If rc = OKERR_ILLEGAL_CARDTYPE Then HandleError = "Illegal cardtype"
If rc = OKERR_CARD_NOT_INSERTED Then HandleError = "Card not inserted"
If rc = OKERR_NO_DRIVER Then HandleError = "No device driver installed"
If rc = OKERR_OUT_OF_SERVICE Then HandleError = "The service is currently not available"
If rc = OKERR_EOF_REACHED Then HandleError = "End of file reached"
If rc = OKERR_ON_BLACKLIST Then HandleError = "The ID is on a blacklist, the requested action is therefore not allowed."
If rc = OKERR_CONSISTENCY_CHECK Then HandleError = "Error during consistency check"
If rc = OKERR_IDENTITY_MISMATCH Then HandleError = "The identity does not match a defined cross-check identity"
If rc = OKERR_MULTIPLE_ERRORS Then HandleError = "Multiple errors have occurred. Use this if there is only the possibility to return one error code, but there happened different errors before (e.g. each thread returned a different error and the controlling thread may only report one)."
If rc = OKERR_ILLEGAL_DRIVER Then HandleError = "Illegal driver"
If rc = OKERR_ILLEGAL_FW_RELEASE Then HandleError = "The connected hardware whose firmware is not useable by this software"
If rc = OKERR_NO_CARDREADER Then HandleError = "No cardreader attached"
If rc = OKERR_IPC_FAULT Then HandleError = "General failure of inter process communication"
If rc = OKERR_WAIT_AND_RETRY Then HandleError = "The service currently does not take calls. The task has to go back to the message loop and try again at a later time (Windows 3.1 only). The code may also be used, in every situation where a 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -