diff --git a/Static/PA块信息表.xlsx b/Static/PA块信息表.xlsx index 1429c2e..fd3044b 100644 Binary files a/Static/PA块信息表.xlsx and b/Static/PA块信息表.xlsx differ diff --git a/UI/BlockParameterManageWidget.py b/UI/BlockParameterManageWidget.py index 67b4cea..abb7533 100644 --- a/UI/BlockParameterManageWidget.py +++ b/UI/BlockParameterManageWidget.py @@ -77,6 +77,7 @@ class DynamicAddBlock(QHBoxLayout): self.buttonlist = [] self.blockViewlist = [] self.tbtypeList = TbtypeList #存放转换块的各种类型 + # print(self.tbtypeList) self.tbList = ['PressureTranslationBlock', 'TemperatureTranslationBlock', 'LevelTranslationBlock', 'FlowTranslationBlock'] #存放四个转换块 self.enumList = [TBType.pressureTB, TBType.tempTB, TBType.levelTB, TBType.flowTB] self.initUI() @@ -123,6 +124,7 @@ class DynamicAddBlock(QHBoxLayout): tbwidget.setLayout(tblayout) tbcombox = TbCombox() + # print(tbType) match tbType: case TBType.pressureTB: tbcombox.setCurrentIndex(0) @@ -131,14 +133,15 @@ class DynamicAddBlock(QHBoxLayout): tbcombox.setCurrentIndex(1) tblockBtn = QPushButton(tbcombox.currentText() + str(i + 1)) case TBType.levelTB: + # print(2222) tbcombox.setCurrentIndex(2) tblockBtn = QPushButton(tbcombox.currentText() + str(i + 1)) case TBType.flowTB: tbcombox.setCurrentIndex(3) tblockBtn = QPushButton(tbcombox.currentText() + str(i + 1)) - tbcombox.setCurrentIndex(0) - tblockBtn = QPushButton('压力转换块' + str(i + 1)) + # tbcombox.setCurrentIndex(0) + # tblockBtn = QPushButton('压力转换块' + str(i + 1)) tblockBtn.setObjectName("tbparameBtn") # tblockBtn.setFixedSize(130, 43) tblockBtn.setCheckable(True) @@ -164,6 +167,7 @@ class DynamicAddBlock(QHBoxLayout): self.parameStackWidget = QStackedWidget() for view in self.blockViewlist: self.parameStackWidget.addWidget(view) + def switchParameterWidget(self, buttonType): for index , button in enumerate(self.buttonlist): @@ -173,10 +177,11 @@ class DynamicAddBlock(QHBoxLayout): def switchTbtype(self, index, combox, button): tbType = combox.itemText(index) - buttonNumber = button.text()[-1:] + buttonNumber = button.text()[-1] button.setText(tbType + str(buttonNumber)) if button.isChecked(): - stackIndex = (int(self.blocklist[0]) + int(self.blocklist[1]) + index) + (int(buttonNumber) - 1) * 4 + stackIndex = (int(self.blocklist[0]) + int(self.blocklist[2]) + index) + (int(buttonNumber) - 1) * 4 + self.parameStackWidget.setCurrentIndex(stackIndex) @@ -274,10 +279,10 @@ class BlockParameterManageWidget(QWidget): address = self.deviceAddressEdit.text() # print(address) if address: - pattern = re.compile(r'^(?:[1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-6])$') + pattern = re.compile(r'^(?:[1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-7])$') match = pattern.match(address) if not match: - QMessageBox.warning(self, '提示', '请输入2 - 126。') + QMessageBox.warning(self, '提示', '请输入2 - 127。') return if self.initUIstat: try: @@ -315,6 +320,7 @@ class BlockParameterManageWidget(QWidget): self.splitter = QSplitter() blocklist = self.blockManage.getBlockNums() TbtypeList = self.blockManage.TBTypeList + self.blockLayout = DynamicAddBlock(blocklist, TbtypeList) self.settingLayout.addLayout(self.blockLayout, 7) self.settingLayout.addWidget(self.splitter, 11) diff --git a/UI/MainWindow.py b/UI/MainWindow.py index 5c91515..229ca26 100644 --- a/UI/MainWindow.py +++ b/UI/MainWindow.py @@ -275,7 +275,7 @@ class MainWindow(QWidget): if self.switchBtn.isChecked(): if self.process: self.stackWidget.setCurrentIndex(1) - QTimer.singleShot(50, lambda:self.stackWidget.setCurrentIndex(2)) + QTimer.singleShot(50, lambda:self.stackWidget.setCurrentIndex(3)) else: self.stackWidget.setCurrentIndex(1) startupInfo = subprocess.STARTUPINFO() @@ -326,7 +326,7 @@ class MainWindow(QWidget): win32gui.SetParent(hwnd, int(self.winId())) - self.stackWidget.setCurrentIndex(2) + self.stackWidget.setCurrentIndex(3) def closeEvent(self, event): if self.process: diff --git a/model/ProjectModel/BlockManage.py b/model/ProjectModel/BlockManage.py index 1184913..530b994 100644 --- a/model/ProjectModel/BlockManage.py +++ b/model/ProjectModel/BlockManage.py @@ -71,7 +71,7 @@ class BlockManage(): return self._dpv1MasterDP def initBlocks(self): - print(self._isPa,5555) + # print(self._isPa,5555) if not self.DPV1Master.judgeSlave(self.address): raise RuntimeError(f"连接从站{self.address}失败.") self.blockDict = { @@ -94,12 +94,36 @@ class BlockManage(): NumCompListDirEntry = dirHeadDatas[5] # 功能块类型数量 复合列表目录登录项的个数 计数设备内的不同块类型(物理块、转换块和功能块)和对象类型 #(在本标准范围内仅针对链接对象) - dirLength = 4 * NumDirEntry + dirLength = 4 * NumCompListDirEntry dirDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 1, length = dirLength) dirDatas = struct.unpack('>{}h'.format(int(dirLength/2)), dirDatas) entryTuples = [(dirDatas[i], dirDatas[i+1]) for i in range(0, len(dirDatas), 2)] - + # print(entryTuples) + dirMesDic = {} + for dirMes in entryTuples: + blockIndex = struct.pack('>h', dirMes[0])[0] + blockNums = dirMes[1] + # print(blockIndex) + if blockIndex in dirMesDic: + dirMesDic[blockIndex] = dirMesDic[blockIndex] + blockNums + else: + dirMesDic[blockIndex] = blockNums + # print(dirMesDic) + entryTuples = [] + for key, value in dirMesDic.items(): + # print(key, value) + if key == 1: + data = self.DPV1Master.readParm(address = self.address, slot = 1, index = key, length = dirLength + 4 * value) + else: + data = self.DPV1Master.readParm(address = self.address, slot = 1, index = key, length = 4 * value) + # print(data, int(len(data)/2)) + print(data) + data = struct.unpack('>{}h'.format(int(len(data)/2)), data) + tuples = [(data[i], data[i+1]) for i in range(0, len(data), 2)] + entryTuples += tuples + # print(entryTuples) for typ in [BlockType.PB, BlockType.TB, BlockType.FB]: + # print(typ) typeIndex = typ.value if type(typ.value) == int else 1 blkDirMesByte = struct.pack('>h', entryTuples[typeIndex][0]) blkIndex = int(blkDirMesByte[0]) # 目录对象编号 @@ -121,11 +145,13 @@ class BlockManage(): block.blockIndex = i block.address = self.address block.addParms() + # print(block.startIndex, block.slot) if typ == BlockType.TB: self.TBTypeList.append(block.getTBType()) self.blockDict[typ].append(block) # print(blkSlot, blkIndex) # print(self.blockDict) + # print(self.TBTypeList) def getBlockValues(self, blockType, blockIndex, callback, callback2): block = self.resetBlockType(blockType, blockIndex) @@ -212,7 +238,8 @@ class Block(): return def getTBType(self): - value = self.parms[list(self.parms.keys())[0]].readValue() + value = int(self.parms[list(self.parms.keys())[0]].readValue()) + # print(value, type(value)) match value: case 1: return TBType.pressureTB diff --git a/protocol/ModBus/DPV1Master.py b/protocol/ModBus/DPV1Master.py index d1315ad..5ec1f28 100644 --- a/protocol/ModBus/DPV1Master.py +++ b/protocol/ModBus/DPV1Master.py @@ -75,15 +75,18 @@ class DPV1Master(): indexByte = index.to_bytes(1, byteorder='little') readByteStream = b'\x01' + hexAddress + slotByte + indexByte + b'\xF0\x00' readDate = struct.unpack('>hhh', readByteStream) - self.writeMultipleRegister(1, 750, self.resetData) + # self.writeMultipleRegister(1, 750, self.resetData) + # time.sleep(0.1) self.writeMultipleRegister(1, 750, readDate) - time.sleep(0.4) + time.sleep(1.1) value = self.readHoldingRegisters(1, 750, -(-length // 2)) # -(-length // 2)向上取整 + # print(value, 222) if value[0] == 57344: self.writeMultipleRegister(1, 750, self.resetData) time.sleep(0.1) return '读取错误' value = struct.pack('>{}H'.format(len(value)), *value)[:length] + # print(value) # print(address, slot, index) # print(value) self.writeMultipleRegister(1, 750, self.resetData) @@ -105,7 +108,7 @@ class DPV1Master(): # print(len(writeByteStream)) writeDate = struct.unpack('>{}h'.format(len(writeByteStream) // 2), writeByteStream) self.writeMultipleRegister(1, 750, writeDate) - time.sleep(0.3) + time.sleep(0.4) value = self.readHoldingRegisters(1, 750, 2) if value[0] == 57344: result = '写入错误' @@ -120,8 +123,10 @@ class DPV1Master(): searchByteStream = b'\x01' + hexAddress + b'\x01\x00\xF0\x00' searchDate = struct.unpack('>hhh', searchByteStream) self.writeMultipleRegister(1, 750, searchDate) - time.sleep(0.3) + time.sleep(1.1) dir = self.readHoldingRegisters(1, 750, 6) + time.sleep(0.1) + # print(dir) self.writeMultipleRegister(1, 750, self.resetData) time.sleep(0.1) if not self.areAllZeros(dir) and dir != 'error':