Commit 05bef9cd by developer33

Project files added, submodule added

parents
obj
*.o
.vs
*.suo
*.csproj.user
*.pdb
*.vshost.*
\ No newline at end of file
[submodule "ufr-lib"]
path = ufr-lib
url = https://git.d-logic.net/nfc-rfid-reader-sdk/ufr-lib.git
"""
"""
UFCODER_ERROR_CODES = {
0x00 :'UFR_OK',
0x01 :'UFR_COMMUNICATION_ERROR',
0x02 :'UFR_CHKSUM_ERROR',
0x03 :'UFR_READING_ERROR',
0x04 :'UFR_WRITING_ERROR',
0x05 :'UFR_BUFFER_OVERFLOW',
0x06 :'UFR_MAX_ADDRESS_EXCEEDED',
0x07 :'UFR_MAX_KEY_INDEX_EXCEEDED',
0x08 :'UFR_NO_CARD',
0x09 :'UFR_COMMAND_NOT_SUPPORTED',
0x0A :'UFR_FORBIDEN_DIRECT_WRITE_IN_SECTOR_TRAILER',
0x0B :'UFR_ADDRESSED_BLOCK_IS_NOT_SECTOR_TRAILER',
0x0C :'UFR_WRONG_ADDRESS_MODE',
0x0D :'UFR_WRONG_ACCESS_BITS_VALUES',
0x0E :'UFR_AUTH_ERROR',
0x0F :'UFR_PARAMETERS_ERROR',
0x10 :'UFR_MAX_SIZE_EXCEEDED',
0x70 :'UFR_WRITE_VERIFICATION_ERROR',
0x71 :'UFR_BUFFER_SIZE_EXCEEDED',
0x72 :'UFR_VALUE_BLOCK_INVALID',
0x73 :'UFR_VALUE_BLOCK_ADDR_INVALID',
0x74 :'UFR_VALUE_BLOCK_MANIPULATION_ERROR',
0x75 :'UFR_WRONG_UI_MODE',
0x76 :'UFR_KEYS_LOCKED',
0x77 :'UFR_KEYS_UNLOCKED',
0x78 :'UFR_WRONG_PASSWORD',
0x79 :'UFR_CAN_NOT_LOCK_DEVICE',
0x7A :'UFR_CAN_NOT_UNLOCK_DEVICE',
0x7B :'UFR_DEVICE_EEPROM_BUSY',
0x7C :'UFR_RTC_SET_ERROR',
0x50 :'UFR_COMMUNICATION_BREAK',
0x51 :'UFR_NO_MEMORY_ERROR',
0x52 :'UFR_CAN_NOT_OPEN_READER',
0x53 :'UFR_READER_NOT_SUPPORTED',
0x54 :'UFR_READER_OPENING_ERROR',
0x55 :'UFR_READER_PORT_NOT_OPENED',
0x56 :'UFR_CANT_CLOSE_READER_PORT',
0xA0 :'UFR_FT_STATUS_ERROR_1',
0xA1 :'UFR_FT_STATUS_ERROR_2',
0xA2 :'UFR_FT_STATUS_ERROR_3',
0xA3 :'UFR_FT_STATUS_ERROR_4',
0xA4 :'UFR_FT_STATUS_ERROR_5',
0xA5 :'UFR_FT_STATUS_ERROR_6',
0xA6 :'UFR_FT_STATUS_ERROR_7',
0xA7 :'UFR_FT_STATUS_ERROR_8',
0xA8 :'UFR_FT_STATUS_ERROR_9',
0x3E8: 'Undocummented error',
0x3E9: 'Undocummented error',
0xFFFFFFFF :'MAX_UFR_STATUS',
}
####################################################################
DESFIRE_ERROR_CODES = {
0xBB7 : 'READER_ERROR', #// 2999 [dec]
0xBB8 : 'NO_CARD_DETECTED', #// 3000 [dec]
0xBB9 : 'CARD_OPERATION_OK', #// 3001 [dec]
0xBBA : 'WRONG_KEY_TYPE', #// 3002 [dec]
0xBBB : 'KEY_AUTH_ERROR', #// 3003 [dec]
0xBBC : 'CARD_CRYPTO_ERROR', #// 3004 [dec]
0xBBD : 'READER_CARD_COMM_ERROR', #// 3005 [dec]
0xBBE : 'PC_READER_COMM_ERROR', #// 3006 [dec]
0xBBF : 'COMMIT_TRANSACTION_NO_REPLY', #// 3007 [dec]
0x0BC0 : 'COMMIT_TRANSACTION_ERROR', #// 3008 [dec]
0x0C0C : 'DESFIRE_CARD_NO_CHANGES',
0x0C03 : 'DESFIRE_CARD_OUT_OF_EEPROM_ERROR',
0x0C1C : 'DESFIRE_CARD_ILLEGAL_COMMAND_CODE',
0x0C1E : 'DESFIRE_CARD_INTEGRITY_ERROR',
0x0C40 : 'DESFIRE_CARD_NO_SUCH_KEY',
0x0C7E : 'DESFIRE_CARD_LENGTH_ERROR',
0x0C9D : 'DESFIRE_CARD_PERMISSION_DENIED',
0x0C93 : 'DESFIRE_CARD_PARAMETER_ERROR',
0x0CA0 : 'DESFIRE_CARD_APPLICATION_NOT_FOUND',
0x0CA1 : 'DESFIRE_CARD_APPL_INTEGRITY_ERROR',
0x0CAE : 'DESFIRE_CARD_AUTHENTICATION_ERROR',
0x0CAF : 'DESFIRE_CARD_ADDITIONAL_FRAME',
0x0CBE : 'DESFIRE_CARD_BOUNDARY_ERROR',
0x0CC1 : 'DESFIRE_CARD_PICC_INTEGRITY_ERROR',
0x0CCA : 'DESFIRE_CARD_COMMAND_ABORTED',
0x0CCD : 'DESFIRE_CARD_PICC_DISABLED_ERROR',
0x0CCE : 'DESFIRE_CARD_COUNT_ERROR',
0x0CDE : 'DESFIRE_CARD_DUPLICATE_ERROR',
0x0CEE : 'DESFIRE_CARD_EEPROM_ERROR_DES',
0x0CF0 : 'DESFIRE_CARD_FILE_NOT_FOUND',
0x0CF1 : 'DESFIRE_CARD_FILE_INTEGRITY_ERROR',
}
\ No newline at end of file
File added
This diff is collapsed. Click to expand it.
File added
import ctypes
from ctypes import *
import sys
import platform
import os
import array
import ErrorCodes
from Functions import *
import struct
##########################################################################
# dll loading
if sys.platform.startswith('win'):
from ctypes import windll
import msvcrt
if platform.architecture()[0] == '32bit': # used for specifying lib for OS version, 32/64bit
uFR = ctypes.windll.LoadLibrary("ufr-lib//windows//x86//uFCoder-x86.dll")
elif platform.architecture()[0] == '64bit':
uFR = ctypes.windll.LoadLibrary("ufr-lib//windows//x86_64//uFCoder-x86_64.dll")
elif sys.platform.startswith('linux'):
uFR = cdll.LoadLibrary("ufr-lib//linux//x86//libuFCoder-x86.so")
elif sys.platform.startswith('darwin'):
uFR = cdll.LoadLibrary("ufr-lib//macos//x86_64//libuFCoder-x86_64.dylib")
##########################################################################
def usage():
print(" +------------------------------------------------+")
print(" | uFR NDEF example |")
print(" +------------------------------------------------+")
print(" --------------------------------------------------")
print(" (1) - Read NDEF records")
print(" (2) - Write NDEF record")
print(" (3) - Initialize card for NDEF messages")
print(" (4) - Erase last NDEF record")
print(" (5) - Erase all NDEF records")
print(" --------------------------------------------------")
##########################################################################
def menu(key):
if str(key) == "1":
ndefReadRecords()
elif str(key) == "2":
ndefWriteRecords()
elif str(key) == "3":
ndefInitCard()
elif str(key) == "4":
ndefEraseLastRecord()
elif str(key) == "5":
ndefEraseAllRecords()
else:
usage()
print(" --------------------------------------------------");
##########################################################################
def ReaderOpenEx(reader_type, port_name, port_interface, arg):
openReader = uFR.ReaderOpenEx
openReader.argtypes = (c_uint32, c_char_p, c_uint32, c_void_p)
openReader.restype = c_uint
b = c_char_p(port_name.encode('utf-8'))
return openReader(reader_type, b, port_interface, arg)
##########################################################################
def ReaderOpen():
openReader = uFR.ReaderOpen
return openReader()
##########################################################################
def ReaderUISignal(light, sound):
uiSignal = uFR.ReaderUISignal
uiSignal.argtypes = (c_ubyte, c_ubyte)
uiSignal.restype = c_uint
uiSignal(light, sound)
##########################################################################
def ReaderClose():
func = uFR.ReaderClose
return func()
##########################################################################
if __name__ == '__main__':
# For opening uFR Nano Online UDP mode use:
# status = ReaderOpenEx(0, "ip_address:port_number", 85, 0)
#
# For opening uFR Nano Online TCP/IP mode use:
# status = ReaderOpenEx(0, "ip address:port_number", 84, 0)
#
# For opening uFR Nano Online without reset/RTS on ESP32 - transparent mode 115200 use:
# status = ReaderOpenEx(2, 0, 0, "UNIT_OPEN_RESET_DISABLE")
print("---------------------------------------------")
print("https://www.d-logic.net/nfc-rfid-reader-sdk/")
print("---------------------------------------------")
print("Desfire console example application version 1.0")
print("---------------------------------------------")
print("Choose reader opening mode:")
print("1. Simple reader open")
print("2. Advanced reader open")
mode = input()
mode = int(mode)
print(mode)
if mode == 1:
status = ReaderOpen()
elif mode == 2:
print("Enter reader type:")
reader_type = input()
reader_type = int(reader_type)
print ("Enter port name:")
port_name = input()
print("Enter port interface:")
port_interface = input()
print("Enter additional argument:")
arg = input()
if port_interface == "U":
port_interface = 85
elif port_interface == "T":
port_interface = 84
else:
port_interface = int(port_interface)
status = ReaderOpenEx(reader_type, port_name, port_interface, arg)
# for uFR online example:
# status = ReaderOpenEx(0, "192.168.1.101:8881", 85, 0)
#status = ReaderOpenEx(0,"192.168.1.108",85,0)
else:
print("Invalid selection")
print("Press ENTER to quit")
input()
sys.exit(1)
if status == 0:
print("Status: " + ErrorCodes.UFCODER_ERROR_CODES[status])
print("Result: Port successfully opened")
print("---------------------------------------------")
#ReaderUISignal(1, 1)
else:
print("Status: " + ErrorCodes.UFCODER_ERROR_CODES[status])
print("Result: Port not opened")
print("---------------------------------------------")
print("Press ENTER to quit")
input()
sys.exit(1)
key = str()
usage()
if sys.platform.startswith('win'):
print("press ESC to exit.")
else:
print("press ESC and hit enter to exit.")
while key != '\x1b': #
if sys.platform.startswith('win'):
key = msvcrt.getwch()
else:
key = input()
menu(key)
ReaderClose()
ufr-lib @ c0a63a23
Subproject commit c0a63a23b0fbce4a82bb9b0942a1748dcd91db07
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment