VersionSet.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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.5'
  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),('试验规格', 7), ('40um', 8),('28um', 9))#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. # print(bin((((productDate.year()-2020)*12 + (productDate.month()-1)) & 0x7F) << 44))
  282. # print(bin(U64Value))
  283. U64Value |= (productDate.day() & 0x1F) << 51 # 发料日期中的日共5位 ,bit51-55
  284. # print(bin((productDate.day() & 0x1F) << 51))
  285. # print(hex(U64Value))
  286. # print("aaaaa")
  287. # print(bin(U64Value))
  288. Bytes_0 = U64Value & 0xFF
  289. Bytes_1 = (U64Value >> 8) & 0xFF
  290. Bytes_2 = (U64Value >> 16) & 0xFF
  291. Bytes_3 = (U64Value >> 24) & 0xFF
  292. Bytes_4 = (U64Value >> 32) & 0xFF
  293. Bytes_5 = (U64Value >> 40) & 0xFF
  294. Bytes_6 = (U64Value >> 48) & 0xFF
  295. # print(Bytes_0,Bytes_1,Bytes_2)
  296. hexStr = '%02X%02X%02X%02X%02X%02X%02X' % (Bytes_0, Bytes_1, Bytes_2, Bytes_3, Bytes_4, Bytes_5, Bytes_6)
  297. # # 53861410004043
  298. # print(hexStr)
  299. # print(bytearray.fromhex(hexStr))
  300. # print(bin(CRC8.getCrc8(bytearray.fromhex(hexStr))))
  301. hexStr += '%02X' % ((~CRC8.getCrc8(bytearray.fromhex(hexStr))) & 0xFF)
  302. # print(hexStr)
  303. data = bytearray([0x01]) # 示例数据,转换为字节数组
  304. # print((CRC8.getCrc8(data)))
  305. return hexStr
  306. def updateStatus(self, param= None):
  307. status = True
  308. if self.ui.workCapValue.currentText() == "无电容":
  309. status = False
  310. self.ui.workCapVender.setEnabled(status)
  311. status = True
  312. if self.ui.blastCapValue.currentText() == "无电容":
  313. status = False
  314. self.ui.blastCapVender.setEnabled(status)
  315. self.ui.versionCode.setText(self.getCurrentParam())
  316. #
  317. # versionCodeChange = self.ui.versionCode.text()
  318. # self.versioncode = versionCodeChange
  319. self.set_fileName_Default()
  320. def showVersion(self, hexStr):
  321. if len(hexStr) == 16 and hexStr[12:14] == "00":
  322. self.showVersionForOldRule(hexStr)
  323. else:
  324. self.showVersionForNewRule(hexStr)
  325. def showVersionForOldRule(self, hexStr):
  326. result, infos = self.getVersionInfosForOldRule(hexStr)
  327. if not result:
  328. QMessageBox.critical(self, '错误', '{0}'.format(infos))
  329. return
  330. contents = []
  331. key = '延期模块版本代码'
  332. contents.append("{0}:{1}".format(key, infos[key]))
  333. key = '芯片主版本'
  334. contents.append("\n{0}:{1}".format(key, infos[key]))
  335. key = '芯片次版本'
  336. contents.append("{0}:{1}".format(key, infos[key]))
  337. key = '数字电容品牌'
  338. contents.append("\n{0}:{1}".format(key, infos[key]))
  339. key = '数字电容容值'
  340. contents.append("{0}:{1}".format(key, infos[key]))
  341. key = '数字电容耐压'
  342. contents.append("{0}:{1}".format(key, infos[key]))
  343. key = '起爆电容品牌'
  344. contents.append("\n{0}:{1}".format(key, infos[key]))
  345. key = '起爆电容容值'
  346. contents.append("{0}:{1}".format(key, infos[key]))
  347. key = '起爆电容耐压'
  348. contents.append("{0}:{1}".format(key, infos[key]))
  349. key = '引火件形式'
  350. contents.append("\n{0}:{1}".format(key, infos[key]))
  351. key = '桥丝规格'
  352. contents.append("{0}:{1}".format(key, infos[key]))
  353. key = 'PCB版本流水号'
  354. contents.append("\n{0}:{1}".format(key, infos[key]))
  355. key = '脚线焊接方式'
  356. contents.append("{0}:{1}".format(key, infos[key]))
  357. QMessageBox.information(self, '信息(旧规则)', '\n'.join(contents))
  358. def getVersionInfosForOldRule(self, versionHexStr):
  359. if not versionHexStr or len(versionHexStr) != 16:
  360. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  361. try:
  362. verBytes = bytearray.fromhex(versionHexStr)
  363. except Exception as e:
  364. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  365. crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
  366. if crc8 != verBytes[-1]:
  367. return False, '{0}\n校验值错误'.format(versionHexStr)
  368. U64Value = 0
  369. U64Value |= verBytes[6]&0xFF
  370. U64Value <<= 8
  371. U64Value |= verBytes[5]&0xFF
  372. U64Value <<= 8
  373. U64Value |= verBytes[4]&0xFF
  374. U64Value <<= 8
  375. U64Value |= verBytes[3]&0xFF
  376. U64Value <<= 8
  377. U64Value |= verBytes[2]&0xFF
  378. U64Value <<= 8
  379. U64Value |= verBytes[1]&0xFF
  380. U64Value <<= 8
  381. U64Value |= verBytes[0]&0xFF
  382. paramDict = self.getParamDict(False)
  383. infos = {}
  384. infos['延期模块版本代码'] = versionHexStr
  385. key = '芯片主版本'
  386. value = U64Value & 0x0F
  387. chipVer_1 = self.paramValue2Str(value, paramDict[key])
  388. if chipVer_1 == None:
  389. chipVer_1 = '未知({0})'.format(value)
  390. infos[key] = chipVer_1
  391. key = '芯片次版本'
  392. value = (U64Value >> 4) & 0x0F
  393. chipVer_2 = self.paramValue2Str(value, paramDict[key])
  394. if chipVer_2 == None:
  395. chipVer_2 = '未知({0})'.format(value)
  396. infos[key] = chipVer_2
  397. key = '数字电容品牌'
  398. value = (((U64Value >> 46) & 0x03)<<3) + ((U64Value >> 8) & 0x07)#2022年9月28日由3位扩展到5位
  399. workCapVender = self.paramValue2Str(value, paramDict[key])
  400. if workCapVender == None:
  401. workCapVender = '未知({0})'.format(value)
  402. infos[key] = workCapVender
  403. key = '数字电容容值'
  404. value = (U64Value >> 11) & 0x0F
  405. workCapValue = self.paramValue2Str(value, paramDict[key])
  406. if workCapValue == None:
  407. workCapValue = '未知({0})'.format(value)
  408. infos[key] = workCapValue
  409. key = '数字电容耐压'
  410. value = (U64Value >> 15) & 0x07
  411. workCapVoltage = self.paramValue2Str(value, paramDict[key])
  412. if workCapVoltage == None:
  413. workCapVoltage = '未知({0})'.format(value)
  414. infos[key] = workCapVoltage
  415. key = '起爆电容品牌'
  416. value = (U64Value >> 18) & 0x07
  417. blastVender = self.paramValue2Str(value, paramDict[key])
  418. if blastVender == None:
  419. blastVender = '未知({0})'.format(value)
  420. infos[key] = blastVender
  421. key = '起爆电容容值'
  422. value = (U64Value >> 21) & 0x07
  423. blastCapValue = self.paramValue2Str(value, paramDict[key])
  424. if blastCapValue == None:
  425. blastCapValue = '未知({0})'.format(value)
  426. infos[key] = blastCapValue
  427. key = '起爆电容耐压'
  428. value = (U64Value >> 24) & 0x07
  429. blastCapVoltage = self.paramValue2Str(value, paramDict[key])
  430. if blastCapVoltage == None:
  431. blastCapVoltage = '未知({0})'.format(value)
  432. infos[key] = blastCapVoltage
  433. key = '引火件形式'
  434. value = (U64Value >> 27) & 0x07
  435. bridgeType = self.paramValue2Str(value, paramDict[key])
  436. if bridgeType == None:
  437. bridgeType = '未知({0})'.format(value)
  438. infos[key] = bridgeType
  439. key = '桥丝规格'
  440. value = (U64Value >> 30) & 0x1F
  441. bridgeValue = self.paramValue2Str(value, paramDict[key])
  442. if bridgeValue == None:
  443. bridgeValue = '未知({0})'.format(value)
  444. infos[key] = bridgeValue
  445. infos['PCB版本流水号'] = str((U64Value >> 35) & 0x7F).zfill(2)
  446. key = '脚线焊接方式'
  447. value = (U64Value >> 42) & 0x0F
  448. lineType = self.paramValue2Str(value, paramDict[key])
  449. if lineType == None:
  450. lineType = '未知({0})'.format(value)
  451. infos[key] = lineType
  452. return True, infos
  453. def showVersionForNewRule(self, hexStr):
  454. result, infos = self.getVersionInfosForNewRule(hexStr)
  455. if not result:
  456. QMessageBox.critical(self, '错误', '{0}'.format(infos))
  457. return
  458. contents = []
  459. key = '延期模块版本代码'
  460. contents.append("{0}:{1}".format(key, infos[key]))
  461. key = '芯片主版本'
  462. contents.append("\n{0}:{1}".format(key, infos[key]))
  463. key = '芯片次版本'
  464. contents.append("{0}:{1}".format(key, infos[key]))
  465. key = '数字电容品牌'
  466. contents.append("\n{0}:{1}".format(key, infos[key]))
  467. key = '数字电容容值'
  468. contents.append("{0}:{1}".format(key, infos[key]))
  469. key = '起爆电容品牌'
  470. contents.append("\n{0}:{1}".format(key, infos[key]))
  471. key = '起爆电容容值'
  472. contents.append("{0}:{1}".format(key, infos[key]))
  473. key = '电容耐压'
  474. contents.append("\n{0}:{1}".format(key, infos[key]))
  475. key = '引火件形式'
  476. contents.append("\n{0}:{1}".format(key, infos[key]))
  477. key = '桥丝规格'
  478. contents.append("{0}:{1}".format(key, infos[key]))
  479. key = 'PCB供应商'
  480. contents.append("\n{0}:{1}".format(key, infos[key]))
  481. key = 'PCB版本流水号'
  482. contents.append("{0}:{1}".format(key, infos[key]))
  483. key = '脚线焊接方式'
  484. contents.append("{0}:{1}".format(key, infos[key]))
  485. key = '发料日期'
  486. contents.append("\n{0}:{1}".format(key, infos[key]))
  487. QMessageBox.information(self, '信息', '\n'.join(contents))
  488. def getVersionInfosForNewRule(self, versionHexStr):
  489. if not versionHexStr or len(versionHexStr) != 16:
  490. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  491. try:
  492. verBytes = bytearray.fromhex(versionHexStr)
  493. except Exception as e:
  494. return False, '{0}\n请输入16位16进制数'.format(versionHexStr)
  495. crc8 = (~CRC8.getCrc8(verBytes[:-1])) & 0xFF
  496. if crc8 != verBytes[-1]:
  497. return False, '{0}\n校验值错误'.format(versionHexStr)
  498. U64Value = 0
  499. U64Value |= verBytes[6]&0xFF
  500. U64Value <<= 8
  501. U64Value |= verBytes[5]&0xFF
  502. U64Value <<= 8
  503. U64Value |= verBytes[4]&0xFF
  504. U64Value <<= 8
  505. U64Value |= verBytes[3]&0xFF
  506. U64Value <<= 8
  507. U64Value |= verBytes[2]&0xFF
  508. U64Value <<= 8
  509. U64Value |= verBytes[1]&0xFF
  510. U64Value <<= 8
  511. U64Value |= verBytes[0]&0xFF
  512. infos = {}
  513. infos['延期模块版本代码'] = versionHexStr
  514. paramDict = self.getParamDict(True)
  515. key = '芯片主版本'#芯片主版本号共4位,bit0-3
  516. value = U64Value & 0x0F
  517. chipVer_1 = self.paramValue2Str(value, paramDict[key])
  518. if chipVer_1 == None:
  519. chipVer_1 = '未知({0})'.format(value)
  520. infos[key] = chipVer_1
  521. key = '芯片次版本'#芯片次版本号共4位,bit4-7
  522. value = (U64Value >> 4) & 0x0F
  523. chipVer_2 = self.paramValue2Str(value, paramDict[key])
  524. if chipVer_2 == None:
  525. chipVer_2 = '未知({0})'.format(value)
  526. infos[key] = chipVer_2
  527. key = '数字电容品牌'#数字电容品牌共5位 ,bit8-12
  528. value = (U64Value >> 8) & 0x1F
  529. workCapVender = self.paramValue2Str(value, paramDict[key])
  530. if workCapVender == None:
  531. workCapVender = '未知({0})'.format(value)
  532. infos[key] = workCapVender
  533. key = '数字电容容值'#数字电容容量共4位 ,bit13-16
  534. value = (U64Value >> 13) & 0x0F
  535. workCapValue = self.paramValue2Str(value, paramDict[key])
  536. if workCapValue == None:
  537. workCapValue = '未知({0})'.format(value)
  538. infos[key] = workCapValue
  539. key = '起爆电容品牌'#起爆电容品牌共3位 ,bit17-19
  540. value = (U64Value >> 17) & 0x07
  541. blastVender = self.paramValue2Str(value, paramDict[key])
  542. if blastVender == None:
  543. blastVender = '未知({0})'.format(value)
  544. infos[key] = blastVender
  545. key = '起爆电容容值'#起爆电容容量共3位 ,bit20-22
  546. value = (U64Value >> 20) & 0x07
  547. blastCapValue = self.paramValue2Str(value, paramDict[key])
  548. if blastCapValue == None:
  549. blastCapValue = '未知({0})'.format(value)
  550. infos[key] = blastCapValue
  551. key = '电容耐压'#电容耐压共3位 ,bit23-25
  552. value = (U64Value >> 23) & 0x07
  553. blastCapVoltage = self.paramValue2Str(value, paramDict[key])
  554. if blastCapVoltage == None:
  555. blastCapVoltage = '未知({0})'.format(value)
  556. infos[key] = blastCapVoltage
  557. key = '引火件形式'#引火件形式共3位 ,bit26-28
  558. value = (U64Value >> 26) & 0x07
  559. bridgeType = self.paramValue2Str(value, paramDict[key])
  560. if bridgeType == None:
  561. bridgeType = '未知({0})'.format(value)
  562. infos[key] = bridgeType
  563. key = '桥丝规格'#桥丝规格共5位 ,bit29-33
  564. value = (U64Value >> 29) & 0x1F
  565. bridgeValue = self.paramValue2Str(value, paramDict[key])
  566. if bridgeValue == None:
  567. bridgeValue = '未知({0})'.format(value)
  568. infos[key] = bridgeValue
  569. infos['PCB版本流水号'] = str((U64Value >> 34) & 0x1F).zfill(2)#PCB版本流水号共5位 ,bit34-38
  570. key = 'PCB供应商'# PCB供应商共2位 ,bit39-40
  571. value = (U64Value >> 39) & 0x03
  572. bridgeValue = self.paramValue2Str(value, paramDict[key])
  573. if bridgeValue == None:
  574. bridgeValue = '未知({0})'.format(value)
  575. infos[key] = bridgeValue
  576. key = '脚线焊接方式'#脚线焊接方式共3位 ,bit41-43
  577. value = (U64Value >> 41) & 0x07
  578. lineType = self.paramValue2Str(value, paramDict[key])
  579. if lineType == None:
  580. lineType = '未知({0})'.format(value)
  581. infos[key] = lineType
  582. # 发料日期中的年月共7位 ,bit44-50
  583. # 发料日期中的日共5位 ,bit51-55
  584. yearAndMonth = (U64Value >> 44) & 0x7F
  585. yaer = yearAndMonth//12
  586. month = 1+ (yearAndMonth%12)
  587. day = (U64Value >> 51) & 0x1F
  588. infos['发料日期'] = "%04d年%d月%d日"%(2020+yaer, month, day)
  589. return True, infos
  590. def closeEvent(self, QCloseEvent):
  591. if self.closeToDlg != None:
  592. self.closeToDlg.show()
  593. if __name__ == '__main__':
  594. import sys
  595. app = QApplication(sys.argv)
  596. ui = VersionSet()
  597. ui.show()
  598. sys.exit(app.exec_())