VersionSet.py 25 KB

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