diff --git a/Static/DP.png b/Static/DP.png new file mode 100644 index 0000000..d0a2744 Binary files /dev/null and b/Static/DP.png differ diff --git a/Static/Main.qss b/Static/Main.qss index 91ed45d..a1be309 100644 --- a/Static/Main.qss +++ b/Static/Main.qss @@ -419,6 +419,16 @@ QTabWidget#areaTabWidget{ } +QLabel#proTypeLabel{ + + font-size: 23px; + + font: bold; + + border: none; + +} + QLabel#batteryLabel{ @@ -491,6 +501,25 @@ QRadioButton#valueRadio{ } +QRadioButton#proTypeRadioBtn{ + + font-size: 25px; + +} + +QRadioButton#proTypeRadioBtn::indicator:enabled:checked{ + + image: url(Static/DP.png); + +} + +QRadioButton#proTypeRadioBtn::indicator:enabled:unchecked{ + + image: url(Static/PA.png); + +} + + QRadioButton#valueRadio::indicator:enabled:checked{ diff --git a/Static/PA.png b/Static/PA.png new file mode 100644 index 0000000..454e54e Binary files /dev/null and b/Static/PA.png differ diff --git a/Static/PA块信息全表.xlsx b/Static/PA块信息全表.xlsx deleted file mode 100644 index 1429c2e..0000000 Binary files a/Static/PA块信息全表.xlsx and /dev/null differ diff --git a/Static/PA块信息表.xlsx b/Static/PA块信息表.xlsx index b95ae32..1429c2e 100644 Binary files a/Static/PA块信息表.xlsx and b/Static/PA块信息表.xlsx differ diff --git a/Static/PA块信息表1.xlsx b/Static/PA块信息表1.xlsx new file mode 100644 index 0000000..13920e0 Binary files /dev/null and b/Static/PA块信息表1.xlsx differ diff --git a/UI/BlockParameterManageWidget.py b/UI/BlockParameterManageWidget.py index d30e9a7..67b4cea 100644 --- a/UI/BlockParameterManageWidget.py +++ b/UI/BlockParameterManageWidget.py @@ -1,9 +1,9 @@ import re import qtawesome -from PyQt5.QtGui import QPixmap, QPainter +from PyQt5.QtGui import QPixmap, QPainter, QIcon from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QStyledItemDelegate, QStyle, QComboBox, QMessageBox, QPushButton,QStackedWidget, QLineEdit \ -, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSplitter, QButtonGroup, QDialog +, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSplitter, QButtonGroup, QDialog, QRadioButton from utils.DBModels.DeviceParModels import * from UI.BlockParameterView import ParmView from UI.SearchAddressWidget import SearchAddressWidget @@ -42,6 +42,7 @@ class HideTextDelegate(QStyledItemDelegate): class TbCombox(QComboBox): def __init__(self): super().__init__() + # self.tbType = tbType self.initUI() def initUI(self): @@ -70,11 +71,12 @@ class TbCombox(QComboBox): class DynamicAddBlock(QHBoxLayout): - def __init__(self, blocklist): + def __init__(self, blocklist, TbtypeList): super().__init__() self.blocklist = blocklist self.buttonlist = [] self.blockViewlist = [] + self.tbtypeList = TbtypeList #存放转换块的各种类型 self.tbList = ['PressureTranslationBlock', 'TemperatureTranslationBlock', 'LevelTranslationBlock', 'FlowTranslationBlock'] #存放四个转换块 self.enumList = [TBType.pressureTB, TBType.tempTB, TBType.levelTB, TBType.flowTB] self.initUI() @@ -114,13 +116,27 @@ class DynamicAddBlock(QHBoxLayout): aiFunctionBlockView = ParmView(AIFunctionBlock, i, BlockType.FB) self.blockViewlist.append(aiFunctionBlockView) - for i in range(tbNumber): + for i, tbType in zip(range(tbNumber), self.tbtypeList): tbwidget = QWidget() tbwidget.setObjectName('tbwidget') tblayout = QHBoxLayout() tbwidget.setLayout(tblayout) tbcombox = TbCombox() + match tbType: + case TBType.pressureTB: + tbcombox.setCurrentIndex(0) + tblockBtn = QPushButton(tbcombox.currentText() + str(i + 1)) + case TBType.tempTB: + tbcombox.setCurrentIndex(1) + tblockBtn = QPushButton(tbcombox.currentText() + str(i + 1)) + case TBType.levelTB: + 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)) tblockBtn.setObjectName("tbparameBtn") @@ -188,12 +204,22 @@ class BlockParameterManageWidget(QWidget): def __init__(self): super().__init__() self.initUI() + self._isPa = True self.initUIstat = True def initUI(self): self.mainlayout = QVBoxLayout() + self.proTypeLabel = QLabel('PA协议') + self.proTypeLabel.setAlignment(Qt.AlignVCenter | Qt.AlignRight) + self.proTypeLabel.setObjectName('proTypeLabel') + + self.proTypeRadioBtn = QRadioButton() + self.proTypeRadioBtn.setObjectName('proTypeRadioBtn') + self.proTypeRadioBtn.toggled.connect(self.changeProType) + + self.settingLayout = QHBoxLayout() self.deviceAddressLabel = QLabel('从站地址') self.deviceAddressLabel.setObjectName('deviceAddressLabel') @@ -221,6 +247,8 @@ class BlockParameterManageWidget(QWidget): self.editAddressBtn.clicked.connect(self.editAddress) self.editAddressBtn.setObjectName("parameBtn") + self.settingLayout.addWidget(self.proTypeLabel, 1) + self.settingLayout.addWidget(self.proTypeRadioBtn, 1) self.settingLayout.addWidget(self.deviceAddressLabel, 1) self.settingLayout.addWidget(self.deviceAddressEdit, 1) self.settingLayout.addWidget(self.confirmBtn, 1) @@ -228,6 +256,7 @@ class BlockParameterManageWidget(QWidget): self.settingLayout.addWidget(self.editAddressBtn, 1) self.settingLayout.addWidget(self.refershDataBtn, 1) # self.settingLayout.addLayout(self.blockLayout) + # self.settingLayout.setSpacing(5) self.splitter = QSplitter() self.settingLayout.addWidget(self.splitter, 18) @@ -252,7 +281,9 @@ class BlockParameterManageWidget(QWidget): return if self.initUIstat: try: - self.blockManage = BlockManage(int(address)) + + self.blockManage = BlockManage(self._isPa, int(address)) + except Exception as e: reply = QMessageBox.question(self.parent(), '警告', @@ -264,7 +295,7 @@ class BlockParameterManageWidget(QWidget): self.splitter = QSplitter() Globals.setValue('blockManage', self.blockManage) blocklist = self.blockManage.getBlockNums() - self.blockLayout = DynamicAddBlock(blocklist) + self.blockLayout = DynamicAddBlock(blocklist, self.blockManage.TBTypeList) self.settingLayout.addLayout(self.blockLayout, 7) self.settingLayout.addWidget(self.splitter, 11) self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20) @@ -283,7 +314,8 @@ class BlockParameterManageWidget(QWidget): self.splitter.deleteLater() self.splitter = QSplitter() blocklist = self.blockManage.getBlockNums() - self.blockLayout = DynamicAddBlock(blocklist) + TbtypeList = self.blockManage.TBTypeList + self.blockLayout = DynamicAddBlock(blocklist, TbtypeList) self.settingLayout.addLayout(self.blockLayout, 7) self.settingLayout.addWidget(self.splitter, 11) self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20) @@ -316,12 +348,12 @@ class BlockParameterManageWidget(QWidget): def editAddress(self): - # if self.initUIstat: - # reply = QMessageBox.question(self.parent(), - # '警告', - # "请先连接设备", - # QMessageBox.Yes) - # return + if self.initUIstat: + reply = QMessageBox.question(self.parent(), + '警告', + "请先连接设备", + QMessageBox.Yes) + return oldAddress = int(self.blockManage.address) @@ -329,7 +361,14 @@ class BlockParameterManageWidget(QWidget): if self.editAddressWidget.exec_() == QDialog.Accepted: newAddress = int(self.editAddressWidget.editAddressEdit.text()) - self.blockManage.DPV1Master.editDevAddress(oldAddress, newAddress) + + result =self.blockManage.DPV1Master.editDevAddress(oldAddress, newAddress) + + reply = QMessageBox.question(self.parent(), + '提示', + result, + QMessageBox.Yes) + return @@ -338,5 +377,27 @@ class BlockParameterManageWidget(QWidget): self.searchAddressWidget = SearchAddressWidget(self.deviceAddressEdit) self.searchAddressWidget.show() - + + def changeProType(self): + if self.proTypeRadioBtn.isChecked(): + self.proTypeLabel.setText('DP协议') + self._isPa = False + + else: + self.proTypeLabel.setText('PA协议') + self._isPa = True + + self.clearLayout() + + def clearLayout(self): + if self.initUIstat: + return + else: + self.blockLayout.deleteLater() + self.splitter.deleteLater() + self.splitter = QSplitter() + self.widget = ShowImage('Static/pict.png') + self.mainlayout.addWidget(self.widget, 20) + self.settingLayout.addWidget(self.splitter,18) + self.initUIstat = True \ No newline at end of file diff --git a/UI/BlockParameterModel.py b/UI/BlockParameterModel.py index cc7610f..30789bb 100644 --- a/UI/BlockParameterModel.py +++ b/UI/BlockParameterModel.py @@ -250,6 +250,7 @@ class VarButtonDelegate(QItemDelegate): else: values = objectTypeEditlayout.getEditlineValue() + dataType = model.datas[sender.index[0]][4] if not values: reply = QMessageBox.question(self.parent(), @@ -267,7 +268,7 @@ class VarButtonDelegate(QItemDelegate): "请输入强制值或数字", QMessageBox.Yes) return - + print(values,555) res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values) self.refreshData() diff --git a/UI/ObjectTypeEditlayout.py b/UI/ObjectTypeEditlayout.py index 0876d7f..54d59fd 100644 --- a/UI/ObjectTypeEditlayout.py +++ b/UI/ObjectTypeEditlayout.py @@ -27,7 +27,7 @@ class ObjectTypeEditlayout(QVBoxLayout): self.addWidget(self.editline2) self.editlineList.extend([self.editline1, self.editline2]) - if self.dataType == 'DS-36': + elif self.dataType == 'DS-36': # layout1 = QHBoxLayout() # layout2 = QHBoxLayout() self.editline1.setPlaceholderText('EU_at_lOO %') @@ -42,7 +42,7 @@ class ObjectTypeEditlayout(QVBoxLayout): self.addWidget(self.editline4) self.editlineList.extend([self.editline1, self.editline2, self.editline3, self.editline4]) - if self.dataType == 'DS-50': + elif self.dataType == 'DS-50': self.editline1.setPlaceholderText('仿真转换块值状况') self.editline2.setPlaceholderText('仿真转换块值') self.editline3.setPlaceholderText('启用或者禁用仿真转换块(0:禁用, <>0:启用)') @@ -52,7 +52,7 @@ class ObjectTypeEditlayout(QVBoxLayout): self.addWidget(self.editline3) self.editlineList.extend([self.editline1, self.editline2, self.editline3]) - if self.dataType == '101': + elif self.dataType == '101': self.editline1.setPlaceholderText('请输入值') self.editline2.setPlaceholderText('请输入状态码') self.addWidget(self.editline1) @@ -68,6 +68,7 @@ class ObjectTypeEditlayout(QVBoxLayout): def getEditlineValue(self): valueList = [] + print(self.editlineList,6777) for editline in self.editlineList: value = editline.text() valueList.append(value) diff --git a/model/ProjectModel/BlockManage.py b/model/ProjectModel/BlockManage.py index 75a8cd4..1184913 100644 --- a/model/ProjectModel/BlockManage.py +++ b/model/ProjectModel/BlockManage.py @@ -42,26 +42,36 @@ class TBType(Enum): class BlockManage(): _instance = None - _dpv1Master = None + _dpv1MasterPA = None + _dpv1MasterDP = None + - def __new__(cls, address): - if not cls._instance: - cls._instance = super().__new__(cls) - return cls._instance + # def __new__(cls, address): + # if not cls._instance: + # cls._instance = super().__new__(cls) + # return cls._instance - def __init__(self, address = None): + def __init__(self, _isPa, address = None): + print(_isPa) + self._isPa = _isPa self.address = address + self.TBTypeList = [] if address: # pass self.initBlocks() @property def DPV1Master(self): - if not self._dpv1Master: - self._dpv1Master = DPV1Master('192.168.3.10', 502) - return self._dpv1Master + if not self._dpv1MasterPA or not self._dpv1MasterDP: + self._dpv1MasterPA = DPV1Master('192.168.3.10', 502) + self._dpv1MasterDP = DPV1Master('192.168.1.10', 502) + if self._isPa: + return self._dpv1MasterPA + else: + return self._dpv1MasterDP def initBlocks(self): + print(self._isPa,5555) if not self.DPV1Master.judgeSlave(self.address): raise RuntimeError(f"连接从站{self.address}失败.") self.blockDict = { @@ -69,6 +79,7 @@ class BlockManage(): BlockType.TB : [], BlockType.FB : [], } + self.TBTypeList = [] dirHeadDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 0, length = 12) dirHeadDatas = struct.unpack('>6h', dirHeadDatas) DirID = dirHeadDatas[0] # 目录id @@ -110,8 +121,9 @@ class BlockManage(): block.blockIndex = i block.address = self.address block.addParms() - if not block.getTBType(): - self.blockDict[typ].append(block) + if typ == BlockType.TB: + self.TBTypeList.append(block.getTBType()) + self.blockDict[typ].append(block) # print(blkSlot, blkIndex) # print(self.blockDict) @@ -127,6 +139,7 @@ class BlockManage(): def writeParmValue(self, blockType, blockIndex, parmIndex, values): block = self.resetBlockType(blockType, blockIndex) parm = block.parms[int(parmIndex)] + # print(values) result = parm.writeParm(values) return result @@ -144,6 +157,8 @@ class BlockManage(): # return [1,1,1] return [len(self.blockDict[BlockType.PB]), len(self.blockDict[BlockType.TB]), len(self.blockDict[BlockType.FB])] + # def getTBTypes(self): + @classmethod def searchSlave(self, callback): self.DPV1Master.searchSlave(callback) @@ -197,7 +212,19 @@ class Block(): return def getTBType(self): - return + value = self.parms[list(self.parms.keys())[0]].readValue() + match value: + case 1: + return TBType.pressureTB + case 2: + return TBType.tempTB + case 3: + return TBType.flowTB + case 4: + return TBType.levelTB + + + def getParmIndex(self, blockType, paramName): match blockType: diff --git a/model/ProjectModel/ParmManage.py b/model/ProjectModel/ParmManage.py index 9f6e507..fc43a1b 100644 --- a/model/ProjectModel/ParmManage.py +++ b/model/ProjectModel/ParmManage.py @@ -37,7 +37,8 @@ class Parm(): return self.unpackValue(value) def writeParm(self, values): - valueByte = self.packValue(*values) + print(*values) + valueByte = self.packValue(values) result = self.DPV1Master.writeParm(address = self.address, slot = self.slot, index = self.realIndex, length = self.size, valueByte = valueByte) def unpackValue(self, value): @@ -72,25 +73,25 @@ class Parm(): def packValue(self, values): match self.dataType: case 'Unsigned8': - return self.packU8(values) + return self.packU8(values[0]) case 'Unsigned16': - return self.packU16(values) + return self.packU16(values[0]) case 'Unsigned32': - return self.packU32(values) + return self.packU32(values[0]) case 'Float': - return self.packFloat(values) + return self.packFloat(values[0]) case '101': - return self.pack101(values) + return self.pack101(*values) case 'DS-32': - return self.packDS32(values) + return self.packDS32(*values) case 'DS-36': - return self.packDS36(values) + return self.packDS36(*values) case 'DS-50': - return self.packDS50(values) + return self.packDS50(*values) case 'OctetString' | 'VisibleString': - return self.packStr(values) + return self.packStr(values[0]) case 'FloatList2': - return self.packFloatList2(values) + return self.packFloatList2(*values) case _: return @@ -111,7 +112,7 @@ class Parm(): # print(value,2222) # print(struct.unpack('{}s'.format(str(len(value))), value)[0]) try: - return value.decode('ASCII') + return value.decode('ASCII', errors = 'ignore') except Exception as e: print(e) @@ -119,7 +120,7 @@ class Parm(): valueByte, statusByte = value[:4], value[4].to_bytes(1, byteorder='little') value = self.unpackFloat(valueByte) status = self.unpackU8(statusByte) - displayStr = '值:{} 状态:{}'.format(value, status) + displayStr = '值:{}\r\n状态:{}'.format(value, status) return displayStr def unpackDS32(self, value): @@ -136,11 +137,13 @@ class Parm(): numberOfParameters = self.unpackU16(value[15:17]) addressOfView1 = self.unpackU16(value[17:19]) numberOfViews = self.unpackU8(value[19:20]) - return '' + # print(clas, parentClass) + return parentClass def unpackDS36(self, value): - EU100Byte, EU0Byte, unitByte, decPointByte = value[:4], value[4:], value[8:10], value[10].to_bytes(1, byteorder='little') + print(len(value)) + EU100Byte, EU0Byte, unitByte, decPointByte = value[:4], value[4:8], value[8:10], value[10].to_bytes(1, byteorder='little') EU100 = self.unpackFloat(EU100Byte) EU0 = self.unpackFloat(EU0Byte) decPoint = self.unpackU8(decPointByte)