VersionSet.py 26 KB

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