VersionSet.py 29 KB

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