读写器介绍:RFID读写器NFC发卡器WEB可编程NDEF文本/网址/智能海报/电话/启动-淘宝网 (taobao.com)
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'ic-02.ui' # # Created by: PyQt5 UI code generator 5.15.4 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. import ctypes # 调用DLL动态库要有这个引用 import sys import os import struct # struct的pack函数把任意数据类型变成字符串 import pdb # 引入程序调试功能,可用 pdb.set_trace() 设置程序调试断点 from PyQt5 import QtCore, QtGui, QtWidgets # 控制字定义 BLOCK0_EN = eval('0x01') # 读写块0 BLOCK1_EN = eval('0x02') # 读写块1 BLOCK2_EN = eval('0x04') # 读写块2 NEEDSERIAL = eval('0x08') # 读写指定序列号的卡 EXTERNKEY = eval('0x10') # 需要每次指定密码 NEEDHALT = eval('0x20') # 写卡后是否休眠卡 readblockdata=bytes(16) #保存读取的块数据,用做写UID后面的厂家信息 class Ui_Frame(object): def setupUi(self, Frame): Frame.setObjectName("Frame") Frame.resize(727, 565) font = QtGui.QFont() font.setPointSize(10) Frame.setFont(font) self.pushButton_beep = QtWidgets.QPushButton(Frame) self.pushButton_beep.setGeometry(QtCore.QRect(20, 10, 141, 30)) self.pushButton_beep.setObjectName("pushButton_beep") self.pushButton_getdevicenum = QtWidgets.QPushButton(Frame) self.pushButton_getdevicenum.setGeometry(QtCore.QRect(160, 10, 141, 30)) self.pushButton_getdevicenum.setObjectName("pushButton_getdevicenum") self.pushButton_piccreadex = QtWidgets.QPushButton(Frame) self.pushButton_piccreadex.setGeometry(QtCore.QRect(20, 90, 140, 30)) self.pushButton_piccreadex.setObjectName("pushButton_piccreadex") self.comboBox = QtWidgets.QComboBox(Frame) self.comboBox.setGeometry(QtCore.QRect(150, 60, 90, 22)) self.comboBox.setObjectName("comboBox") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.textEdit_oldkey = QtWidgets.QTextEdit(Frame) self.textEdit_oldkey.setGeometry(QtCore.QRect(550, 57, 130, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_oldkey.setFont(font) self.textEdit_oldkey.setObjectName("textEdit_oldkey") self.label = QtWidgets.QLabel(Frame) self.label.setGeometry(QtCore.QRect(30, 60, 121, 21)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Frame) self.label_2.setGeometry(QtCore.QRect(270, 60, 101, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.comboBox_2 = QtWidgets.QComboBox(Frame) self.comboBox_2.setGeometry(QtCore.QRect(370, 60, 70, 22)) self.comboBox_2.setObjectName("comboBox_2") self.comboBox_2.addItem("") self.comboBox_2.addItem("") self.label_3 = QtWidgets.QLabel(Frame) self.label_3.setGeometry(QtCore.QRect(470, 60, 71, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.pushButton_piccwriteex = QtWidgets.QPushButton(Frame) self.pushButton_piccwriteex.setGeometry(QtCore.QRect(20, 120, 140, 30)) self.pushButton_piccwriteex.setObjectName("pushButton_piccwriteex") self.pushButton_piccchangesinglekey = QtWidgets.QPushButton(Frame) self.pushButton_piccchangesinglekey.setGeometry(QtCore.QRect(20, 178, 140, 30)) self.pushButton_piccchangesinglekey.setObjectName("pushButton_piccchangesinglekey") self.comboBox_3 = QtWidgets.QComboBox(Frame) self.comboBox_3.setGeometry(QtCore.QRect(20, 153, 140, 25)) self.comboBox_3.setObjectName("comboBox_3") self.comboBox_3.addItem("") self.comboBox_3.addItem("") self.comboBox_3.addItem("") self.pushButton_piccwriteserial = QtWidgets.QPushButton(Frame) self.pushButton_piccwriteserial.setGeometry(QtCore.QRect(20, 325, 141, 30)) self.pushButton_piccwriteserial.setObjectName("pushButton_piccwriteserial") self.pushButton_piccwrite = QtWidgets.QPushButton(Frame) self.pushButton_piccwrite.setGeometry(QtCore.QRect(20, 290, 141, 30)) self.pushButton_piccwrite.setObjectName("pushButton_piccwrite") self.pushButton_piccread = QtWidgets.QPushButton(Frame) self.pushButton_piccread.setGeometry(QtCore.QRect(20, 260, 141, 30)) self.pushButton_piccread.setObjectName("pushButton_piccread") self.listWidget = QtWidgets.QListWidget(Frame) self.listWidget.setGeometry(QtCore.QRect(20, 360, 691, 201)) self.listWidget.setObjectName("listWidget") self.textEdit_thisblock = QtWidgets.QTextEdit(Frame) self.textEdit_thisblock.setGeometry(QtCore.QRect(170, 290, 430, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_thisblock.setFont(font) self.textEdit_thisblock.setObjectName("textEdit_thisblock") self.textEdit_uidno = QtWidgets.QTextEdit(Frame) self.textEdit_uidno.setGeometry(QtCore.QRect(170, 325, 120, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_uidno.setFont(font) self.textEdit_uidno.setObjectName("textEdit_uidno") self.label_4 = QtWidgets.QLabel(Frame) self.label_4.setGeometry(QtCore.QRect(170, 262, 171, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.spinBox = QtWidgets.QSpinBox(Frame) self.spinBox.setGeometry(QtCore.QRect(350, 260, 60, 25)) self.spinBox.setMinimumSize(QtCore.QSize(60, 22)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.spinBox.setFont(font) self.spinBox.setObjectName("spinBox") self.label_5 = QtWidgets.QLabel(Frame) self.label_5.setGeometry(QtCore.QRect(620, 95, 61, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.label_6 = QtWidgets.QLabel(Frame) self.label_6.setGeometry(QtCore.QRect(620, 125, 61, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_6.setFont(font) self.label_6.setObjectName("label_6") self.label_7 = QtWidgets.QLabel(Frame) self.label_7.setGeometry(QtCore.QRect(620, 155, 61, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_7.setFont(font) self.label_7.setObjectName("label_7") self.textEdit_newkey = QtWidgets.QTextEdit(Frame) self.textEdit_newkey.setGeometry(QtCore.QRect(170, 180, 430, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_newkey.setFont(font) self.textEdit_newkey.setObjectName("textEdit_newkey") self.pushButton_clearlist = QtWidgets.QPushButton(Frame) self.pushButton_clearlist.setGeometry(QtCore.QRect(570, 325, 141, 30)) self.pushButton_clearlist.setObjectName("pushButton_clearlist") self.label_8 = QtWidgets.QLabel(Frame) self.label_8.setGeometry(QtCore.QRect(170, 210, 391, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_8.setFont(font) self.label_8.setObjectName("label_8") self.textEdit_block0 = QtWidgets.QTextEdit(Frame) self.textEdit_block0.setGeometry(QtCore.QRect(170, 90, 430, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_block0.setFont(font) self.textEdit_block0.setObjectName("textEdit_block0") self.textEdit_block1 = QtWidgets.QTextEdit(Frame) self.textEdit_block1.setGeometry(QtCore.QRect(170, 120, 430, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_block1.setFont(font) self.textEdit_block1.setObjectName("textEdit_block1") self.textEdit_block2 = QtWidgets.QTextEdit(Frame) self.textEdit_block2.setGeometry(QtCore.QRect(170, 150, 430, 28)) font = QtGui.QFont() font.setFamily("宋体") font.setPointSize(11) self.textEdit_block2.setFont(font) self.textEdit_block2.setObjectName("textEdit_block2") self.label_9 = QtWidgets.QLabel(Frame) self.label_9.setGeometry(QtCore.QRect(610, 185, 81, 21)) font = QtGui.QFont() font.setPointSize(11) self.label_9.setFont(font) self.label_9.setObjectName("label_9") self.retranslateUi(Frame) self.pushButton_beep.clicked.connect(self.pushButton_beep_click) self.pushButton_clearlist.clicked.connect(self.pushButton_clearlist_click) self.pushButton_getdevicenum.clicked.connect(self.pushButton_getdevicenum_click) self.pushButton_piccreadex.clicked.connect(self.pushButton_piccreadex_click) self.pushButton_piccwriteex.clicked.connect(self.pushButton_piccwriteex_click) self.pushButton_piccchangesinglekey.clicked.connect(self.pushButton_piccchangesinglekey_click) self.pushButton_piccread.clicked.connect(self.pushButton_piccread_click) self.pushButton_piccwrite.clicked.connect(self.pushButton_piccwrite_click) self.pushButton_piccwriteserial.clicked.connect(self.pushButton_piccwriteserial_click) self.textEdit_thisblock.textChanged.connect(self.textEdit_thisblock_change_handler) self.textEdit_block0.textChanged.connect(self.textEdit_block0_change_handler) self.textEdit_block1.textChanged.connect(self.textEdit_block1_change_handler) self.textEdit_block2.textChanged.connect(self.textEdit_block2_change_handler) self.textEdit_newkey.textChanged.connect(self.textEdit_newkey_change_handler) QtCore.QMetaObject.connectSlotsByName(Frame) def retranslateUi(self, Frame): _translate = QtCore.QCoreApplication.translate Frame.setWindowTitle(_translate("Frame", "IC-02_Python_Qt_Demo")) self.pushButton_beep.setText(_translate("Frame", "驱动读写器发声")) self.pushButton_getdevicenum.setText(_translate("Frame", "获取读写器出厂序号")) self.pushButton_piccreadex.setText(_translate("Frame", "轻松读取指定扇区数据")) self.comboBox.setItemText(0, _translate("Frame", "第 0 扇区")) self.comboBox.setItemText(1, _translate("Frame", "第 1 扇区")) self.comboBox.setItemText(2, _translate("Frame", "第 2 扇区")) self.comboBox.setItemText(3, _translate("Frame", "第 3 扇区")) self.comboBox.setItemText(4, _translate("Frame", "第 4 扇区")) self.comboBox.setItemText(5, _translate("Frame", "第 5 扇区")) self.comboBox.setItemText(6, _translate("Frame", "第 6 扇区")) self.comboBox.setItemText(7, _translate("Frame", "第 7 扇区")) self.comboBox.setItemText(8, _translate("Frame", "第 8 扇区")) self.comboBox.setItemText(9, _translate("Frame", "第 9 扇区")) self.comboBox.setItemText(10, _translate("Frame", "第 10 扇区")) self.comboBox.setItemText(11, _translate("Frame", "第 11 扇区")) self.comboBox.setItemText(12, _translate("Frame", "第 12 扇区")) self.comboBox.setItemText(13, _translate("Frame", "第 13 扇区")) self.comboBox.setItemText(14, _translate("Frame", "第 14 扇区")) self.comboBox.setItemText(15, _translate("Frame", "第 15 扇区")) self.textEdit_oldkey.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.label.setText(_translate("Frame", "请选择读写扇区:")) self.label_2.setText(_translate("Frame", "认证密码类型:")) self.comboBox_2.setItemText(0, _translate("Frame", "B 密码")) self.comboBox_2.setItemText(1, _translate("Frame", "A 密码")) self.label_3.setText(_translate("Frame", "认证密码:")) self.pushButton_piccwriteex.setText(_translate("Frame", "轻松写数据到指定扇区")) self.pushButton_piccchangesinglekey.setText(_translate("Frame", "修改指定扇区密码")) self.comboBox_3.setItemText(0, _translate("Frame", "只修改A密码")) self.comboBox_3.setItemText(1, _translate("Frame", "修改A、B密码")) self.comboBox_3.setItemText(2, _translate("Frame", "修改AB密码及控制位")) self.pushButton_piccwriteserial.setText(_translate("Frame", "写UID卡号")) self.pushButton_piccwrite.setText(_translate("Frame", "写数据到指定块")) self.pushButton_piccread.setText(_translate("Frame", "读取指定块数据")) self.textEdit_thisblock.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.textEdit_uidno.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.label_4.setText(_translate("Frame", "请输入读写块地址 0-63:")) self.label_5.setText(_translate("Frame", "第 0 块")) self.label_6.setText(_translate("Frame", "第 1 块")) self.label_7.setText(_translate("Frame", "第 2 块")) self.textEdit_newkey.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.pushButton_clearlist.setText(_translate("Frame", "清空下栏提示信息")) self.label_8.setText(_translate("Frame", " A密码(6字节) 控制位(4字节) B密码(6字节)")) self.textEdit_block0.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.textEdit_block1.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.textEdit_block2.setHtml(_translate("Frame", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'宋体\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'SimSun\'; font-size:10pt;\"><br /></p></body></html>")) self.label_9.setText(_translate("Frame", "密码控制块")) def textEdit_thisblock_change_handler(self): max_length = 47 text = self.textEdit_thisblock.toPlainText() current_len = len(text) text_cursor = self.textEdit_thisblock.textCursor() if current_len > max_length: text_valid = text[0:47] self.textEdit_thisblock.clear() self.textEdit_thisblock.setText(text_valid) self.textEdit_thisblock.setTextCursor(text_cursor) def textEdit_block0_change_handler(self): max_length = 47 text = self.textEdit_block0.toPlainText() current_len = len(text) text_cursor = self.textEdit_block0.textCursor() if current_len > max_length: text_valid = text[0:47] self.textEdit_block0.clear() self.textEdit_block0.setText(text_valid) self.textEdit_block0.setTextCursor(text_cursor) def textEdit_block1_change_handler(self): max_length = 47 text = self.textEdit_block1.toPlainText() current_len = len(text) text_cursor = self.textEdit_block1.textCursor() if current_len > max_length: text_valid = text[0:47] self.textEdit_block1.clear() self.textEdit_block1.setText(text_valid) self.textEdit_block1.setTextCursor(text_cursor) def textEdit_block2_change_handler(self): max_length = 47 text = self.textEdit_block2.toPlainText() current_len = len(text) text_cursor = self.textEdit_block2.textCursor() if current_len > max_length: text_valid = text[0:47] self.textEdit_block2.clear() self.textEdit_block2.setText(text_valid) self.textEdit_block2.setTextCursor(text_cursor) def textEdit_newkey_change_handler(self): max_length = 47 text = self.textEdit_newkey.toPlainText() current_len = len(text) text_cursor = self.textEdit_newkey.textCursor() if current_len > max_length: text_valid = text[0:47] self.textEdit_newkey.clear() self.textEdit_newkey.setText(text_valid) self.textEdit_newkey.setTextCursor(text_cursor) def ListBottom(self): self.listWidget.scrollToBottom() seleid = self.listWidget.count() - 1 self.listWidget.item(seleid).setSelected(True) # IC卡操作错误代码解释 def ListErrInf(self, Errcode): if (Errcode == 8): self.listWidget.addItem('错误代码:8,未寻到卡,请重新拿开卡后再放到感应区!') elif (Errcode == 1): self.listWidget.addItem('错误代码:1,0~2块都没读出来,可能刷卡太块。但卡序列号已被读出来!') elif (Errcode == 2): self.listWidget.addItem('错误代码:2,第0块已被读出,但1~2块读取失败。卡序列号已被读出来!') elif (Errcode == 3): self.listWidget.addItem('错误代码:3,第0、1块已被读出,但2块读取失败。卡序列号已被读出来!') elif (Errcode == 9): self.listWidget.addItem('错误代码:9,有多张卡在感应区,寻卡过程中防冲突失败,读序列吗错误!') elif (Errcode == 10): self.listWidget.addItem('错误代码:10,该卡可能已被休眠,无法选中卡片!') elif (Errcode == 11): self.listWidget.addItem('错误代码:11,密码装载失败!') elif (Errcode == 12): self.listWidget.addItem('错误代码:12,卡片密码认证失败!') elif (Errcode == 13): self.listWidget.addItem('错误代码:13,读指定块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!') elif (Errcode == 14): self.listWidget.addItem('错误代码:14,写指定块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!') elif (Errcode == 21): self.listWidget.addItem('错误代码:21,没有动态库!') elif (Errcode == 22): self.listWidget.addItem('错误代码:22,动态库或驱动程序异常!') elif (Errcode == 23): self.listWidget.addItem('错误代码:23,(表示未检测到免驱动读写器!)(有驱动读写器表示驱动程序错误或未检测到有驱读写器!)') elif (Errcode == 24): self.listWidget.addItem('错误代码:24,操作超时,一般是动态库没有反映!') elif (Errcode == 25): self.listWidget.addItem('错误代码:25,发送字数不够!') elif (Errcode == 26): self.listWidget.addItem('错误代码:26,发送的CRC错!') elif (Errcode == 27): self.listWidget.addItem('错误代码:27,接收的字数不够!') elif (Errcode == 28): self.listWidget.addItem('错误代码:28,接收的CRC错!') else: self.listWidget.addItem('未知错误,错误代码:' + str(Errcode)) self.ListBottom() def pushButton_beep_click(self): status = Objdll.pcdbeep(50) % 256 if status == 0: self.listWidget.addItem("读写器已执行响声指令!") else: self.listWidget.addItem("驱动设备嘀一声:USB通讯失败,请以超级用户模式运行,如sudo python3 beep.py") self.ListBottom() def pushButton_clearlist_click(self): self.listWidget.clear() def pushButton_getdevicenum_click(self): devno = bytes(4) # 声明4个字节缓冲 status = Objdll.pcdgetdevicenumber(devno) % 256 if (status == 0): Objdll.pcdbeep(38) SerialNum = '' for num in range(0, len(devno)): SerialNum = SerialNum + '%02X' % (devno[num]) if (num < len(devno) - 1): SerialNum = SerialNum + '-' self.listWidget.addItem('设备 序列号:' + SerialNum) self.ListBottom() else: self.ListErrInf(status) def pushButton_piccreadex_click(self): myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY # 读写控制字 myareano = self.comboBox.currentIndex() # 指定读写区号 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypicckey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 mypiccdata = bytes(48) # 读卡数据缓冲,一个扇区共48个字节 status = Objdll.piccreadex(myctrlword, mypiccserial, myareano, authmode, mypicckey, mypiccdata) % 256 if (status == 0): Objdll.pcdbeep(38) dispstr = '16进制卡号:%02X%02X%02X%02X' % (mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',读卡扇区数据成功!') piccdataStr = '' for num in range(0, len(mypiccdata)): piccdataStr = piccdataStr + '%02X ' % (mypiccdata[num]) self.textEdit_block0.setPlainText(piccdataStr[0:48]) #直接给文本框赋值,此方法无格式信息 self.textEdit_block1.setPlainText(piccdataStr[48:96]) # 直接给文本框赋值,此方法无格式信息 self.textEdit_block2.setPlainText(piccdataStr[96:143]) # 直接给文本框赋值,此方法无格式信息 self.ListBottom() else: self.ListErrInf(status) def pushButton_piccwriteex_click(self): myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY # 读写控制字 myareano = self.comboBox.currentIndex() # 指定读写区号 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypicckey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 mypiccdata=bytes.fromhex(self.textEdit_block0.toPlainText()) # 写卡数据,总计48个字节 if(len(mypiccdata)==16): mypiccdata=mypiccdata+bytes.fromhex(self.textEdit_block1.toPlainText()) # 写卡数据,总计48个字节 if (len(mypiccdata) == 32): mypiccdata = mypiccdata + bytes.fromhex(self.textEdit_block2.toPlainText()) # 写卡数据,总计48个字节 if (len(mypiccdata)==48): status = Objdll.piccwriteex(myctrlword, mypiccserial, myareano, authmode, mypicckey, mypiccdata) % 256 if (status == 0): Objdll.pcdbeep(38) dispstr = '16进制卡号:%02X%02X%02X%02X' % (mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',写卡扇区数据成功!') self.ListBottom() else: self.ListErrInf(status) else: self.listWidget.addItem('第2块的写卡数据输入错误,请输入16个16进制的写卡数据!') self.ListBottom() else: self.listWidget.addItem('第1块的写卡数据输入错误,请输入16个16进制的写卡数据!') self.ListBottom() else: self.listWidget.addItem('第0块的写卡数据输入错误,请输入16个16进制的写卡数据!') self.ListBottom() def pushButton_piccchangesinglekey_click(self): myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY # 读写控制字 myareano = self.comboBox.currentIndex() # 指定读写区号 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypiccoldkey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 #mypiccnewkey 指定6字节新A密码+4字节控制码+6字节B密码+1字节功能码 ,注意:指定新密码时一定要记住,否则有可能找不回密码,导致该卡报废!!! #功能码为:3 表示同时更改A、B 密码及权限访问字 #功能码为:2 表示密码权限访问字不更改,只改A、B密码 #功能码为:0 示只改A密码 newkey=self.textEdit_newkey.toPlainText() if (self.comboBox_3.currentIndex() == 0): newkey=newkey+" 00" elif(self.comboBox_3.currentIndex() == 1): newkey = newkey + " 02" else: newkey = newkey + " 03" mypiccnewkey=bytes.fromhex(newkey) # 新密码 if (len(mypiccnewkey) == 17): status = Objdll.piccchangesinglekeyex(myctrlword, mypiccserial, myareano, authmode, mypiccoldkey,mypiccnewkey) % 256 if (status == 0): Objdll.pcdbeep(38) dispstr = '16进制卡号:%02X%02X%02X%02X' % (mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',更改卡密码成功!') self.ListBottom() else: self.ListErrInf(status) else: self.listWidget.addItem('新A、B密码及控制位不是16个字节,请输入正确的6字节A密码+4字节控制位+6字节B密码!') self.ListBottom() def pushButton_piccread_click(self): global readblockdata myblock = self.spinBox.value() # 指定读写块号 myareano=myblock//4 # 根据块号获取扇区号,为的是认证扇区密码 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypicckey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 myblockdata=bytes(16) #读卡数据缓冲,一个块共16个字节 status = Objdll.piccrequest(mypiccserial) % 256 #寻找感应区内的卡片 if(status==0): status = Objdll.piccauthkey1(mypiccserial,myareano,authmode,mypicckey) % 256 #寻到卡后,认证要读块所在扇区的密码 if(status==0): status = Objdll.piccread(myblock,myblockdata) % 256 #密码认证成功,读块数据 if(status==0): Objdll.pcdbeep(38) readblockdata=myblockdata #保存读取的块数据用于UID卡复制 dispstr = '16进制卡号:%02X%02X%02X%02X' % ( mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',读卡块数据成功!') piccdataStr = '' for num in range(0, len(myblockdata)): piccdataStr = piccdataStr + '%02X ' % (myblockdata[num]) self.textEdit_thisblock.setPlainText(piccdataStr) #直接给文本框赋值,此方法无格式信息 self.ListBottom() else: self.ListErrInf(status) else: self.ListErrInf(status) else: self.ListErrInf(status) def pushButton_piccwrite_click(self): myblock = self.spinBox.value() # 指定读写块号 myareano=myblock//4 # 根据块号获取扇区号,为的是认证扇区密码 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypicckey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 myblockdata=bytes.fromhex(self.textEdit_thisblock.toPlainText()) #写卡数据缓冲,一个块共16个字节 if (len(myblockdata) == 16): status = Objdll.piccrequest(mypiccserial) % 256 #寻找感应区内的卡片 if(status==0): status = Objdll.piccauthkey1(mypiccserial,myareano,authmode,mypicckey) % 256 #寻到卡后,认证要读块所在扇区的密码 if(status==0): status = Objdll.piccwrite(myblock,myblockdata) % 256 #密码认证成功,写块数据 if(status==0): Objdll.pcdbeep(38) dispstr = '16进制卡号:%02X%02X%02X%02X' % ( mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',写卡块数据成功!') self.ListBottom() else: self.ListErrInf(status) else: self.ListErrInf(status) else: self.ListErrInf(status) else: self.listWidget.addItem('请输入16个字节16进制的写卡信息!') self.ListBottom() def pushButton_piccwriteserial_click(self): global readblockdata myctrlword = BLOCK0_EN # 读写控制字 myareano = self.comboBox.currentIndex() # 指定读写区号 authmode = self.comboBox_2.currentIndex() # 大于0表示用A密码认证,推荐用A密码认证 mypicckey = bytes.fromhex(self.textEdit_oldkey.toPlainText()[0:12]) # 卡片认证密码, mypiccserial = bytes(4) # 4字节卡序列号缓冲 mypiccdata = bytes(16) # 16字节写入数据缓冲,UID卡号是前面4个字节,第五字节必须等于前四个字节的异或和 newuid=int(self.textEdit_uidno.toPlainText()) if(newuid>=0 and newuid<=4294967295): mypiccdata = struct.pack('<I', newuid) # 将卡号转字节数组低位在前 mypiccdata=mypiccdata+readblockdata[4:16] status=Objdll.piccwriteserial(myctrlword,mypiccserial,authmode,mypicckey,mypiccdata) % 256 if(status==0): status = Objdll.piccrequest(mypiccserial) % 256 #寻找感应区内的卡片 if(status==0): Objdll.pcdbeep(38) dispstr = '16进制卡号:%02X%02X%02X%02X' % ( mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3]) Cardno = mypiccserial[0] Cardno = Cardno + (mypiccserial[1] * 256) Cardno = Cardno + (mypiccserial[2] * 65536) Cardno = Cardno + (mypiccserial[3] * 16777216) CardnoStr = '%010d' % Cardno self.listWidget.addItem(dispstr + ',转10进制卡号:' + CardnoStr + ',写UID卡号成功!') self.ListBottom() else: self.ListErrInf(status) else: self.ListErrInf(status) else: self.listWidget.addItem('UID的取值范围是:0-4294967295,请输入正确的UID号!') self.ListBottom() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Frame = QtWidgets.QFrame() ui = Ui_Frame() ui.setupUi(Frame) Frame.show() ui.textEdit_oldkey.setPlainText("FFFFFFFFFFFF") ui.textEdit_block0.setPlainText("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") ui.textEdit_block1.setPlainText("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") ui.textEdit_block2.setPlainText("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") ui.textEdit_newkey.setPlainText("FF FF FF FF FF FF FF 07 80 69 FF FF FF FF FF FF") ui.textEdit_thisblock.setPlainText("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") ui.textEdit_uidno.setPlainText("0123456789") ui.comboBox_2.setCurrentIndex(1) # windows系统加载当前目录下的DLL库 dllfile = sys.path[0] + '\OUR_MIFARE.dll' Objdll = ctypes.windll.LoadLibrary(dllfile) Objdll = ctypes.WinDLL(dllfile) #Linux加载当前目录下的so库 #dllfile = sys.path[0] + '/libOURMIFARE.so' #Objdll = ctypes.cdll.LoadLibrary(dllfile) sys.exit(app.exec_())