VersionSet.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. import os
  2. import qrcode
  3. from PIL.ImageQt import ImageQt
  4. from PyQt5.QtCore import *
  5. from PyQt5.QtCore import Qt
  6. from PyQt5.QtGui import *
  7. from PyQt5.QtWidgets import *
  8. import CRC8
  9. from Config import Configuration
  10. from ui.VersionSet import Ui_Form
  11. softwareIconPath = r'D:\PycharmProjects\Scan\ScanUtils\pic\scan.png'
  12. # softwareIconPath = r':pic/scan.png'
  13. folderName = 'material'
  14. VERSION = '2.7'
  15. class VersionSet(QWidget):
  16. #自定义信号
  17. mySignal = pyqtSignal(str)
  18. def __init__(self, parent = None, closeToDlg = None):
  19. '''构造函数'''
  20. super(VersionSet, self).__init__(parent)
  21. self.ui = Ui_Form()
  22. self.ui.setupUi(self)
  23. self.setWindowIcon(QIcon(softwareIconPath))
  24. self.setWindowTitle('生产物料扫码记录V{0}'.format(VERSION))
  25. self.setWindowFlags(self.windowFlags() | Qt.CustomizeWindowHint)#QtCore.Qt.WindowStaysOnTopHint顶层显示
  26. #禁用最小化
  27. # self.setWindowFlags(self.windowFlags() & ~Qt.WindowMinimizeButtonHint)
  28. #禁用最大化
  29. # self.setWindowFlags(self.windowFlags() & ~Qt.WindowMaximizeButtonHint)
  30. #禁止拉伸窗口大小
  31. # self.setFixedSize(self.width(), self.height())
  32. self.closeToDlg = closeToDlg
  33. self.widgetInit()
  34. # 设置参数
  35. def getParamDict(self, newRule = True):
  36. paramDict = {}
  37. if newRule:#新规则2023年4月20日
  38. paramDict['芯片主版本'] = (('HX01', 1), ('HX02', 2), ('HX03', 3), ('HX05', 4), ('HX10', 5))#4位
  39. paramDict['芯片次版本'] = (('第1版(A)', 1), ('第2版(B)', 2), ('第3版(C)', 3), ('第4版(D)', 4), ('第5版(E)', 5), ('第6版(F)', 6))#4位
  40. paramDict['数字电容容值'] = (('无电容', 0), ('1uF', 1), ('4.7uF', 2), ('10uF', 3), ('22uF', 4), ('33uF', 5), ('47uF', 6), ('68uF', 7), ('100uF', 8))#4位
  41. # 2022年9月28日由3位扩展到5位
  42. paramDict['数字电容品牌'] = (('试验品牌', 0), ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('火炬', 4), ('湘江', 5), ('振华', 6), ('丰华', 7), ('国巨', 8), ('三星', 9))
  43. paramDict['电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2))#3位
  44. paramDict['起爆电容容值'] = (('无电容', 0), ('33uF', 1), ('47uF', 2), ('68uF', 3), ('100uF', 4), ('220uF', 5),('120uF', 6))#3位
  45. paramDict['起爆电容品牌'] = (('试验品牌', 0), ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('永铭', 4), ('丰宾', 5), ('米朗', 6))#3位
  46. paramDict['引火件形式'] = (('无', 0), ('焊接刚性药头', 1), ('贴片刚性药头', 2), ('贴片发热电阻', 3), ('碗状电阻器', 4))#3位
  47. 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位
  48. paramDict['脚线焊接方式'] = (('无孔焊接', 0), ('有孔焊接', 1), ('铭威铆接', 2), ('创德铆接', 3))#4位
  49. paramDict['PCB供应商'] = (('丰达兴', 0), ('欧拓', 1), ('镓锐', 2), ('联宇宏', 3))
  50. else:#旧规则
  51. paramDict['芯片主版本'] = (('HX02', 2), ('HX03', 3)) # 4位
  52. paramDict['芯片次版本'] = (('第1版(A)', 1), ('第2版(B)', 2), ('第3版(C)', 3), ('第4版(D)', 4), ('第5版(E)', 5)) # 4位
  53. paramDict['数字电容容值'] = (
  54. ('无电容', 0), ('1uF', 1), ('4.7uF', 2), ('10uF', 3), ('22uF', 4), ('33uF', 5), ('47uF', 6), ('68uF', 7),
  55. ('100uF', 8)) # 4位
  56. # 2022年9月28日由3位扩展到5位
  57. paramDict['数字电容品牌'] = (
  58. ('AVX', 1), ('Vishay', 2), ('Sunlord', 3), ('火炬', 4), ('湘江', 5), ('振华', 6), ('丰华', 7), ('国巨', 8))
  59. paramDict['数字电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2)) # 3位
  60. paramDict['起爆电容容值'] = (('无电容', 0), ('33uF', 1), ('47uF', 2), ('68uF', 3), ('100uF', 4)) # 3位
  61. paramDict['起爆电容品牌'] = (('AVX', 1), ('Vishay', 2), ('Sunlord', 3)) # 3位
  62. paramDict['起爆电容耐压'] = (('16V', 0), ('20V', 1), ('25V', 2)) # 3位
  63. paramDict['引火件形式'] = (('无', 0), ('焊接刚性药头', 1), ('贴片刚性药头', 2), ('贴片发热电阻', 3), ('碗状电阻器', 4)) # 3位
  64. paramDict['桥丝规格'] = (('16um(7.9~8.6欧)', 0), ('2欧姆', 1)) # 5位
  65. paramDict['脚线焊接方式'] = (('焊接(有孔)', 1), ('铆接', 2), ('焊接(无孔)', 3)) # 4位
  66. return paramDict
  67. # 初始化:
  68. def widgetInit(self):
  69. paramDict = self.getParamDict(True)
  70. for item in paramDict['芯片主版本']:
  71. self.ui.chipVer_1.addItem(item[0])
  72. for item in paramDict['芯片次版本']:
  73. self.ui.chipVer_2.addItem(item[0])
  74. for item in paramDict['数字电容容值']:
  75. self.ui.workCapValue.addItem(item[0])
  76. for item in paramDict['数字电容品牌']:
  77. self.ui.workCapVender.addItem(item[0])
  78. for item in paramDict['起爆电容容值']:
  79. self.ui.blastCapValue.addItem(item[0])
  80. for item in paramDict['起爆电容品牌']:
  81. self.ui.blastCapVender.addItem(item[0])
  82. for item in paramDict['电容耐压']:
  83. self.ui.capVoltage.addItem(item[0])
  84. for item in paramDict['引火件形式']:
  85. self.ui.bridgeType.addItem(item[0])
  86. for item in paramDict['桥丝规格']:
  87. self.ui.bridgeValue.addItem(item[0])
  88. for item in paramDict['PCB供应商']:
  89. self.ui.pcbVender.addItem(item[0])
  90. for item in range(32):
  91. self.ui.pcbVer.addItem(str(item).zfill(2))#5位
  92. for item in paramDict['脚线焊接方式']:
  93. self.ui.lineType.addItem(item[0])
  94. self.setDefault()
  95. self.updateStatus()
  96. self.versionCode=''
  97. self.productDate=''
  98. self.setDirDefault()
  99. # 创建保存.txt的文件夹
  100. self.mkdirFile()
  101. self.set_fileName_Default()
  102. self.ui.chipVer_1.activated.connect(self.updateStatus)
  103. self.ui.chipVer_2.activated.connect(self.updateStatus)
  104. self.ui.workCapValue.activated.connect(self.updateStatus)
  105. self.ui.workCapVender.activated.connect(self.updateStatus)
  106. self.ui.blastCapValue.activated.connect(self.updateStatus)
  107. self.ui.blastCapVender.activated.connect(self.updateStatus)
  108. self.ui.capVoltage.activated.connect(self.updateStatus)
  109. self.ui.bridgeType.activated.connect(self.updateStatus)
  110. self.ui.bridgeValue.activated.connect(self.updateStatus)
  111. self.ui.pcbVender.activated.connect(self.updateStatus)
  112. self.ui.pcbVer.activated.connect(self.updateStatus)
  113. self.ui.lineType.activated.connect(self.updateStatus)
  114. self.ui.productDate.dateChanged.connect(self.updateStatus)
  115. # self.ui.copy.clicked.connect(self.copySolf)
  116. # self.ui.commit.clicked.connect(self.open_ScanInput)
  117. self.ui.commit.clicked.connect(self.open_ScanInput)
  118. self.ui.change_dir.clicked.connect(self.select_dir)
  119. self.ui.btnFileName.clicked.connect(self.get_text)
  120. # self.ui.read.clicked.connect(self.readSolf
  121. # self.ui.write.clicked.connect(self.writeSolf)
  122. # self.ui.analyst.clicked.connect(self.analystSolf).
  123. # 打开窗口
  124. def open_ScanInput(self,event):
  125. versionCode= self.ui.versionCode.text()
  126. productDate = self.ui.productDate.text()
  127. fileName = self.ui.file_name.text()
  128. # 默认路径名
  129. directory = self.ui.dir.text()
  130. file_path =directory + '/' + fileName
  131. from ScanInput import ScanInput
  132. if os.path.exists(file_path):
  133. msg_box = QMessageBox(QMessageBox.Question, "提示", "目标文件夹中存在已存在同名文件,是否需要重命名")
  134. msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
  135. # 将 Save 按钮的文本设置为中文
  136. save_button = msg_box.button(QMessageBox.Yes)
  137. save_button.setText("是")
  138. save_button = msg_box.button(QMessageBox.No)
  139. save_button.setText("否")
  140. # 执行
  141. choice = msg_box.exec_()
  142. if choice == QMessageBox.No:
  143. self.ScanInput_ui = ScanInput(versionCode, productDate, fileName, directory)
  144. self.ScanInput_ui.show()
  145. elif choice == QMessageBox.Yes:
  146. msg_box.done(choice)
  147. else:
  148. # 生成二维码
  149. self.saveCode()
  150. self.ScanInput_ui = ScanInput(versionCode, productDate, fileName, directory)
  151. self.ScanInput_ui.show()
  152. # 保存二维码
  153. def saveCode(self):
  154. versionCode= self.ui.versionCode.text()
  155. qr_code = self.generate_qr_code(versionCode)
  156. file_path_name = "/"+versionCode+".png"
  157. file_path =self.ui.dir.text() +file_path_name
  158. self.save_qr_code(qr_code, file_path)
  159. # 创建默认的文件夹
  160. def mkdirFile(self):
  161. desktopPath = Configuration().get_desktop()
  162. folderNamePath = desktopPath + '\\' + folderName
  163. if not os.path.exists(folderNamePath):
  164. os.mkdir(folderNamePath)
  165. else:
  166. return True
  167. # 更改目录
  168. def select_dir(self):
  169. filePathName = self.ui.dir.text()
  170. options = QFileDialog.Options()
  171. options |= QFileDialog.ShowDirsOnly
  172. # 获取返回在值
  173. directory = QFileDialog.getExistingDirectory(self, "选择目录",os.path.expanduser(filePathName), options=options)
  174. if not directory:
  175. self.ui.dir.setText(filePathName)
  176. else:
  177. self.ui.dir.setText(directory)
  178. # 默认地址
  179. def setDirDefault(self):
  180. desktopPath = Configuration().get_desktop()
  181. desktopPath = desktopPath.replace('\\','/')
  182. filePathName = desktopPath + '/' + folderName
  183. self.ui.dir.setText(filePathName)
  184. # 生成二维码
  185. def generate_qr_code(self,data: str) -> QPixmap:
  186. qr = qrcode.QRCode(version=1, box_size=10, border=4)
  187. qr.add_data(data)
  188. qr.make(fit=True)
  189. img = qr.make_image(fill_color="black", back_color="white")
  190. pixmap = QPixmap.fromImage(ImageQt(img))
  191. return pixmap
  192. # 保存二维码
  193. def save_qr_code(self,pixmap: QPixmap, file_path: str):
  194. pixmap.save(file_path)
  195. # 设置初始值
  196. def setDefault(self):
  197. self.ui.workCapValue.setCurrentIndex(4)#默认22uF
  198. self.ui.workCapVender.setCurrentIndex(6)#默认振华
  199. self.ui.blastCapValue.setCurrentIndex(1)#默认33uF
  200. self.ui.blastCapVender.setCurrentIndex(2)#默认Vishay
  201. self.ui.chipVer_1.setCurrentIndex(1)
  202. self.ui.chipVer_2.setCurrentIndex(4)
  203. self.ui.bridgeType.setCurrentIndex(4)
  204. self.ui.lineType.setCurrentIndex(0)
  205. self.ui.productDate.setDate(QDate.currentDate())
  206. # 设置文件名称初始值
  207. def set_fileName_Default(self):
  208. versionode= self.ui.versionCode.text()
  209. productDate = self.ui.productDate.text()
  210. fileName = versionode+'_'+productDate+'.txt'
  211. self.ui.file_name.setText(fileName)
  212. # 修改文件名称 并检查文件名称
  213. def get_text(self):
  214. # QInputDialog组件定义
  215. inputDialog = QInputDialog(self)
  216. # QInputDialog组件设置
  217. versionCode= self.ui.versionCode.text()
  218. productDate = self.ui.productDate.text()
  219. defaultFileName = versionCode+'_'+productDate
  220. FileNameLab = self.ui.file_name.text()
  221. FileNameLab = FileNameLab.replace(".txt","")
  222. # 方式二
  223. defaultFileLen = len(defaultFileName)
  224. text, ok = inputDialog.getText(self, '标题', '请输入文本:', text=FileNameLab) # 返回文本内容和按钮的点击项
  225. if ok:
  226. if text[:defaultFileLen] == defaultFileName:
  227. outputTxt = text + ".txt"
  228. self.ui.file_name.setText(outputTxt)
  229. inputDialog.reject()
  230. else:
  231. QMessageBox.information(self, "提示", f"请以{defaultFileName}作为开头的文件名") # 显示输入的文本信息
  232. self.get_text()
  233. def paramStr2Value(self, content, paramList):
  234. for item in paramList:
  235. if content == item[0]:
  236. return item[1]
  237. return None
  238. def paramValue2Str(self, value, paramList):
  239. for item in paramList:
  240. if value == item[1]:
  241. return item[0]
  242. return None
  243. # 版本号
  244. def getCurrentParam(self):
  245. paramDict = self.getParamDict(True)
  246. chipVer_1 = self.paramStr2Value(self.ui.chipVer_1.currentText(), paramDict['芯片主版本'])
  247. chipVer_2 = self.paramStr2Value(self.ui.chipVer_2.currentText(), paramDict['芯片次版本'])
  248. workCapVender = self.paramStr2Value(self.ui.workCapVender.currentText(), paramDict['数字电容品牌'])
  249. workCapValue = self.paramStr2Value(self.ui.workCapValue.currentText(), paramDict['数字电容容值'])
  250. blastCapVender = self.paramStr2Value(self.ui.blastCapVender.currentText(), paramDict['起爆电容品牌'])
  251. blastCapValue = self.paramStr2Value(self.ui.blastCapValue.currentText(), paramDict['起爆电容容值'])
  252. capVoltage = self.paramStr2Value(self.ui.capVoltage.currentText(), paramDict['电容耐压'])
  253. bridgeType = self.paramStr2Value(self.ui.bridgeType.currentText(), paramDict['引火件形式'])
  254. bridgeValue = self.paramStr2Value(self.ui.bridgeValue.currentText(), paramDict['桥丝规格'])
  255. pcbVender = self.paramStr2Value(self.ui.pcbVender.currentText(), paramDict['PCB供应商'])
  256. pcbVer = int(self.ui.pcbVer.currentText())
  257. lineType = self.paramStr2Value(self.ui.lineType.currentText(), paramDict['脚线焊接方式'])
  258. productDate = self.ui.productDate.date()#发料日期
  259. U64Value = chipVer_1 & 0x0F #芯片主版本号共4位,bit0-3
  260. U64Value |= (chipVer_2 & 0x0F) << 4#芯片次版本号共4位,bit4-7
  261. U64Value |= (workCapVender & 0x1F) << 8 #数字电容品牌共5位 ,bit8-12
  262. U64Value |= (workCapValue & 0x0F) << 13 #数字电容容量共4位 ,bit13-16
  263. U64Value |= (blastCapVender & 0x07) << 17 #起爆电容品牌共3位 ,bit17-19
  264. U64Value |= (blastCapValue & 0x07) << 20 #起爆电容容量共3位 ,bit20-22
  265. U64Value |= (capVoltage & 0x07) << 23 #电容耐压共3位 ,bit23-25
  266. U64Value |= (bridgeType & 0x07) << 26 #引火件形式共3位 ,bit26-28
  267. U64Value |= (bridgeValue & 0x1F) << 29 #桥丝规格共5位 ,bit29-33
  268. U64Value |= (pcbVer & 0x1F) << 34 #PCB版本流水号共5位 ,bit34-38
  269. U64Value |= (pcbVender & 0x03) << 39 #PCB供应商共2位 ,bit39-40
  270. U64Value |= (lineType & 0x07) << 41 #脚线焊接方式共3位 ,bit41-43
  271. U64Value |= (((productDate.year()-2020)*12 + (productDate.month()-1)) & 0x7F) << 44 # 发料日期中的年月共7位 ,bit44-50
  272. U64Value |= (productDate.day() & 0x1F) << 51 # 发料日期中的日共5位 ,bit51-55
  273. Bytes_0 = U64Value & 0xFF
  274. Bytes_1 = (U64Value >> 8) & 0xFF
  275. Bytes_2 = (U64Value >> 16) & 0xFF
  276. Bytes_3 = (U64Value >> 24) & 0xFF
  277. Bytes_4 = (U64Value >> 32) & 0xFF
  278. Bytes_5 = (U64Value >> 40) & 0xFF
  279. Bytes_6 = (U64Value >> 48) & 0xFF
  280. hexStr = '%02X%02X%02X%02X%02X%02X%02X' % (Bytes_0, Bytes_1, Bytes_2, Bytes_3, Bytes_4, Bytes_5, Bytes_6)
  281. hexStr += '%02X' % ((~CRC8.getCrc8(bytearray.fromhex(hexStr))) & 0xFF)
  282. data = bytearray([0x01]) # 示例数据,转换为字节数组
  283. # print((CRC8.getCrc8(data)))
  284. return hexStr
  285. def updateStatus(self, param= None):
  286. status = True
  287. if self.ui.workCapValue.currentText() == "无电容":
  288. status = False
  289. self.ui.workCapVender.setEnabled(status)
  290. status = True
  291. if self.ui.blastCapValue.currentText() == "无电容":
  292. status = False
  293. self.ui.blastCapVender.setEnabled(status)
  294. self.ui.versionCode.setText(self.getCurrentParam())
  295. self.set_fileName_Default()
  296. def showVersion(self, hexStr):
  297. if len(hexStr) == 16 and hexStr[12:14] == "00":
  298. self.showVersionForOldRule(hexStr)
  299. else:
  300. self.showVersionForNewRule(hexStr)
  301. def showVersionForOldRule(self, hexStr):
  302. result, infos = self.getVersionInfosForOldRule(hexStr)
  303. if not result:
  304. QMessageBox.critical(self, '错误', '{0}'.format(infos))
  305. return
  306. contents = []
  307. key = '延期模块版本代码'
  308. contents.append("{0}:{1}".format(key, infos[key]))
  309. key = '芯片主版本'
  310. contents.append("\n{0}:{1}".format(key, infos[key]))
  311. key = '芯片次版本'
  312. contents.append("{0}:{1}".format(key, infos[key]))
  313. key = '数字电容品牌'
  314. contents.append("\n{0}:{1}".format(key, infos[key]))
  315. key = '数字电容容值'
  316. contents.append("{0}:{1}".format(key, infos[key]))
  317. key = '数字电容耐压'
  318. contents.append("{0}:{1}".format(key, infos[key]))
  319. key = '起爆电容品牌'
  320. contents.append("\n{0}:{1}".format(key, infos[key]))
  321. key = '起爆电容容值'
  322. contents.append("{0}:{1}".format(key, infos[key]))
  323. key = '起爆电容耐压'
  324. contents.append("{0}:{1}".format(key, infos[key]))
  325. key = '引火件形式'
  326. contents.append("\n{0}:{1}".format(key, infos[key]))
  327. key = '桥丝规格'
  328. contents.append("{0}:{1}".format(key, infos[key]))
  329. key = 'PCB版本流水号'
  330. contents.append("\n{0}:{1}".format(key, infos[key]))
  331. key = '脚线焊接方式'
  332. contents.append("{0}:{1}".format(key, infos[key]))
  333. QMessageBox.information(self, '信息(旧规则)', '\n'.join(contents))
  334. def getVersionInfosForOldRule(self, versionHexStr):
  335. if not versionHexStr or len(versionHexStr) != 16:
  336. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  337. try:
  338. verBytes = bytearray.fromhex(versionHexStr)
  339. except Exception as e:
  340. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  341. crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
  342. if crc8 != verBytes[-1]:
  343. return False, '{0}\n校验值错误'.format(versionHexStr)
  344. U64Value = 0
  345. U64Value |= verBytes[6]&0xFF
  346. U64Value <<= 8
  347. U64Value |= verBytes[5]&0xFF
  348. U64Value <<= 8
  349. U64Value |= verBytes[4]&0xFF
  350. U64Value <<= 8
  351. U64Value |= verBytes[3]&0xFF
  352. U64Value <<= 8
  353. U64Value |= verBytes[2]&0xFF
  354. U64Value <<= 8
  355. U64Value |= verBytes[1]&0xFF
  356. U64Value <<= 8
  357. U64Value |= verBytes[0]&0xFF
  358. paramDict = self.getParamDict(False)
  359. infos = {}
  360. infos['延期模块版本代码'] = versionHexStr
  361. key = '芯片主版本'
  362. value = U64Value & 0x0F
  363. chipVer_1 = self.paramValue2Str(value, paramDict[key])
  364. if chipVer_1 == None:
  365. chipVer_1 = '未知({0})'.format(value)
  366. infos[key] = chipVer_1
  367. key = '芯片次版本'
  368. value = (U64Value >> 4) & 0x0F
  369. chipVer_2 = self.paramValue2Str(value, paramDict[key])
  370. if chipVer_2 == None:
  371. chipVer_2 = '未知({0})'.format(value)
  372. infos[key] = chipVer_2
  373. key = '数字电容品牌'
  374. value = (((U64Value >> 46) & 0x03)<<3) + ((U64Value >> 8) & 0x07)#2022年9月28日由3位扩展到5位
  375. workCapVender = self.paramValue2Str(value, paramDict[key])
  376. if workCapVender == None:
  377. workCapVender = '未知({0})'.format(value)
  378. infos[key] = workCapVender
  379. key = '数字电容容值'
  380. value = (U64Value >> 11) & 0x0F
  381. workCapValue = self.paramValue2Str(value, paramDict[key])
  382. if workCapValue == None:
  383. workCapValue = '未知({0})'.format(value)
  384. infos[key] = workCapValue
  385. key = '数字电容耐压'
  386. value = (U64Value >> 15) & 0x07
  387. workCapVoltage = self.paramValue2Str(value, paramDict[key])
  388. if workCapVoltage == None:
  389. workCapVoltage = '未知({0})'.format(value)
  390. infos[key] = workCapVoltage
  391. key = '起爆电容品牌'
  392. value = (U64Value >> 18) & 0x07
  393. blastVender = self.paramValue2Str(value, paramDict[key])
  394. if blastVender == None:
  395. blastVender = '未知({0})'.format(value)
  396. infos[key] = blastVender
  397. key = '起爆电容容值'
  398. value = (U64Value >> 21) & 0x07
  399. blastCapValue = self.paramValue2Str(value, paramDict[key])
  400. if blastCapValue == None:
  401. blastCapValue = '未知({0})'.format(value)
  402. infos[key] = blastCapValue
  403. key = '起爆电容耐压'
  404. value = (U64Value >> 24) & 0x07
  405. blastCapVoltage = self.paramValue2Str(value, paramDict[key])
  406. if blastCapVoltage == None:
  407. blastCapVoltage = '未知({0})'.format(value)
  408. infos[key] = blastCapVoltage
  409. key = '引火件形式'
  410. value = (U64Value >> 27) & 0x07
  411. bridgeType = self.paramValue2Str(value, paramDict[key])
  412. if bridgeType == None:
  413. bridgeType = '未知({0})'.format(value)
  414. infos[key] = bridgeType
  415. key = '桥丝规格'
  416. value = (U64Value >> 30) & 0x1F
  417. bridgeValue = self.paramValue2Str(value, paramDict[key])
  418. if bridgeValue == None:
  419. bridgeValue = '未知({0})'.format(value)
  420. infos[key] = bridgeValue
  421. infos['PCB版本流水号'] = str((U64Value >> 35) & 0x7F).zfill(2)
  422. key = '脚线焊接方式'
  423. value = (U64Value >> 42) & 0x0F
  424. lineType = self.paramValue2Str(value, paramDict[key])
  425. if lineType == None:
  426. lineType = '未知({0})'.format(value)
  427. infos[key] = lineType
  428. return True, infos
  429. def showVersionForNewRule(self, hexStr):
  430. result, infos = self.getVersionInfosForNewRule(hexStr)
  431. if not result:
  432. QMessageBox.critical(self, '错误', '{0}'.format(infos))
  433. return
  434. contents = []
  435. key = '延期模块版本代码'
  436. contents.append("{0}:{1}".format(key, infos[key]))
  437. key = '芯片主版本'
  438. contents.append("\n{0}:{1}".format(key, infos[key]))
  439. key = '芯片次版本'
  440. contents.append("{0}:{1}".format(key, infos[key]))
  441. key = '数字电容品牌'
  442. contents.append("\n{0}:{1}".format(key, infos[key]))
  443. key = '数字电容容值'
  444. contents.append("{0}:{1}".format(key, infos[key]))
  445. key = '起爆电容品牌'
  446. contents.append("\n{0}:{1}".format(key, infos[key]))
  447. key = '起爆电容容值'
  448. contents.append("{0}:{1}".format(key, infos[key]))
  449. key = '电容耐压'
  450. contents.append("\n{0}:{1}".format(key, infos[key]))
  451. key = '引火件形式'
  452. contents.append("\n{0}:{1}".format(key, infos[key]))
  453. key = '桥丝规格'
  454. contents.append("{0}:{1}".format(key, infos[key]))
  455. key = 'PCB供应商'
  456. contents.append("\n{0}:{1}".format(key, infos[key]))
  457. key = 'PCB版本流水号'
  458. contents.append("{0}:{1}".format(key, infos[key]))
  459. key = '脚线焊接方式'
  460. contents.append("{0}:{1}".format(key, infos[key]))
  461. key = '发料日期'
  462. contents.append("\n{0}:{1}".format(key, infos[key]))
  463. QMessageBox.information(self, '信息', '\n'.join(contents))
  464. def getVersionInfosForNewRule(self, versionHexStr):
  465. if not versionHexStr or len(versionHexStr) != 16:
  466. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  467. try:
  468. verBytes = bytearray.fromhex(versionHexStr)
  469. except Exception as e:
  470. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  471. crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
  472. if crc8 != verBytes[-1]:
  473. return False, '{0}\n校验值错误'.format(versionHexStr)
  474. U64Value = 0
  475. U64Value |= verBytes[6]&0xFF
  476. U64Value <<= 8
  477. U64Value |= verBytes[5]&0xFF
  478. U64Value <<= 8
  479. U64Value |= verBytes[4]&0xFF
  480. U64Value <<= 8
  481. U64Value |= verBytes[3]&0xFF
  482. U64Value <<= 8
  483. U64Value |= verBytes[2]&0xFF
  484. U64Value <<= 8
  485. U64Value |= verBytes[1]&0xFF
  486. U64Value <<= 8
  487. U64Value |= verBytes[0]&0xFF
  488. infos = {}
  489. infos['延期模块版本代码'] = versionHexStr
  490. paramDict = self.getParamDict(True)
  491. key = '芯片主版本'#芯片主版本号共4位,bit0-3
  492. value = U64Value & 0x0F
  493. chipVer_1 = self.paramValue2Str(value, paramDict[key])
  494. if chipVer_1 == None:
  495. chipVer_1 = '未知({0})'.format(value)
  496. infos[key] = chipVer_1
  497. key = '芯片次版本'#芯片次版本号共4位,bit4-7
  498. value = (U64Value >> 4) & 0x0F
  499. chipVer_2 = self.paramValue2Str(value, paramDict[key])
  500. if chipVer_2 == None:
  501. chipVer_2 = '未知({0})'.format(value)
  502. infos[key] = chipVer_2
  503. key = '数字电容品牌'#数字电容品牌共5位 ,bit8-12
  504. value = (U64Value >> 8) & 0x1F
  505. workCapVender = self.paramValue2Str(value, paramDict[key])
  506. if workCapVender == None:
  507. workCapVender = '未知({0})'.format(value)
  508. infos[key] = workCapVender
  509. key = '数字电容容值'#数字电容容量共4位 ,bit13-16
  510. value = (U64Value >> 13) & 0x0F
  511. workCapValue = self.paramValue2Str(value, paramDict[key])
  512. if workCapValue == None:
  513. workCapValue = '未知({0})'.format(value)
  514. infos[key] = workCapValue
  515. key = '起爆电容品牌'#起爆电容品牌共3位 ,bit17-19
  516. value = (U64Value >> 17) & 0x07
  517. blastVender = self.paramValue2Str(value, paramDict[key])
  518. if blastVender == None:
  519. blastVender = '未知({0})'.format(value)
  520. infos[key] = blastVender
  521. key = '起爆电容容值'#起爆电容容量共3位 ,bit20-22
  522. value = (U64Value >> 20) & 0x07
  523. blastCapValue = self.paramValue2Str(value, paramDict[key])
  524. if blastCapValue == None:
  525. blastCapValue = '未知({0})'.format(value)
  526. infos[key] = blastCapValue
  527. key = '电容耐压'#电容耐压共3位 ,bit23-25
  528. value = (U64Value >> 23) & 0x07
  529. blastCapVoltage = self.paramValue2Str(value, paramDict[key])
  530. if blastCapVoltage == None:
  531. blastCapVoltage = '未知({0})'.format(value)
  532. infos[key] = blastCapVoltage
  533. key = '引火件形式'#引火件形式共3位 ,bit26-28
  534. value = (U64Value >> 26) & 0x07
  535. bridgeType = self.paramValue2Str(value, paramDict[key])
  536. if bridgeType == None:
  537. bridgeType = '未知({0})'.format(value)
  538. infos[key] = bridgeType
  539. key = '桥丝规格'#桥丝规格共5位 ,bit29-33
  540. value = (U64Value >> 29) & 0x1F
  541. bridgeValue = self.paramValue2Str(value, paramDict[key])
  542. if bridgeValue == None:
  543. bridgeValue = '未知({0})'.format(value)
  544. infos[key] = bridgeValue
  545. infos['PCB版本流水号'] = str((U64Value >> 34) & 0x1F).zfill(2)#PCB版本流水号共5位 ,bit34-38
  546. key = 'PCB供应商'# PCB供应商共2位 ,bit39-40
  547. value = (U64Value >> 39) & 0x03
  548. bridgeValue = self.paramValue2Str(value, paramDict[key])
  549. if bridgeValue == None:
  550. bridgeValue = '未知({0})'.format(value)
  551. infos[key] = bridgeValue
  552. key = '脚线焊接方式'#脚线焊接方式共3位 ,bit41-43
  553. value = (U64Value >> 41) & 0x07
  554. lineType = self.paramValue2Str(value, paramDict[key])
  555. if lineType == None:
  556. lineType = '未知({0})'.format(value)
  557. infos[key] = lineType
  558. # 发料日期中的年月共7位 ,bit44-50
  559. # 发料日期中的日共5位 ,bit51-55
  560. yearAndMonth = (U64Value >> 44) & 0x7F
  561. yaer = yearAndMonth//12
  562. month = 1+ (yearAndMonth%12)
  563. day = (U64Value >> 51) & 0x1F
  564. infos['发料日期'] = "%04d年%d月%d日"%(2020+yaer, month, day)
  565. return True, infos
  566. def closeEvent(self, QCloseEvent):
  567. if self.closeToDlg != None:
  568. self.closeToDlg.show()
  569. if __name__ == '__main__':
  570. import sys
  571. app = QApplication(sys.argv)
  572. ui = VersionSet()
  573. ui.show()
  574. sys.exit(app.exec_())