123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- import os
- import qrcode
- from PIL.ImageQt import ImageQt
- from PyQt5.QtCore import *
- from PyQt5.QtCore import Qt
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- import CRC8
- from Config import Configuration
- from ui.VersionSet import Ui_Form
- softwareIconPath = r'D:\PycharmProjects\Scan\ScanUtils\pic\scan.png'
- # softwareIconPath = r':pic/scan.png'
- folderName = 'material'
- VERSION = '2.7'
- class VersionSet(QWidget):
- #自定义信号
- mySignal = pyqtSignal(str)
- def __init__(self, parent = None, closeToDlg = None):
- '''构造函数'''
- super(VersionSet, self).__init__(parent)
- self.ui = Ui_Form()
- self.ui.setupUi(self)
- self.setWindowIcon(QIcon(softwareIconPath))
- self.setWindowTitle('生产物料扫码记录V{0}'.format(VERSION))
- self.setWindowFlags(self.windowFlags() | Qt.CustomizeWindowHint)#QtCore.Qt.WindowStaysOnTopHint顶层显示
- #禁用最小化
- # self.setWindowFlags(self.windowFlags() & ~Qt.WindowMinimizeButtonHint)
- #禁用最大化
- # self.setWindowFlags(self.windowFlags() & ~Qt.WindowMaximizeButtonHint)
- #禁止拉伸窗口大小
- # self.setFixedSize(self.width(), self.height())
- self.closeToDlg = closeToDlg
- self.widgetInit()
- # 设置参数
- def getParamDict(self, newRule = True):
- paramDict = {}
- if newRule:#新规则2023年4月20日
- paramDict['芯片主版本'] = (('HX01', 1), ('HX02', 2), ('HX03', 3), ('HX05', 4), ('HX10', 5))#4位
- paramDict['芯片次版本'] = (('第1版(A)', 1), ('第2版(B)', 2), ('第3版(C)', 3), ('第4版(D)', 4), ('第5版(E)', 5), ('第6版(F)', 6))#4位
- paramDict['数字电容容值'] = (('无电容', 0), ('1uF', 1), ('4.7uF', 2), ('10uF', 3), ('22uF', 4), ('33uF', 5), ('47uF', 6), ('68uF', 7), ('100uF', 8))#4位
- # 2022年9月28日由3位扩展到5位
- paramDict['数字电容品牌'] = (('试验品牌', 0), ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('火炬', 4), ('湘江', 5), ('振华', 6), ('丰华', 7), ('国巨', 8), ('三星', 9))
- paramDict['电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2))#3位
- paramDict['起爆电容容值'] = (('无电容', 0), ('33uF', 1), ('47uF', 2), ('68uF', 3), ('100uF', 4), ('220uF', 5),('120uF', 6))#3位
- paramDict['起爆电容品牌'] = (('试验品牌', 0), ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('永铭', 4), ('丰宾', 5), ('米朗', 6))#3位
- paramDict['引火件形式'] = (('无', 0), ('焊接刚性药头', 1), ('贴片刚性药头', 2), ('贴片发热电阻', 3), ('碗状电阻器', 4))#3位
- paramDict['桥丝规格'] = (('16um(7.9~8.6欧)', 0), ('2欧姆', 1), ('8欧姆', 2), ('20um', 3), ('22um', 4), ('25um', 5), ('30um', 6),('试验规格', 7), ('40um', 8),('28um', 9),('50um', 10))#5位
- paramDict['脚线焊接方式'] = (('无孔焊接', 0), ('有孔焊接', 1), ('铭威铆接', 2), ('创德铆接', 3))#4位
- paramDict['PCB供应商'] = (('丰达兴', 0), ('欧拓', 1), ('镓锐', 2), ('联宇宏', 3))
- else:#旧规则
- paramDict['芯片主版本'] = (('HX02', 2), ('HX03', 3)) # 4位
- paramDict['芯片次版本'] = (('第1版(A)', 1), ('第2版(B)', 2), ('第3版(C)', 3), ('第4版(D)', 4), ('第5版(E)', 5)) # 4位
- paramDict['数字电容容值'] = (
- ('无电容', 0), ('1uF', 1), ('4.7uF', 2), ('10uF', 3), ('22uF', 4), ('33uF', 5), ('47uF', 6), ('68uF', 7),
- ('100uF', 8)) # 4位
- # 2022年9月28日由3位扩展到5位
- paramDict['数字电容品牌'] = (
- ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('火炬', 4), ('湘江', 5), ('振华', 6), ('丰华', 7), ('国巨', 8))
- paramDict['数字电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2)) # 3位
- paramDict['起爆电容容值'] = (('无电容', 0), ('33uF', 1), ('47uF', 2), ('68uF', 3), ('100uF', 4)) # 3位
- paramDict['起爆电容品牌'] = (('AVX', 1), ('Vishay', 2), ('Sunlord', 3)) # 3位
- paramDict['起爆电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2)) # 3位
- paramDict['引火件形式'] = (('无', 0), ('焊接刚性药头', 1), ('贴片刚性药头', 2), ('贴片发热电阻', 3), ('碗状电阻器', 4)) # 3位
- paramDict['桥丝规格'] = (('16um(7.9~8.6欧)', 0), ('2欧姆', 1)) # 5位
- paramDict['脚线焊接方式'] = (('焊接(有孔)', 1), ('铆接', 2), ('焊接(无孔)', 3)) # 4位
- return paramDict
- # 初始化:
- def widgetInit(self):
- paramDict = self.getParamDict(True)
- for item in paramDict['芯片主版本']:
- self.ui.chipVer_1.addItem(item[0])
- for item in paramDict['芯片次版本']:
- self.ui.chipVer_2.addItem(item[0])
- for item in paramDict['数字电容容值']:
- self.ui.workCapValue.addItem(item[0])
- for item in paramDict['数字电容品牌']:
- self.ui.workCapVender.addItem(item[0])
- for item in paramDict['起爆电容容值']:
- self.ui.blastCapValue.addItem(item[0])
- for item in paramDict['起爆电容品牌']:
- self.ui.blastCapVender.addItem(item[0])
- for item in paramDict['电容耐压']:
- self.ui.capVoltage.addItem(item[0])
- for item in paramDict['引火件形式']:
- self.ui.bridgeType.addItem(item[0])
- for item in paramDict['桥丝规格']:
- self.ui.bridgeValue.addItem(item[0])
- for item in paramDict['PCB供应商']:
- self.ui.pcbVender.addItem(item[0])
- for item in range(32):
- self.ui.pcbVer.addItem(str(item).zfill(2))#5位
- for item in paramDict['脚线焊接方式']:
- self.ui.lineType.addItem(item[0])
- self.setDefault()
- self.updateStatus()
- self.versionCode=''
- self.productDate=''
- self.setDirDefault()
- # 创建保存.txt的文件夹
- self.mkdirFile()
- self.set_fileName_Default()
- self.ui.chipVer_1.activated.connect(self.updateStatus)
- self.ui.chipVer_2.activated.connect(self.updateStatus)
- self.ui.workCapValue.activated.connect(self.updateStatus)
- self.ui.workCapVender.activated.connect(self.updateStatus)
- self.ui.blastCapValue.activated.connect(self.updateStatus)
- self.ui.blastCapVender.activated.connect(self.updateStatus)
- self.ui.capVoltage.activated.connect(self.updateStatus)
- self.ui.bridgeType.activated.connect(self.updateStatus)
- self.ui.bridgeValue.activated.connect(self.updateStatus)
- self.ui.pcbVender.activated.connect(self.updateStatus)
- self.ui.pcbVer.activated.connect(self.updateStatus)
- self.ui.lineType.activated.connect(self.updateStatus)
- self.ui.productDate.dateChanged.connect(self.updateStatus)
- # self.ui.copy.clicked.connect(self.copySolf)
- # self.ui.commit.clicked.connect(self.open_ScanInput)
- self.ui.commit.clicked.connect(self.open_ScanInput)
- self.ui.change_dir.clicked.connect(self.select_dir)
- self.ui.btnFileName.clicked.connect(self.get_text)
- # self.ui.read.clicked.connect(self.readSolf
- # self.ui.write.clicked.connect(self.writeSolf)
- # self.ui.analyst.clicked.connect(self.analystSolf).
- # 打开窗口
- def open_ScanInput(self,event):
- versionCode= self.ui.versionCode.text()
- productDate = self.ui.productDate.text()
- fileName = self.ui.file_name.text()
- # 默认路径名
- directory = self.ui.dir.text()
- file_path =directory + '/' + fileName
- from ScanInput import ScanInput
- if os.path.exists(file_path):
- msg_box = QMessageBox(QMessageBox.Question, "提示", "目标文件夹中存在已存在同名文件,是否需要重命名")
- msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
- # 将 Save 按钮的文本设置为中文
- save_button = msg_box.button(QMessageBox.Yes)
- save_button.setText("是")
- save_button = msg_box.button(QMessageBox.No)
- save_button.setText("否")
- # 执行
- choice = msg_box.exec_()
- if choice == QMessageBox.No:
- self.ScanInput_ui = ScanInput(versionCode, productDate, fileName, directory)
- self.ScanInput_ui.show()
- elif choice == QMessageBox.Yes:
- msg_box.done(choice)
- else:
- # 生成二维码
- self.saveCode()
- self.ScanInput_ui = ScanInput(versionCode, productDate, fileName, directory)
- self.ScanInput_ui.show()
- # 保存二维码
- def saveCode(self):
- versionCode= self.ui.versionCode.text()
- qr_code = self.generate_qr_code(versionCode)
- file_path_name = "/"+versionCode+".png"
- file_path =self.ui.dir.text() +file_path_name
- self.save_qr_code(qr_code, file_path)
- # 创建默认的文件夹
- def mkdirFile(self):
- desktopPath = Configuration().get_desktop()
- folderNamePath = desktopPath + '\\' + folderName
- if not os.path.exists(folderNamePath):
- os.mkdir(folderNamePath)
- else:
- return True
- # 更改目录
- def select_dir(self):
- filePathName = self.ui.dir.text()
- options = QFileDialog.Options()
- options |= QFileDialog.ShowDirsOnly
- # 获取返回在值
- directory = QFileDialog.getExistingDirectory(self, "选择目录",os.path.expanduser(filePathName), options=options)
- if not directory:
- self.ui.dir.setText(filePathName)
- else:
- self.ui.dir.setText(directory)
- # 默认地址
- def setDirDefault(self):
- desktopPath = Configuration().get_desktop()
- desktopPath = desktopPath.replace('\\','/')
- filePathName = desktopPath + '/' + folderName
- self.ui.dir.setText(filePathName)
- # 生成二维码
- def generate_qr_code(self,data: str) -> QPixmap:
- qr = qrcode.QRCode(version=1, box_size=10, border=4)
- qr.add_data(data)
- qr.make(fit=True)
- img = qr.make_image(fill_color="black", back_color="white")
- pixmap = QPixmap.fromImage(ImageQt(img))
- return pixmap
- # 保存二维码
- def save_qr_code(self,pixmap: QPixmap, file_path: str):
- pixmap.save(file_path)
- # 设置初始值
- def setDefault(self):
- self.ui.workCapValue.setCurrentIndex(4)#默认22uF
- self.ui.workCapVender.setCurrentIndex(6)#默认振华
- self.ui.blastCapValue.setCurrentIndex(1)#默认33uF
- self.ui.blastCapVender.setCurrentIndex(2)#默认Vishay
- self.ui.chipVer_1.setCurrentIndex(1)
- self.ui.chipVer_2.setCurrentIndex(4)
- self.ui.bridgeType.setCurrentIndex(4)
- self.ui.lineType.setCurrentIndex(0)
- self.ui.productDate.setDate(QDate.currentDate())
- # 设置文件名称初始值
- def set_fileName_Default(self):
- versionode= self.ui.versionCode.text()
- productDate = self.ui.productDate.text()
- fileName = versionode+'_'+productDate+'.txt'
- self.ui.file_name.setText(fileName)
- # 修改文件名称 并检查文件名称
- def get_text(self):
- # QInputDialog组件定义
- inputDialog = QInputDialog(self)
- # QInputDialog组件设置
- versionCode= self.ui.versionCode.text()
- productDate = self.ui.productDate.text()
- defaultFileName = versionCode+'_'+productDate
- FileNameLab = self.ui.file_name.text()
- FileNameLab = FileNameLab.replace(".txt","")
- # 方式二
- defaultFileLen = len(defaultFileName)
- text, ok = inputDialog.getText(self, '标题', '请输入文本:', text=FileNameLab) # 返回文本内容和按钮的点击项
- if ok:
- if text[:defaultFileLen] == defaultFileName:
- outputTxt = text + ".txt"
- self.ui.file_name.setText(outputTxt)
- inputDialog.reject()
- else:
- QMessageBox.information(self, "提示", f"请以{defaultFileName}作为开头的文件名") # 显示输入的文本信息
- self.get_text()
- def paramStr2Value(self, content, paramList):
- for item in paramList:
- if content == item[0]:
- return item[1]
- return None
- def paramValue2Str(self, value, paramList):
- for item in paramList:
- if value == item[1]:
- return item[0]
- return None
- # 版本号
- def getCurrentParam(self):
- paramDict = self.getParamDict(True)
- chipVer_1 = self.paramStr2Value(self.ui.chipVer_1.currentText(), paramDict['芯片主版本'])
- chipVer_2 = self.paramStr2Value(self.ui.chipVer_2.currentText(), paramDict['芯片次版本'])
- workCapVender = self.paramStr2Value(self.ui.workCapVender.currentText(), paramDict['数字电容品牌'])
- workCapValue = self.paramStr2Value(self.ui.workCapValue.currentText(), paramDict['数字电容容值'])
- blastCapVender = self.paramStr2Value(self.ui.blastCapVender.currentText(), paramDict['起爆电容品牌'])
- blastCapValue = self.paramStr2Value(self.ui.blastCapValue.currentText(), paramDict['起爆电容容值'])
- capVoltage = self.paramStr2Value(self.ui.capVoltage.currentText(), paramDict['电容耐压'])
- bridgeType = self.paramStr2Value(self.ui.bridgeType.currentText(), paramDict['引火件形式'])
- bridgeValue = self.paramStr2Value(self.ui.bridgeValue.currentText(), paramDict['桥丝规格'])
- pcbVender = self.paramStr2Value(self.ui.pcbVender.currentText(), paramDict['PCB供应商'])
- pcbVer = int(self.ui.pcbVer.currentText())
- lineType = self.paramStr2Value(self.ui.lineType.currentText(), paramDict['脚线焊接方式'])
- productDate = self.ui.productDate.date()#发料日期
- U64Value = chipVer_1 & 0x0F #芯片主版本号共4位,bit0-3
- U64Value |= (chipVer_2 & 0x0F) << 4#芯片次版本号共4位,bit4-7
- U64Value |= (workCapVender & 0x1F) << 8 #数字电容品牌共5位 ,bit8-12
- U64Value |= (workCapValue & 0x0F) << 13 #数字电容容量共4位 ,bit13-16
- U64Value |= (blastCapVender & 0x07) << 17 #起爆电容品牌共3位 ,bit17-19
- U64Value |= (blastCapValue & 0x07) << 20 #起爆电容容量共3位 ,bit20-22
- U64Value |= (capVoltage & 0x07) << 23 #电容耐压共3位 ,bit23-25
- U64Value |= (bridgeType & 0x07) << 26 #引火件形式共3位 ,bit26-28
- U64Value |= (bridgeValue & 0x1F) << 29 #桥丝规格共5位 ,bit29-33
- U64Value |= (pcbVer & 0x1F) << 34 #PCB版本流水号共5位 ,bit34-38
- U64Value |= (pcbVender & 0x03) << 39 #PCB供应商共2位 ,bit39-40
- U64Value |= (lineType & 0x07) << 41 #脚线焊接方式共3位 ,bit41-43
- U64Value |= (((productDate.year()-2020)*12 + (productDate.month()-1)) & 0x7F) << 44 # 发料日期中的年月共7位 ,bit44-50
- U64Value |= (productDate.day() & 0x1F) << 51 # 发料日期中的日共5位 ,bit51-55
- Bytes_0 = U64Value & 0xFF
- Bytes_1 = (U64Value >> 8) & 0xFF
- Bytes_2 = (U64Value >> 16) & 0xFF
- Bytes_3 = (U64Value >> 24) & 0xFF
- Bytes_4 = (U64Value >> 32) & 0xFF
- Bytes_5 = (U64Value >> 40) & 0xFF
- Bytes_6 = (U64Value >> 48) & 0xFF
- hexStr = '%02X%02X%02X%02X%02X%02X%02X' % (Bytes_0, Bytes_1, Bytes_2, Bytes_3, Bytes_4, Bytes_5, Bytes_6)
- hexStr += '%02X' % ((~CRC8.getCrc8(bytearray.fromhex(hexStr))) & 0xFF)
- data = bytearray([0x01]) # 示例数据,转换为字节数组
- # print((CRC8.getCrc8(data)))
- return hexStr
- def updateStatus(self, param= None):
- status = True
- if self.ui.workCapValue.currentText() == "无电容":
- status = False
- self.ui.workCapVender.setEnabled(status)
- status = True
- if self.ui.blastCapValue.currentText() == "无电容":
- status = False
- self.ui.blastCapVender.setEnabled(status)
- self.ui.versionCode.setText(self.getCurrentParam())
- self.set_fileName_Default()
- def showVersion(self, hexStr):
- if len(hexStr) == 16 and hexStr[12:14] == "00":
- self.showVersionForOldRule(hexStr)
- else:
- self.showVersionForNewRule(hexStr)
- def showVersionForOldRule(self, hexStr):
- result, infos = self.getVersionInfosForOldRule(hexStr)
- if not result:
- QMessageBox.critical(self, '错误', '{0}'.format(infos))
- return
- contents = []
- key = '延期模块版本代码'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '芯片主版本'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '芯片次版本'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '数字电容品牌'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '数字电容容值'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '数字电容耐压'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '起爆电容品牌'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '起爆电容容值'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '起爆电容耐压'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '引火件形式'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '桥丝规格'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = 'PCB版本流水号'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '脚线焊接方式'
- contents.append("{0}:{1}".format(key, infos[key]))
- QMessageBox.information(self, '信息(旧规则)', '\n'.join(contents))
- def getVersionInfosForOldRule(self, versionHexStr):
- if not versionHexStr or len(versionHexStr) != 16:
- return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
- try:
- verBytes = bytearray.fromhex(versionHexStr)
- except Exception as e:
- return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
- crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
- if crc8 != verBytes[-1]:
- return False, '{0}\n校验值错误'.format(versionHexStr)
- U64Value = 0
- U64Value |= verBytes[6]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[5]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[4]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[3]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[2]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[1]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[0]&0xFF
- paramDict = self.getParamDict(False)
- infos = {}
- infos['延期模块版本代码'] = versionHexStr
- key = '芯片主版本'
- value = U64Value & 0x0F
- chipVer_1 = self.paramValue2Str(value, paramDict[key])
- if chipVer_1 == None:
- chipVer_1 = '未知({0})'.format(value)
- infos[key] = chipVer_1
- key = '芯片次版本'
- value = (U64Value >> 4) & 0x0F
- chipVer_2 = self.paramValue2Str(value, paramDict[key])
- if chipVer_2 == None:
- chipVer_2 = '未知({0})'.format(value)
- infos[key] = chipVer_2
- key = '数字电容品牌'
- value = (((U64Value >> 46) & 0x03)<<3) + ((U64Value >> 8) & 0x07)#2022年9月28日由3位扩展到5位
- workCapVender = self.paramValue2Str(value, paramDict[key])
- if workCapVender == None:
- workCapVender = '未知({0})'.format(value)
- infos[key] = workCapVender
- key = '数字电容容值'
- value = (U64Value >> 11) & 0x0F
- workCapValue = self.paramValue2Str(value, paramDict[key])
- if workCapValue == None:
- workCapValue = '未知({0})'.format(value)
- infos[key] = workCapValue
- key = '数字电容耐压'
- value = (U64Value >> 15) & 0x07
- workCapVoltage = self.paramValue2Str(value, paramDict[key])
- if workCapVoltage == None:
- workCapVoltage = '未知({0})'.format(value)
- infos[key] = workCapVoltage
- key = '起爆电容品牌'
- value = (U64Value >> 18) & 0x07
- blastVender = self.paramValue2Str(value, paramDict[key])
- if blastVender == None:
- blastVender = '未知({0})'.format(value)
- infos[key] = blastVender
- key = '起爆电容容值'
- value = (U64Value >> 21) & 0x07
- blastCapValue = self.paramValue2Str(value, paramDict[key])
- if blastCapValue == None:
- blastCapValue = '未知({0})'.format(value)
- infos[key] = blastCapValue
- key = '起爆电容耐压'
- value = (U64Value >> 24) & 0x07
- blastCapVoltage = self.paramValue2Str(value, paramDict[key])
- if blastCapVoltage == None:
- blastCapVoltage = '未知({0})'.format(value)
- infos[key] = blastCapVoltage
- key = '引火件形式'
- value = (U64Value >> 27) & 0x07
- bridgeType = self.paramValue2Str(value, paramDict[key])
- if bridgeType == None:
- bridgeType = '未知({0})'.format(value)
- infos[key] = bridgeType
- key = '桥丝规格'
- value = (U64Value >> 30) & 0x1F
- bridgeValue = self.paramValue2Str(value, paramDict[key])
- if bridgeValue == None:
- bridgeValue = '未知({0})'.format(value)
- infos[key] = bridgeValue
- infos['PCB版本流水号'] = str((U64Value >> 35) & 0x7F).zfill(2)
- key = '脚线焊接方式'
- value = (U64Value >> 42) & 0x0F
- lineType = self.paramValue2Str(value, paramDict[key])
- if lineType == None:
- lineType = '未知({0})'.format(value)
- infos[key] = lineType
- return True, infos
- def showVersionForNewRule(self, hexStr):
- result, infos = self.getVersionInfosForNewRule(hexStr)
- if not result:
- QMessageBox.critical(self, '错误', '{0}'.format(infos))
- return
- contents = []
- key = '延期模块版本代码'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '芯片主版本'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '芯片次版本'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '数字电容品牌'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '数字电容容值'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '起爆电容品牌'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '起爆电容容值'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '电容耐压'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '引火件形式'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = '桥丝规格'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = 'PCB供应商'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- key = 'PCB版本流水号'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '脚线焊接方式'
- contents.append("{0}:{1}".format(key, infos[key]))
- key = '发料日期'
- contents.append("\n{0}:{1}".format(key, infos[key]))
- QMessageBox.information(self, '信息', '\n'.join(contents))
- def getVersionInfosForNewRule(self, versionHexStr):
- if not versionHexStr or len(versionHexStr) != 16:
- return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
- try:
- verBytes = bytearray.fromhex(versionHexStr)
- except Exception as e:
- return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
- crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
- if crc8 != verBytes[-1]:
- return False, '{0}\n校验值错误'.format(versionHexStr)
- U64Value = 0
- U64Value |= verBytes[6]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[5]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[4]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[3]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[2]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[1]&0xFF
- U64Value <<= 8
- U64Value |= verBytes[0]&0xFF
- infos = {}
- infos['延期模块版本代码'] = versionHexStr
- paramDict = self.getParamDict(True)
- key = '芯片主版本'#芯片主版本号共4位,bit0-3
- value = U64Value & 0x0F
- chipVer_1 = self.paramValue2Str(value, paramDict[key])
- if chipVer_1 == None:
- chipVer_1 = '未知({0})'.format(value)
- infos[key] = chipVer_1
- key = '芯片次版本'#芯片次版本号共4位,bit4-7
- value = (U64Value >> 4) & 0x0F
- chipVer_2 = self.paramValue2Str(value, paramDict[key])
- if chipVer_2 == None:
- chipVer_2 = '未知({0})'.format(value)
- infos[key] = chipVer_2
- key = '数字电容品牌'#数字电容品牌共5位 ,bit8-12
- value = (U64Value >> 8) & 0x1F
- workCapVender = self.paramValue2Str(value, paramDict[key])
- if workCapVender == None:
- workCapVender = '未知({0})'.format(value)
- infos[key] = workCapVender
- key = '数字电容容值'#数字电容容量共4位 ,bit13-16
- value = (U64Value >> 13) & 0x0F
- workCapValue = self.paramValue2Str(value, paramDict[key])
- if workCapValue == None:
- workCapValue = '未知({0})'.format(value)
- infos[key] = workCapValue
- key = '起爆电容品牌'#起爆电容品牌共3位 ,bit17-19
- value = (U64Value >> 17) & 0x07
- blastVender = self.paramValue2Str(value, paramDict[key])
- if blastVender == None:
- blastVender = '未知({0})'.format(value)
- infos[key] = blastVender
- key = '起爆电容容值'#起爆电容容量共3位 ,bit20-22
- value = (U64Value >> 20) & 0x07
- blastCapValue = self.paramValue2Str(value, paramDict[key])
- if blastCapValue == None:
- blastCapValue = '未知({0})'.format(value)
- infos[key] = blastCapValue
- key = '电容耐压'#电容耐压共3位 ,bit23-25
- value = (U64Value >> 23) & 0x07
- blastCapVoltage = self.paramValue2Str(value, paramDict[key])
- if blastCapVoltage == None:
- blastCapVoltage = '未知({0})'.format(value)
- infos[key] = blastCapVoltage
- key = '引火件形式'#引火件形式共3位 ,bit26-28
- value = (U64Value >> 26) & 0x07
- bridgeType = self.paramValue2Str(value, paramDict[key])
- if bridgeType == None:
- bridgeType = '未知({0})'.format(value)
- infos[key] = bridgeType
- key = '桥丝规格'#桥丝规格共5位 ,bit29-33
- value = (U64Value >> 29) & 0x1F
- bridgeValue = self.paramValue2Str(value, paramDict[key])
- if bridgeValue == None:
- bridgeValue = '未知({0})'.format(value)
- infos[key] = bridgeValue
- infos['PCB版本流水号'] = str((U64Value >> 34) & 0x1F).zfill(2)#PCB版本流水号共5位 ,bit34-38
- key = 'PCB供应商'# PCB供应商共2位 ,bit39-40
- value = (U64Value >> 39) & 0x03
- bridgeValue = self.paramValue2Str(value, paramDict[key])
- if bridgeValue == None:
- bridgeValue = '未知({0})'.format(value)
- infos[key] = bridgeValue
- key = '脚线焊接方式'#脚线焊接方式共3位 ,bit41-43
- value = (U64Value >> 41) & 0x07
- lineType = self.paramValue2Str(value, paramDict[key])
- if lineType == None:
- lineType = '未知({0})'.format(value)
- infos[key] = lineType
- # 发料日期中的年月共7位 ,bit44-50
- # 发料日期中的日共5位 ,bit51-55
- yearAndMonth = (U64Value >> 44) & 0x7F
- yaer = yearAndMonth//12
- month = 1+ (yearAndMonth%12)
- day = (U64Value >> 51) & 0x1F
- infos['发料日期'] = "%04d年%d月%d日"%(2020+yaer, month, day)
- return True, infos
- def closeEvent(self, QCloseEvent):
- if self.closeToDlg != None:
- self.closeToDlg.show()
- if __name__ == '__main__':
- import sys
- app = QApplication(sys.argv)
- ui = VersionSet()
- ui.show()
- sys.exit(app.exec_())
|