Python 读写T5557低频RFID,将T5557卡制做成ID、HID卡

news2025/2/28 0:13:16

本示例使用的发卡器: T5557 T5567 T5577低频RFID读写器 EM4100 HID卡复制器 酒店门卡-淘宝网 (taobao.com)

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget,QMessageBox,QCheckBox,QLineEdit
from PyQt5.QtGui import QFont
from RWT5557Demo import Ui_MainWindow
import sys

import struct  # struct的pack函数把任意数据类型变成字符串
import ctypes  # 调用DLL动态库要有这个引用

# 控制字定义
NEEDSERIAL = eval('0x01')  # 需要只对指定系列号的卡操作
NEEDKEY = eval('0x02')     # 需要用密码认证
LOCKBIT = eval('0x04')     # 锁定配置块或数据块,仅对   t5557_init,t5557_write ,t5557_changekey函数有效
KEYENABLE = eval('0x08')   # 启用本卡的密码功能
RESETCARD = eval('0x10')   # 操作成功后重启卡片

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)

        self.check_authkey.stateChanged.connect(self.check_authkey_onStateChanged)
        self.check_serial.stateChanged.connect(self.check_serial_onStateChanged)
        self.check_Enkey.stateChanged.connect(self.check_Enkey_onStateChanged)
        self.radio_em4100.toggled.connect(self.radio_em4100_toggled)
        self.comboBox2.activated.connect(self.comboBox2_activated)

        self.push_beep.clicked.connect(self.push_beep_clicked)
        self.push_getdevnum.clicked.connect(self.push_getdevnum_clicked)
        self.push_readcard.clicked.connect(self.push_readcard_clicked)
        self.push_writcard.clicked.connect(self.push_writcard_clicked)
        self.push_changekey.clicked.connect(self.push_changekey_clicked)
        self.push_editconfig.clicked.connect(self.push_editconfig_clicked)
        self.push_readid.clicked.connect(self.push_readid_clicked)
        self.push_toidhid.clicked.connect(self.push_toidhid_clicked)
        self.push_changeid0.clicked.connect(self.push_changeid0_clicked)
        self.push_changeid1.clicked.connect(self.push_changeid1_clicked)

    def DispErrInf(self,Errcode):
        if (Errcode == 8):
            QMessageBox.critical(self,'提示','错误代码:8,未寻到卡,请重新拿开卡后再放到感应区!', QMessageBox.Yes)
        elif (Errcode == 1):
            QMessageBox.critical(self,'提示','错误代码:1,写入配置的值不正确,请重新写入!', QMessageBox.Yes)
        elif (Errcode == 2):
            QMessageBox.critical(self,'提示','错误代码:2,本卡尚未开启密码功能,函数myctrlword中无需加入 NEEDKEY ', QMessageBox.Yes)
        elif (Errcode == 3):
            QMessageBox.critical(self,'提示','错误代码:3,需要密码才能读卡,函数myctrlword要加入NEEDKEY ', QMessageBox.Yes)
        elif (Errcode == 5):
            QMessageBox.critical(self,'提示','错误代码:5,密码错误!', QMessageBox.Yes)
        elif (Errcode == 21):
            QMessageBox.critical(self,'提示','错误代码:21,没有动态库!', QMessageBox.Yes)
        elif (Errcode == 22):
            QMessageBox.critical(self,'提示','错误代码:22,动态库或驱动程序异常!', QMessageBox.Yes)
        elif (Errcode == 23):
            QMessageBox.critical(self,'提示','错误代码:23,驱动程序错误或尚未安装!', QMessageBox.Yes)
        elif (Errcode == 24):
            QMessageBox.critical(self,'提示','错误代码:24,操作超时,一般是动态库没有反映!', QMessageBox.Yes)
        elif (Errcode == 25):
            QMessageBox.critical(self,'提示','错误代码:25,发送字数不够!', QMessageBox.Yes)
        elif (Errcode == 26):
            QMessageBox.critical(self,'提示','错误代码:26,发送的CRC错!', QMessageBox.Yes)
        elif (Errcode == 27):
            QMessageBox.critical(self,'提示','错误代码:27,接收的字数不够!', QMessageBox.Yes)
        elif (Errcode == 28):
            QMessageBox.critical(self,'提示','错误代码:28,接收的CRC错!', QMessageBox.Yes)
        else:
            QMessageBox.critical(self,'提示','未知错误,错误代码:' + str(Errcode), QMessageBox.Yes)

    def comboBox2_activated(self,index):
        if self.comboBox2.currentIndex() ==0:
            self.text_newid3.setText('24')
        elif self.comboBox2.currentIndex() ==1:
            self.text_newid3.setText('35')
        elif self.comboBox2.currentIndex() ==2:
            self.text_newid3.setText('35')
        elif self.comboBox2.currentIndex() ==3:
            self.text_newid3.setText('33')
        else:
            self.text_newid3.setText('%d' %(self.comboBox2.currentIndex()+4))


    def check_authkey_onStateChanged(self):
        if self.check_authkey.isChecked():
            self.text_authkey.setVisible(True)
        else:
            self.text_authkey.setVisible(False)

    def check_serial_onStateChanged(self):
        if self.check_serial.isChecked():
            self.text_piccserial.setVisible(True)
        else:
            self.text_piccserial.setVisible(False)

    def check_Enkey_onStateChanged(self):
        if self.check_Enkey.isChecked():
            self.label_20.setVisible(True)
            self.text_Enauthkey.setVisible(True)
            self.text_config.setText('00088038')
        else:
            self.label_20.setVisible(False)
            self.text_Enauthkey.setVisible(False)
            self.text_config.setText('00088028')

    def radio_em4100_toggled(self):
        self.text_idserial.setText('')
        self.text_newid0.setText('')
        self.text_newid1.setText('')
        self.text_newid2.setText('')
        self.text_newid3.setText('')
        if self.radio_em4100.isChecked():
            self.comboBox.clear()
            self.comboBox.addItem('10位16进制码')
            self.comboBox.addItem('8H10D 码')
            self.comboBox.addItem('韦根34码')
            self.comboBox.addItem('韦根26码')
            self.label_28.setVisible(False)
            self.text_newid3.setVisible(False)
            self.comboBox2.setVisible(False)
            self.comboBox.setCurrentIndex(1)
        else:
            self.comboBox.clear()
            self.comboBox.addItem('12位16进制码')
            self.comboBox.addItem('8H10D 码')
            self.comboBox.addItem('韦根34码')
            self.comboBox.addItem('韦根26码')
            self.comboBox.addItem('4.3H6D码')
            self.comboBox.addItem('4H5D码')
            self.label_28.setVisible(True)
            self.text_newid3.setVisible(True)
            self.comboBox2.setVisible(True)
            self.comboBox.setCurrentIndex(1)

    def push_beep_clicked(self):
        status = Objdll.idr_beep(50) % 256
        if (status != 0):
            self.DispErrInf(status)

    def push_getdevnum_clicked(self):
        devno = bytes(4)  # 声明4个字节缓冲
        status = Objdll.pcdgetdevicenumber(devno) % 256
        if (status == 0):
            Objdll.idr_beep(38)
            SerialNum = ''
            for num in range(0, len(devno)):
                SerialNum = SerialNum + '%d' % (devno[num])
                if (num < len(devno) - 1):
                    SerialNum = SerialNum + '-'
            QMessageBox.information(self,'提示','设备出厂编号:' + SerialNum,QMessageBox.Yes)
        else:
            self.DispErrInf(status)

    def push_readcard_clicked(self):
        myctrlword = 0  # 控制位
        oldpicckey = bytes(4)  # 4字节卡认证密码
        mypiccserial = bytes(6)  # 6字节卡序列号
        mypiccdata = bytes(50)  # 读卡缓冲

        if (self.check_authkey.isChecked()):    #选择需要先认证卡片密码
            PasswStr=self.text_authkey.text().strip()
            if(is_valid_hex(PasswStr)==False or len(bytes.fromhex(PasswStr))!=4):
                QMessageBox.critical(self,'提示','卡片认证密钥错误,请输入8位16进制卡片认证密钥!',QMessageBox.Yes)
                self.text_authkey.setFocus()
                return
            myctrlword = myctrlword + NEEDKEY
            oldpicckey = bytes.fromhex(PasswStr)

        if (self.check_serial.isChecked()):     #选择只操作指定卡号的卡
            serialstr=self.text_piccserial.text().strip()
            if (is_valid_hex(serialstr) == False or len(bytes.fromhex(serialstr))!=6):
                QMessageBox.critical(self, '提示', '卡号错误,请输入12位16进制卡号!', QMessageBox.Yes)
                self.text_piccserial.setFocus()
                return
            myctrlword = myctrlword + NEEDSERIAL
            mypiccserial = bytes.fromhex(serialstr)

        seleblock0= ''      #第0页块选标志位
        for i in range(8):
            self.chckbox = self.findChild(QCheckBox, "check_block%d" % (i))
            if self.chckbox.isChecked():
                seleblock0 = '1' + seleblock0
            else:
                seleblock0 = '0' + seleblock0
        mypiccblockflag=bytes([int(seleblock0, 2)])

        seleblock1 = '0'    #第1页块选标志位,注意首位先取0
        for i in range(8,12):
            self.chckbox = self.findChild(QCheckBox, "check_block%d" % (i))
            if self.chckbox.isChecked():
                seleblock1 = '1' + seleblock1
            else:
                seleblock1 = '0' + seleblock1
        mypiccblockflag = mypiccblockflag + bytes([int(seleblock1, 2)])

        status = Objdll.t5557_read(myctrlword, mypiccserial, oldpicckey, mypiccblockflag, mypiccdata) % 256
        if (status == 0):
            Objdll.idr_beep(38)
            SerialNum = ''
            for num in range(0, len(mypiccserial)):
                SerialNum = SerialNum + '%02X' % (mypiccserial[num])
            DataHexStr = ''
            for num in range(0, mypiccdata[1]):
                DataHexStr = DataHexStr + '%02X' % (mypiccdata[num + 2])

            seleblock=seleblock0[::-1]+seleblock1[::-1][1:5]    #根据块选标志位解析每块数据
            j=0
            for i in range(12):
                if(seleblock[i:i+1]=='1'):
                    self.textedit=self.findChild(QLineEdit,'text_block%d' % (i) )
                    datastr=DataHexStr[j:j+8]
                    j=j+8
                    self.textedit.setText(datastr)

            QMessageBox.information(self,'提示','读卡成功,16进制卡号:' + SerialNum + ',卡无线转输分频比:' + str(mypiccdata[0]),QMessageBox.Yes)
        else:
            self.DispErrInf(status)

    def push_writcard_clicked(self):
        myctrlword = 0  # 控制位
        oldpicckey = bytes(4)  # 4字节卡认证密码
        mypiccserial = bytes(6)  # 6字节卡序列号

        if (self.check_authkey.isChecked()):  # 选择需要先认证卡片密码
            PasswStr = self.text_authkey.text().strip()
            if (is_valid_hex(PasswStr) == False or len(bytes.fromhex(PasswStr)) != 4):
                QMessageBox.critical(self, '提示', '卡片认证密钥错误,请输入8位16进制卡片认证密钥!', QMessageBox.Yes)
                self.text_authkey.setFocus()
                return
            myctrlword = myctrlword + NEEDKEY
            oldpicckey = bytes.fromhex(PasswStr)

        if (self.check_serial.isChecked()):  # 选择只操作指定卡号的卡
            serialstr = self.text_piccserial.text().strip()
            if (is_valid_hex(serialstr) == False or len(bytes.fromhex(serialstr)) != 6):
                QMessageBox.critical(self, '提示', '卡号错误,请输入12位16进制卡号!', QMessageBox.Yes)
                self.text_piccserial.setFocus()
                return
            myctrlword = myctrlword + NEEDSERIAL
            mypiccserial = bytes.fromhex(serialstr)

        seleblock0 = ''  # 第0页块选标志位
        writedata=''
        for i in range(8):
            self.chckbox = self.findChild(QCheckBox, "check_block%d" % (i))
            self.textedit = self.findChild(QLineEdit, 'text_block%d' % (i))
            if self.chckbox.isChecked():
                seleblock0 = '1' + seleblock0
                blockdata=self.textedit.text().strip()
                if (is_valid_hex(blockdata) == False or len(bytes.fromhex(blockdata)) != 4):
                    QMessageBox.critical(self, '提示', '第%d' %(i)+"块写卡数据输入错误!", QMessageBox.Yes)
                    self.textedit.setFocus()
                    return
                writedata=writedata+blockdata
            else:
                seleblock0 = '0' + seleblock0
        mypiccblockflag = bytes([int(seleblock0, 2)])

        seleblock1 = '0'  # 第1页块选标志位,注意首位先取0
        for i in range(8, 12):
            self.chckbox = self.findChild(QCheckBox, "check_block%d" % (i))
            self.textedit = self.findChild(QLineEdit, 'text_block%d' % (i))
            if self.chckbox.isChecked():
                seleblock1 = '1' + seleblock1
                blockdata = self.textedit.text().strip()
                if (is_valid_hex(blockdata) == False or len(bytes.fromhex(blockdata)) != 4):
                    QMessageBox.critical(self, '提示', '第%d' % (i) + "块写卡数据输入错误!", QMessageBox.Yes)
                    self.textedit.setFocus()
                    return
                writedata = writedata + blockdata
            else:
                seleblock1 = '0' + seleblock1
        mypiccblockflag = mypiccblockflag + bytes([int(seleblock1, 2)])

        writebuf=bytes.fromhex(writedata)
        if (len(writebuf)<1):
            QMessageBox.critical(self, '提示', '请选择要写入数据的块号!', QMessageBox.Yes)
            return

        status = Objdll.t5557_write(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,writebuf) % 256
        if (status == 0):
            Objdll.idr_beep(38)
            SerialNum = ''
            for num in range(0, len(mypiccserial)):
                SerialNum = SerialNum + '%02X' % (mypiccserial[num])
            QMessageBox.information(self,'提示','16进制卡号:' + SerialNum+ ',写卡成功!',QMessageBox.Yes)
        else:
            self.DispErrInf(status)

    def push_changekey_clicked(self):
        myctrlword = 0  # 控制位
        oldpicckey = bytes(4)  # 4字节卡认证密码
        mypiccserial = bytes(6)  # 6字节卡序列号

        if (self.check_authkey.isChecked()):  # 选择需要先认证卡片密码
            PasswStr = self.text_authkey.text().strip()
            if (is_valid_hex(PasswStr) == False or len(bytes.fromhex(PasswStr)) != 4):
                QMessageBox.critical(self, '提示', '卡片认证密钥错误,请输入8位16进制卡片认证密钥!', QMessageBox.Yes)
                self.text_authkey.setFocus()
                return
            myctrlword = myctrlword + NEEDKEY
            oldpicckey = bytes.fromhex(PasswStr)

        if (self.check_serial.isChecked()):  # 选择只操作指定卡号的卡
            serialstr = self.text_piccserial.text().strip()
            if (is_valid_hex(serialstr) == False or len(bytes.fromhex(serialstr)) != 6):
                QMessageBox.critical(self, '提示', '卡号错误,请输入12位16进制卡号!', QMessageBox.Yes)
                self.text_piccserial.setFocus()
                return
            myctrlword = myctrlword + NEEDSERIAL
            mypiccserial = bytes.fromhex(serialstr)

        newkeystr=self.text_newkey.text().strip()
        if (is_valid_hex(newkeystr) == False or len(bytes.fromhex(newkeystr)) != 4):
            QMessageBox.critical(self, '提示', '卡片新密钥错误,请输入8位16进制卡片新密钥!', QMessageBox.Yes)
            self.text_newkey.setFocus()
            return
        newkeybuf=bytes.fromhex(newkeystr)

        status = Objdll.t5557_changekey(myctrlword, mypiccserial, oldpicckey, newkeybuf) % 256
        if (status == 0):
            Objdll.idr_beep(38)
            SerialNum = ''
            for num in range(0, len(mypiccserial)):
                SerialNum = SerialNum + '%02X' % (mypiccserial[num])
            QMessageBox.information(self, '提示', '16进制卡号:' + SerialNum + ',修改卡密钥成功!', QMessageBox.Yes)
        else:
            self.DispErrInf(status)

    def push_editconfig_clicked(self):
        myctrlword = 0  # 控制位
        oldpicckey = bytes(4)  # 4字节卡认证密码
        newpicckey=bytes(4)    # 4字节新密码
        mypiccserial = bytes(6)  # 6字节卡序列号

        if (self.check_authkey.isChecked()):  # 选择需要先认证卡片密码
            PasswStr = self.text_authkey.text().strip()
            if (is_valid_hex(PasswStr) == False or len(bytes.fromhex(PasswStr)) != 4):
                QMessageBox.critical(self, '提示', '卡片认证密钥错误,请输入8位16进制卡片认证密钥!', QMessageBox.Yes)
                self.text_authkey.setFocus()
                return
            myctrlword = myctrlword + NEEDKEY
            oldpicckey = bytes.fromhex(PasswStr)

        if (self.check_Enkey.isChecked()):
            newkeystr=self.text_Enauthkey.text().strip()
            if (is_valid_hex(newkeystr) == False or len(bytes.fromhex(newkeystr)) != 4):
                QMessageBox.critical(self, '提示', '卡片密钥错误,请输入8位16进制卡片密钥!', QMessageBox.Yes)
                self.text_Enauthkey.setFocus()
                return
            newpicckey=bytes.fromhex(newkeystr)
            myctrlword = myctrlword + KEYENABLE

        configstr=self.text_config.text().strip()
        if (is_valid_hex(configstr) == False or len(bytes.fromhex(configstr)) != 4):
            QMessageBox.critical(self, '提示', '卡片配置值错误,请输入8位16进制卡片配置值!', QMessageBox.Yes)
            self.text_config.setFocus()
            return
        configbuf=bytes.fromhex(configstr)

        status = Objdll.t5557_init(myctrlword, mypiccserial, oldpicckey, configbuf, newpicckey) % 256
        if (status == 0):
            Objdll.idr_beep(38)
            SerialNum = ''
            for num in range(0, len(mypiccserial)):
                SerialNum = SerialNum + '%02X' % (mypiccserial[num])
            QMessageBox.information(self, '提示', '16进制卡号:' + SerialNum + ',修改卡配置值成功!', QMessageBox.Yes)
        else:
            self.DispErrInf(status)

    def push_readid_clicked(self):
        mypiccserial = bytes(7)  # 卡序列号缓冲
        if (self.radio_em4100.isChecked()):
            status = Objdll.idr_read(mypiccserial) % 256
            if (status==0):
                Objdll.idr_beep(38)
                SerialNum = ''
                for num in range(0, 5):
                    SerialNum = SerialNum + '%02X' % (mypiccserial[num])
                self.text_idserial.setText(SerialNum)
                self.push_changeid0_clicked()
                QMessageBox.information(self, '提示', '读ID卡成功,16进制卡号:' + SerialNum , QMessageBox.Yes)
            else:
                self.DispErrInf(status)
        else:
            status = Objdll.hid_read(mypiccserial) % 256
            if (status == 0):
                Objdll.idr_beep(38)
                SerialNum = ''
                for num in range(0, 7):
                    SerialNum = SerialNum + '%02X' % (mypiccserial[num])
                self.text_idserial.setText(SerialNum)
                self.push_changeid0_clicked()
                QMessageBox.information(self, '提示', '读HID卡成功,16进制卡号:' + SerialNum, QMessageBox.Yes)
            else:
                self.DispErrInf(status)

    def push_toidhid_clicked(self):
        myctrlword = 0  # 控制位
        oldpicckey = bytes(4)  # 4字节卡认证密码
        mypiccserial = bytes(6)  # 6字节卡序列号
        newpicckey = bytes(4)  # 4字节卡新密码

        if (self.check_authkey.isChecked()):  # 选择需要先认证卡片密码
            PasswStr = self.text_authkey.text().strip()
            if (is_valid_hex(PasswStr) == False or len(bytes.fromhex(PasswStr)) != 4):
                QMessageBox.critical(self, '提示', '卡片认证密钥错误,请输入8位16进制卡片认证密钥!', QMessageBox.Yes)
                self.text_authkey.setFocus()
                return
            myctrlword = myctrlword + NEEDKEY
            oldpicckey = bytes.fromhex(PasswStr)

        if (self.check_serial.isChecked()):  # 选择只操作指定卡号的卡
            serialstr = self.text_piccserial.text().strip()
            if (is_valid_hex(serialstr) == False or len(bytes.fromhex(serialstr)) != 6):
                QMessageBox.critical(self, '提示', '卡号错误,请输入12位16进制卡号!', QMessageBox.Yes)
                self.text_piccserial.setFocus()
                return
            myctrlword = myctrlword + NEEDSERIAL
            mypiccserial = bytes.fromhex(serialstr)

        if (self.check_authkey_2.isChecked()):
            newkeystr=self.text_authkey_2.text().strip()
            if (is_valid_hex(newkeystr) == False or len(bytes.fromhex(newkeystr)) != 4):
                QMessageBox.critical(self, '提示', '卡密钥错误,请输入8位16进制卡密钥!', QMessageBox.Yes)
                self.text_authkey_2.setFocus()
                return
            myctrlword = myctrlword + KEYENABLE
            newpicckey = bytes.fromhex(newkeystr)

        myctrlword = myctrlword + RESETCARD    # 操作后重启卡片,否则在制卡后,需要拿开卡片重放才能成功读卡

        SerialNum = self.text_idserial.text().strip()
        if (self.radio_em4100.isChecked()):
            if (is_valid_hex(SerialNum) == False or len(bytes.fromhex(SerialNum)) != 5):
                QMessageBox.critical(self, '提示', '原始16进制卡信息错误,请输入10位原始16进制ID卡信息!', QMessageBox.Yes)
                self.text_idserial.setFocus()
                return

            mynewuid=bytes.fromhex(SerialNum)
            status = Objdll.t5557_to4100(myctrlword, mypiccserial, oldpicckey, newpicckey, mynewuid)
            if status==0:
                Objdll.idr_beep(38)
                QMessageBox.information(self, '提示', 'ID卡号写入成功,卡片变成ID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能!', QMessageBox.Yes)
            else:
                self.DispErrInf(status)
        else:
            if (is_valid_hex(SerialNum) == False or len(bytes.fromhex(SerialNum)) != 7):
                QMessageBox.critical(self, '提示', '原始16进制卡信息错误,请输入14位原始16进制HID卡信息!', QMessageBox.Yes)
                self.text_idserial.setFocus()
                return

            mynewuid = bytes.fromhex(SerialNum)
            status = Objdll.t5557_tohid(myctrlword, mypiccserial, oldpicckey, newpicckey, mynewuid)
            if status == 0:
                Objdll.idr_beep(38)
                QMessageBox.information(self, '提示', 'HID卡号写入成功,卡片变成HID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能!',QMessageBox.Yes)
            else:
                self.DispErrInf(status)

    def push_changeid0_clicked(self):
        SerialNum = self.text_idserial.text().strip()
        if (self.radio_em4100.isChecked()):
            if (is_valid_hex(SerialNum) == False or len(bytes.fromhex(SerialNum)) != 5):
                QMessageBox.critical(self, '提示', '原始16进制卡信息错误,请输入10位原始16进制ID卡信息!', QMessageBox.Yes)
                self.text_idserial.setFocus()
                return
            if self.comboBox.currentIndex()==0:
                self.text_newid0.setText(SerialNum[0:2])
                self.text_newid1.setText(SerialNum[2:4])
                self.text_newid2.setText(SerialNum[4:10])
            elif self.comboBox.currentIndex()==1:
                self.text_newid0.setText(SerialNum[0:2])
                self.text_newid1.setText('')
                self.text_newid2.setText('%010d' %(int(SerialNum[2:10],16)))
            elif self.comboBox.currentIndex()==2:
                self.text_newid0.setText(SerialNum[0:2])
                self.text_newid1.setText('')
                self.text_newid2.setText('%05d' % (int(SerialNum[2:6], 16))+'%05d' % (int(SerialNum[6:10], 16)))
            elif self.comboBox.currentIndex()==3:
                self.text_newid0.setText(SerialNum[0:2])
                self.text_newid1.setText(SerialNum[2:4])
                self.text_newid2.setText('%03d' % (int(SerialNum[4:6], 16))+'%05d' % (int(SerialNum[6:10], 16)))
        else:
            if (is_valid_hex(SerialNum) == False or len(bytes.fromhex(SerialNum)) != 7):
                QMessageBox.critical(self, '提示', '原始16进制卡信息错误,请输入14位原始16进制HID卡信息!', QMessageBox.Yes)
                self.text_idserial.setFocus()
                return
            if self.comboBox.currentIndex()==0:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                self.text_newid1.setText(SerialNum[6:8])
                self.text_newid2.setText(SerialNum[8:14])
            elif self.comboBox.currentIndex()==1:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                self.text_newid1.setText('')
                self.text_newid2.setText('%010d' %(int(SerialNum[6:14],16)))
            elif self.comboBox.currentIndex()==2:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                self.text_newid1.setText('')
                self.text_newid2.setText('%05d' % (int(SerialNum[6:10], 16))+'%05d' % (int(SerialNum[10:14], 16)))
            elif self.comboBox.currentIndex()==3:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                self.text_newid1.setText(SerialNum[6:8])
                self.text_newid2.setText('%03d' % (int(SerialNum[8:10], 16))+'%05d' % (int(SerialNum[10:14], 16)))
            elif self.comboBox.currentIndex()==4:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                bitstr=('00000000000000000000000000000000'+bin(int(SerialNum[6:14],16))[2:])[-32:]
                self.text_newid1.setText('%d' % (int(bitstr[:13], 2)))
                self.text_newid2.setText('%d' %(int(bitstr[-19:],2)))
            elif self.comboBox.currentIndex()==5:
                self.text_newid3.setText('%d' %(int(SerialNum[0:2],16)))
                self.text_newid0.setText(SerialNum[2:6])
                self.text_newid1.setText(SerialNum[6:10])
                self.text_newid2.setText('%05d' % (int(SerialNum[10:14], 16)))

    def push_changeid1_clicked(self):
        str0 = self.text_newid0.text().strip()
        str1 = self.text_newid1.text().strip()
        str2 = self.text_newid2.text().strip()
        str3 = self.text_newid3.text().strip()

        if (self.radio_em4100.isChecked()):
            if self.comboBox.currentIndex() == 0:
                newidstr=str0+str1+str2
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 5):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 1:
                newidstr = str0  +  '%08X' %(int(str2))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 5):
                    QMessageBox.critical(self, '提示', '厂商代码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 2:
                str2=('0000000000'+str2)[-10:]
                if int(str2[:5])>65535 or int(str2[-5:])>65535:
                    QMessageBox.critical(self, '提示', '卡号输入错误!', QMessageBox.Yes)
                    return
                newidstr = str0  + '%04X' %(int(str2[:5]))+ '%04X' %(int(str2[-5:]))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 5):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 3:
                str2 = ('00000000' + str2)[-8:]
                if int(str2[:3]) > 255 or int(str2[-5:]) > 65535:
                    QMessageBox.critical(self, '提示', '卡号输入错误!', QMessageBox.Yes)
                    return
                newidstr = str0 + str1 + '%02X' %(int(str2[:3])) + '%04X' %(int(str2[-5:]))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 5):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
        else:
            str3='%02X'%(int(str3))
            if self.comboBox.currentIndex() == 0:
                newidstr = str3 + str0 + str1 + str2
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 1:
                newidstr = str3 + str0 + str1 +  '%08X' %(int(str2))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 2:
                str2 = ('0000000000' + str2)[-10:]
                if int(str2[:5]) > 65535 or int(str2[-5:]) > 65535:
                    QMessageBox.critical(self, '提示', '卡号输入错误!', QMessageBox.Yes)
                    return
                newidstr = str3 + str0 + '%04X' %(int(str2[:5]))+ '%04X' %(int(str2[-5:]))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 3:
                str2 = ('00000000' + str2)[-8:]
                if int(str2[:3]) > 255 or int(str2[-5:]) > 65535:
                    QMessageBox.critical(self, '提示', '卡号输入错误!', QMessageBox.Yes)
                    return
                newidstr = str3 + str0 + str1 +  '%02X' %(int(str2[:3])) + '%04X' %(int(str2[-5:]))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 4:
                if int(str1)>8191 or int(str2)>524287:
                    QMessageBox.critical(self, '提示', '前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                str12=('0000000000000'+bin(int(str1))[2:])[-13:]+ ('0000000000000000000'+bin(int(str2))[2:])[-19:]
                str12='%08X' %(int(str12, 2))
                newidstr = str3 + str0 + str12
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)
            elif self.comboBox.currentIndex() == 5:
                newidstr = str3 + str0 + str1 + '%04X' %(int(str2))
                if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):
                    QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)
                    return
                self.text_idserial.setText(newidstr)


def is_valid_hex(input_str):
    input_str = input_str.replace(" ", "")
    try:
        if (len(bytes.fromhex(input_str)) == len(input_str) / 2):
            return True
        else:
            return False
    except:
        return False

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWindow = MainWindow()

    screen = QDesktopWidget().screenGeometry()
    size = mainWindow.geometry()
    # 获得窗口相关坐标
    newLeft = (screen.width() - size.width()) // 2
    newTop = (screen.height() - size.height()) // 2
    # 移动窗口使其居中
    mainWindow.move(newLeft, newTop)

    mainWindow.setWindowTitle("T5557 Python Demo")
    mainWindow.text_authkey.setVisible(False)
    mainWindow.text_piccserial.setVisible(False)
    mainWindow.label_20.setVisible(False)
    mainWindow.text_Enauthkey.setVisible(False)
    mainWindow.label_28.setVisible(False)
    mainWindow.text_newid3.setVisible(False)
    mainWindow.comboBox2.setVisible(False)
    mainWindow.comboBox.setCurrentIndex(1)
    mainWindow.show()

    font = QFont()
    font.setFamily('Arial')  # 设置字体名称
    font.setPointSize(8)

    if sys.platform == 'linux' or sys.platform == 'mac':
        # Linux加载当前目录下的so库
        dllfile = sys.path[0] + '/libOURIDR.so'
        Objdll = ctypes.cdll.LoadLibrary(dllfile)
    else:
        # windows系统加载当前目录下的DLL库
        dllfile = sys.path[0] + '\OUR_IDR.dll'
        Objdll = ctypes.windll.LoadLibrary(dllfile)

    sys.exit(app.exec_())

源码下载:T5557低频标签Python读写源码资源-CSDN文库

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1585158.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于ARM内核的智能手环(day7)

RTC&#xff08;实时时钟&#xff09; 什么是RTC&#xff1f; RTC是指实时时钟&#xff08;Real-Time Clock&#xff09;&#xff0c;是一种能够持续跟踪时间的计时器&#xff0c;即使在设备断电的情况下也能保持时间的准确性。它通常用于需要准确时间记录的应用&#xff0c;…

遥感降水、气温数据的处理与可视化、ERA5大气再分析数据的统计分析、干旱监测及SCI论文写作技巧

深度探讨人工智能在大气科学中的应用&#xff0c;特别是如何结合最新AI模型与Python技术处理和分析气候数据。课程介绍包括GPT-4等先进AI工具&#xff0c;旨在帮助学员掌握这些工具的功能及应用范围。内容覆盖使用GPT处理数据、生成论文摘要、文献综述、技术方法分析等实战案例…

Oracle数据库imp文件导入失败提示:“不是有效的导出文件, 标头验证失败”解决方法

导入数据库时&#xff0c;直接提示不是有效的导出文件&#xff0c;标头验证失败 原因&#xff1a;这是因为导出的imp文件和你当前导入的数据库版本不一致造成的&#xff0c;例如&#xff1a;导出文件版本号12.0.1 导入数据库的版本号11.0.2&#xff0c;会报这个错误。 解决办法…

[C++]map set

一、set 1、概念 set是按照一定次序存储元素的容器在set中&#xff0c;元素的value也标识它(value就是key&#xff0c;类型为T)&#xff0c;并且每个value必须是唯一的。set中的元素不能在容器中修改(元素总是const)&#xff0c;但是可以从容器中插入或删除它们。在内部&…

泰迪智能科技高职人工智能专业人才培养方案

人工智能行业近年来得到了快速发展&#xff0c;全球科技公司都在竞相投入人工智能的研发&#xff0c;从硅谷到北京&#xff0c;都在人工智能上取得了显著的进步。人工智能已经从学术研究转变为影响制造业、医疗保健、交通运输和零售等多个行业的关键因素。我国政策的积极推动下…

备战2024年中学生古诗文大会(初中组):单选题真题和独家解析

我们继续来做中学生古诗文大会&#xff08;初中组&#xff09;&#xff0c;即我们常说的初中生古诗文大会的部分真题&#xff0c;从中了解初中生古诗文大会的考察内容和形式&#xff0c;并且提供了我独家的题目解析和答案&#xff0c;供初中的同学们学习和参考。 初中生古诗文…

C++常用技巧与算法总结(简洁)

前言警告&#xff1a; 1、注意数据的边界&#xff0c;数组不能越界&#xff01; 2、 时间复杂度 3、开long long 4、注意输出的四舍五入 printf("%d %.0f\n",k,sum*1.0/k);//double类型输出会自动四舍五入&#xff1b; 5、让Dev C支持C11 先在dev的【工具】里找…

从零到部署指南:Ubuntu上安装Boost和Crow库

1.安装boost 在安装Crow之前&#xff0c;需要确保您的系统中已经安装了Boost库。以下是Boost库安装步骤&#xff1a; 首先&#xff0c;从Boost官方网站或通过特定的链接下载Boost的源码&#xff0c;boost源码具体可参看这个链接&#xff1a; https://blog.csdn.net/duan199201…

提升App用户黏性,Xinstall推出注册用户自动绑定功能

在移动互联网时代&#xff0c;App的用户留存和活跃度对于产品的成功至关重要。然而&#xff0c;许多App在面临用户注册和绑定时&#xff0c;常常遭遇繁琐的操作流程和不佳的用户体验&#xff0c;导致用户流失严重。为了解决这一痛点&#xff0c;Xinstall推出了一项创新功能——…

蚂蚁集团CodeFuse 发布“图生代码”功能,支持产品设计图一键生成代码

4月11日&#xff0c;蚂蚁集团自研的智能研发平台CodeFuse推出“图生代码”新功能&#xff0c;支持开发人员用产品设计图一键生成代码&#xff0c;大幅提升前端页面的开发效率。目前相关功能正在内测。 和很多互联网公司一样&#xff0c;蚂蚁集团正在内部全面推行AI编程&#x…

Ubuntu-22.04安装Virtualbox并安装Windows10

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、Virtualbox是什么&#xff1f;二、安装Virtualbox1.关闭Secure Boot2.安装 三、安装Windows101.新装虚拟机基本配置2.新装虚拟机核心配置 总结 前言 虚拟机…

【实战JVM】双亲委派机制

个人名片&#xff1a; &#x1f43c;作者简介&#xff1a;一名大三在校生&#xff0c;喜欢AI编程&#x1f38b; &#x1f43b;‍❄️个人主页&#x1f947;&#xff1a;落798. &#x1f43c;个人WeChat&#xff1a;hmmwx53 &#x1f54a;️系列专栏&#xff1a;&#x1f5bc;️…

pip install opencv-python出现ModuleNotFoundError: No module named ‘skbuild‘错误解决方案

问题描述 File “”, line 1, in File “/tmp/pip-build-o148qsmj/opencv-python/setup.py”, line 10, in from skbuild import cmaker, setup ModuleNotFoundError: No module named ‘skbuild’ Command “python setup.py egg_info” failed with error code 1 in /tmp…

东用科技助力5G+区域教育管理智慧平安校园建设

一、 方案背景 为深入贯彻党中央、国务院关于加快5G发展、加强教育信息化工作的决策部署&#xff0c;加快推进《5G应用“扬帆”行动计划》实施&#xff0c;促进5G与教育融合创新发展&#xff0c;按照“育人为本、多方协同、问题导向、深度融合”的原则&#xff0c;工业和信息化…

LeetCode-1766. 互质树【树 深度优先搜索 广度优先搜索 数组 数学 数论】

LeetCode-1766. 互质树【树 深度优先搜索 广度优先搜索 数组 数学 数论】 题目描述&#xff1a;解题思路一&#xff1a;DFS 中记录节点值的深度和编号&#xff0c;回溯写法。关键点是1 < nums[i] < 50解题思路二&#xff1a;0解题思路三&#xff1a;0 题目描述&#xff1…

心跳机制原理学习

心跳机制 应用场景&#xff1a; 在长连接下&#xff0c;有可能很长一段时间都没有数据往来。理论上说&#xff0c;这个连接是一直保持连接的&#xff0c;但是实际情况中&#xff0c;如果中间节点出现什么故障是难以知道的。更要命的是&#xff0c;有的节点&#xff08;防火墙…

实验5 流程图和盒图ns图

一、实验目的 通过绘制流程图和盒图&#xff0c;熟练掌握流程图和盒图的基本原理。 能对简单问题进行流程图和盒图的分析&#xff0c;独立地完成流程图和盒图设计。 二、实验项目内容&#xff08;实验题目&#xff09; 1、用Microsoft Visio绘制下列程序的程序流程图。 若…

Go语言mac环境搭建详解

Go语言mac环境搭建详解见视频&#xff0c;视频下方也有讲解具体的操作步骤。 Golang Mac电脑环境搭建、开发工具Vscode配置 Go语言mac环境搭建步骤如下&#xff1a; 1、下载安装Golang Go官网下载地址&#xff1a;https://golang.org/dl/ Go官方镜像站&#xff08;推荐&…

一线城市嵌入式软件开发工程师每年调薪幅度能有多少?

15%对于刚入职的新人来说确实有可能有&#xff0c;如果你的底薪比较低的话。不过后面随着你工资变高&#xff0c;这个幅度会越来越趋向0%。在开始前我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「 嵌入式的资料从专业入门到高级教程」&#xff0c; 点个关注在…

GEE数据集——汉森全球森林变化数据集Hansen Global Forest Change v1.11 (2000-2023)

Hansen Global Forest Change v1.11 (2000-2023) 对大地遥感卫星图像进行时间序列分析以确定全球森林范围和变化特征的结果。 第一个 "和 "最后一个 "波段是大地遥感卫星光谱波段&#xff08;红、近红外、SWIR1 和 SWIR2&#xff09;的第一个和最后一个可用年…