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

本示例使用的发卡器: 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 sysimport 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) % 256if (status != 0):self.DispErrInf(status)def push_getdevnum_clicked(self):devno = bytes(4)  # 声明4个字节缓冲status = Objdll.pcdgetdevicenumber(devno) % 256if (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()returnmyctrlword = myctrlword + NEEDKEYoldpicckey = 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()returnmyctrlword = myctrlword + NEEDSERIALmypiccserial = 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' + seleblock0else:seleblock0 = '0' + seleblock0mypiccblockflag=bytes([int(seleblock0, 2)])seleblock1 = '0'    #第1页块选标志位,注意首位先取0for i in range(8,12):self.chckbox = self.findChild(QCheckBox, "check_block%d" % (i))if self.chckbox.isChecked():seleblock1 = '1' + seleblock1else:seleblock1 = '0' + seleblock1mypiccblockflag = mypiccblockflag + bytes([int(seleblock1, 2)])status = Objdll.t5557_read(myctrlword, mypiccserial, oldpicckey, mypiccblockflag, mypiccdata) % 256if (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=0for 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+8self.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()returnmyctrlword = myctrlword + NEEDKEYoldpicckey = 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()returnmyctrlword = myctrlword + NEEDSERIALmypiccserial = 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' + seleblock0blockdata=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()returnwritedata=writedata+blockdataelse:seleblock0 = '0' + seleblock0mypiccblockflag = bytes([int(seleblock0, 2)])seleblock1 = '0'  # 第1页块选标志位,注意首位先取0for 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' + seleblock1blockdata = 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()returnwritedata = writedata + blockdataelse:seleblock1 = '0' + seleblock1mypiccblockflag = mypiccblockflag + bytes([int(seleblock1, 2)])writebuf=bytes.fromhex(writedata)if (len(writebuf)<1):QMessageBox.critical(self, '提示', '请选择要写入数据的块号!', QMessageBox.Yes)returnstatus = Objdll.t5557_write(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,writebuf) % 256if (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()returnmyctrlword = myctrlword + NEEDKEYoldpicckey = 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()returnmyctrlword = myctrlword + NEEDSERIALmypiccserial = 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()returnnewkeybuf=bytes.fromhex(newkeystr)status = Objdll.t5557_changekey(myctrlword, mypiccserial, oldpicckey, newkeybuf) % 256if (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()returnmyctrlword = myctrlword + NEEDKEYoldpicckey = 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()returnnewpicckey=bytes.fromhex(newkeystr)myctrlword = myctrlword + KEYENABLEconfigstr=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()returnconfigbuf=bytes.fromhex(configstr)status = Objdll.t5557_init(myctrlword, mypiccserial, oldpicckey, configbuf, newpicckey) % 256if (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) % 256if (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) % 256if (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()returnmyctrlword = myctrlword + NEEDKEYoldpicckey = 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()returnmyctrlword = myctrlword + NEEDSERIALmypiccserial = 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()returnmyctrlword = myctrlword + KEYENABLEnewpicckey = 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()returnmynewuid=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()returnmynewuid = 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()returnif 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()returnif 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+str2if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 5):QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)returnself.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)returnself.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)returnnewidstr = 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)returnself.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)returnnewidstr = 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)returnself.text_idserial.setText(newidstr)else:str3='%02X'%(int(str3))if self.comboBox.currentIndex() == 0:newidstr = str3 + str0 + str1 + str2if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)returnself.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)returnself.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)returnnewidstr = 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)returnself.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)returnnewidstr = 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)returnself.text_idserial.setText(newidstr)elif self.comboBox.currentIndex() == 4:if int(str1)>8191 or int(str2)>524287:QMessageBox.critical(self, '提示', '前缀码、卡号输入错误!', QMessageBox.Yes)returnstr12=('0000000000000'+bin(int(str1))[2:])[-13:]+ ('0000000000000000000'+bin(int(str2))[2:])[-19:]str12='%08X' %(int(str12, 2))newidstr = str3 + str0 + str12if (is_valid_hex(newidstr) == False or len(bytes.fromhex(newidstr)) != 7):QMessageBox.critical(self, '提示', '厂商代码、前缀码、卡号输入错误!', QMessageBox.Yes)returnself.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)returnself.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 Trueelse:return Falseexcept:return Falseif __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)mainWindow = MainWindow()screen = QDesktopWidget().screenGeometry()size = mainWindow.geometry()# 获得窗口相关坐标newLeft = (screen.width() - size.width()) // 2newTop = (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.hqwc.cn/news/618350.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【LeetCode】回溯算法类题目详解

所有题目均来自于LeetCode&#xff0c;刷题代码使用的Python3版本 回溯算法 回溯算法是一种搜索的方法&#xff0c;在二叉树总结当中&#xff0c;经常使用到递归去解决相关的问题&#xff0c;在二叉树的所有路径问题中&#xff0c;我们就使用到了回溯算法来找到所有的路径。 …

策略为王股票软件源代码\StkUI\View\BaseView.cpp-------显示股票基本资料的视图-------程序代码都在里面了

CString strHeader info.GetStockCode(); strHeader " "; /修改 strHeader info.GetStockName(); strHeader "\r\n\r\n "; GetEditCtrl().SetWindowText( strHeader ); GetEditCtrl().SetSel…

5.9 mybatis之callSettersOnNulls作用

文章目录 1. 当callSettersOnNullstrue时2. 当callSettersOnNullsfalse时 在mybatis的settings配置参数中有个callSettersOnNulls参数&#xff0c;官方解释为&#xff1a;指定当结果集中值为 null 的时候是否调用映射对象的 setter&#xff08;map 对象时为 put&#xff09;方法…

REINFORCE及进阶算法讲解笔记

REINFORCE 总结 估计VALUE-methods没有在理论上证明收敛&#xff0c;而policy-methods不需要估计value function。 本算法总结了过去的算法&#xff0c;将过去算法作为特例看待&#xff0c;证明了即使是结合函数估计和实际采样的value梯度都可以无偏估计&#xff0c;证明了某种…

访问者模式类图与代码

某图书管理系统中管理着两种类型的文献&#xff1a;图书和论文。现在要求统计所有馆藏文献的总页码(假设图书馆中有一本540页的图书和两篇各25页的论文&#xff0c;那么馆藏文献的总页码就是590页)。采用Visitor(访问者)模式实现该要求&#xff0c;得到如图7.16所示的类图。 访…

Java_04

Servlet: Servlet即serverapplet&#xff0c;指运行在服务器端的小程序&#xff0c;是sun公司提供的一门用于开发动态web资源的技术&#xff0c;通常我们也把实现了servlet接口的java程序也称为Servlet&#xff1b; package com.example.demo;import jakarta.servlet.*;impor…

利用Sentinel解决雪崩问题(一)流量控制

1、解决雪崩问题的常见方式有四种: 超时处理:设定超时时间&#xff0c;请求超过一定时间没有响应就返回错误信息&#xff0c;不会无休止等待;舱壁模式:限定每个业务能使用的线程数&#xff0c;避免耗尽整个tomcat的资源&#xff0c;因此也叫线程隔离;熔断降级:由断路器统计业务…

数据——关键生产要素

数据作为数字经济时代的关键生产要素&#xff0c;逐步融入生产生活各方面&#xff0c;深刻影响并重构着经济社会运行和社会治理&#xff0c;已成为影响未来发展的关键战略性资源。近年来&#xff0c;我国高度重视发展数字经济、数据要素及其市场化配置改革&#xff0c;发布了一…

风电机组中仍然装有电动机吗?

风电机组中确实装有电动机。虽然风电机组的主要功能是将风能转换为电能&#xff0c;但在其启动和运行过程中&#xff0c;电动机发挥着不可或缺的作用。 在风电机组的启动阶段&#xff0c;电动机负责提供初始的启动动力。由于风力发电的特性&#xff0c;风电机组并不能在任意风…

快速安装/升级/卸载Ascend配套软件包

一、参考资料 配套MindSpore 昇腾软件安装指引&#xff08;23.0.RC3&#xff09; 快速安装CANN 二、安装Ascend配套软件包 1. Ascend配套软件包简介 Ascend配套软件包&#xff0c;包括&#xff1a;固件、驱动和CANN&#xff08;Compute Architecture for Neural Networks&…

【设计模式】六大设计原则

设计原则 研究 23 种设计模式是困难的&#xff0c;甚至是没必要的六大设计原则零、单一职责原则开闭原则里氏代换原则依赖倒置原则接口隔离原则迪米特法则合成复用原则 研究 23 种设计模式是困难的&#xff0c;甚至是没必要的 设计模式有23种&#xff0c;我认为对普通人来说想…

【C++成长记】C++入门 | 类和对象(上) |类的作用域、类的实例化、类的对象大小的计算、类成员函数的this指针

&#x1f40c;博主主页&#xff1a;&#x1f40c;​倔强的大蜗牛&#x1f40c;​ &#x1f4da;专栏分类&#xff1a;C❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 目录 一、类的作用域 二、类的实例化 三、类对象模型 四、this指针 1、this指针的引出 2 this指针的特…