main
zcwBit 1 year ago
parent 79915c5b37
commit c738ed85e4

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -419,6 +419,16 @@ QTabWidget#areaTabWidget{
} }
QLabel#proTypeLabel{
font-size: 23px;
font: bold;
border: none;
}
QLabel#batteryLabel{ 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{ QRadioButton#valueRadio::indicator:enabled:checked{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,9 +1,9 @@
import re import re
import qtawesome import qtawesome
from PyQt5.QtGui import QPixmap, QPainter from PyQt5.QtGui import QPixmap, QPainter, QIcon
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QStyledItemDelegate, QStyle, QComboBox, QMessageBox, QPushButton,QStackedWidget, QLineEdit \ 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 utils.DBModels.DeviceParModels import *
from UI.BlockParameterView import ParmView from UI.BlockParameterView import ParmView
from UI.SearchAddressWidget import SearchAddressWidget from UI.SearchAddressWidget import SearchAddressWidget
@ -42,6 +42,7 @@ class HideTextDelegate(QStyledItemDelegate):
class TbCombox(QComboBox): class TbCombox(QComboBox):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# self.tbType = tbType
self.initUI() self.initUI()
def initUI(self): def initUI(self):
@ -70,11 +71,12 @@ class TbCombox(QComboBox):
class DynamicAddBlock(QHBoxLayout): class DynamicAddBlock(QHBoxLayout):
def __init__(self, blocklist): def __init__(self, blocklist, TbtypeList):
super().__init__() super().__init__()
self.blocklist = blocklist self.blocklist = blocklist
self.buttonlist = [] self.buttonlist = []
self.blockViewlist = [] self.blockViewlist = []
self.tbtypeList = TbtypeList #存放转换块的各种类型
self.tbList = ['PressureTranslationBlock', 'TemperatureTranslationBlock', 'LevelTranslationBlock', 'FlowTranslationBlock'] #存放四个转换块 self.tbList = ['PressureTranslationBlock', 'TemperatureTranslationBlock', 'LevelTranslationBlock', 'FlowTranslationBlock'] #存放四个转换块
self.enumList = [TBType.pressureTB, TBType.tempTB, TBType.levelTB, TBType.flowTB] self.enumList = [TBType.pressureTB, TBType.tempTB, TBType.levelTB, TBType.flowTB]
self.initUI() self.initUI()
@ -114,13 +116,27 @@ class DynamicAddBlock(QHBoxLayout):
aiFunctionBlockView = ParmView(AIFunctionBlock, i, BlockType.FB) aiFunctionBlockView = ParmView(AIFunctionBlock, i, BlockType.FB)
self.blockViewlist.append(aiFunctionBlockView) self.blockViewlist.append(aiFunctionBlockView)
for i in range(tbNumber): for i, tbType in zip(range(tbNumber), self.tbtypeList):
tbwidget = QWidget() tbwidget = QWidget()
tbwidget.setObjectName('tbwidget') tbwidget.setObjectName('tbwidget')
tblayout = QHBoxLayout() tblayout = QHBoxLayout()
tbwidget.setLayout(tblayout) tbwidget.setLayout(tblayout)
tbcombox = TbCombox() 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) tbcombox.setCurrentIndex(0)
tblockBtn = QPushButton('压力转换块' + str(i + 1)) tblockBtn = QPushButton('压力转换块' + str(i + 1))
tblockBtn.setObjectName("tbparameBtn") tblockBtn.setObjectName("tbparameBtn")
@ -188,12 +204,22 @@ class BlockParameterManageWidget(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.initUI() self.initUI()
self._isPa = True
self.initUIstat = True self.initUIstat = True
def initUI(self): def initUI(self):
self.mainlayout = QVBoxLayout() 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.settingLayout = QHBoxLayout()
self.deviceAddressLabel = QLabel('从站地址') self.deviceAddressLabel = QLabel('从站地址')
self.deviceAddressLabel.setObjectName('deviceAddressLabel') self.deviceAddressLabel.setObjectName('deviceAddressLabel')
@ -221,6 +247,8 @@ class BlockParameterManageWidget(QWidget):
self.editAddressBtn.clicked.connect(self.editAddress) self.editAddressBtn.clicked.connect(self.editAddress)
self.editAddressBtn.setObjectName("parameBtn") 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.deviceAddressLabel, 1)
self.settingLayout.addWidget(self.deviceAddressEdit, 1) self.settingLayout.addWidget(self.deviceAddressEdit, 1)
self.settingLayout.addWidget(self.confirmBtn, 1) self.settingLayout.addWidget(self.confirmBtn, 1)
@ -228,6 +256,7 @@ class BlockParameterManageWidget(QWidget):
self.settingLayout.addWidget(self.editAddressBtn, 1) self.settingLayout.addWidget(self.editAddressBtn, 1)
self.settingLayout.addWidget(self.refershDataBtn, 1) self.settingLayout.addWidget(self.refershDataBtn, 1)
# self.settingLayout.addLayout(self.blockLayout) # self.settingLayout.addLayout(self.blockLayout)
# self.settingLayout.setSpacing(5)
self.splitter = QSplitter() self.splitter = QSplitter()
self.settingLayout.addWidget(self.splitter, 18) self.settingLayout.addWidget(self.splitter, 18)
@ -252,7 +281,9 @@ class BlockParameterManageWidget(QWidget):
return return
if self.initUIstat: if self.initUIstat:
try: try:
self.blockManage = BlockManage(int(address))
self.blockManage = BlockManage(self._isPa, int(address))
except Exception as e: except Exception as e:
reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
'警告', '警告',
@ -264,7 +295,7 @@ class BlockParameterManageWidget(QWidget):
self.splitter = QSplitter() self.splitter = QSplitter()
Globals.setValue('blockManage', self.blockManage) Globals.setValue('blockManage', self.blockManage)
blocklist = self.blockManage.getBlockNums() blocklist = self.blockManage.getBlockNums()
self.blockLayout = DynamicAddBlock(blocklist) self.blockLayout = DynamicAddBlock(blocklist, self.blockManage.TBTypeList)
self.settingLayout.addLayout(self.blockLayout, 7) self.settingLayout.addLayout(self.blockLayout, 7)
self.settingLayout.addWidget(self.splitter, 11) self.settingLayout.addWidget(self.splitter, 11)
self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20) self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20)
@ -283,7 +314,8 @@ class BlockParameterManageWidget(QWidget):
self.splitter.deleteLater() self.splitter.deleteLater()
self.splitter = QSplitter() self.splitter = QSplitter()
blocklist = self.blockManage.getBlockNums() 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.addLayout(self.blockLayout, 7)
self.settingLayout.addWidget(self.splitter, 11) self.settingLayout.addWidget(self.splitter, 11)
self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20) self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20)
@ -316,12 +348,12 @@ class BlockParameterManageWidget(QWidget):
def editAddress(self): def editAddress(self):
# if self.initUIstat: if self.initUIstat:
# reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
# '警告', '警告',
# "请先连接设备", "请先连接设备",
# QMessageBox.Yes) QMessageBox.Yes)
# return return
oldAddress = int(self.blockManage.address) oldAddress = int(self.blockManage.address)
@ -329,7 +361,14 @@ class BlockParameterManageWidget(QWidget):
if self.editAddressWidget.exec_() == QDialog.Accepted: if self.editAddressWidget.exec_() == QDialog.Accepted:
newAddress = int(self.editAddressWidget.editAddressEdit.text()) 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
@ -339,4 +378,26 @@ class BlockParameterManageWidget(QWidget):
self.searchAddressWidget.show() 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

@ -250,6 +250,7 @@ class VarButtonDelegate(QItemDelegate):
else: else:
values = objectTypeEditlayout.getEditlineValue() values = objectTypeEditlayout.getEditlineValue()
dataType = model.datas[sender.index[0]][4] dataType = model.datas[sender.index[0]][4]
if not values: if not values:
reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
@ -267,7 +268,7 @@ class VarButtonDelegate(QItemDelegate):
"请输入强制值或数字", "请输入强制值或数字",
QMessageBox.Yes) QMessageBox.Yes)
return return
print(values,555)
res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values) res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values)
self.refreshData() self.refreshData()

@ -27,7 +27,7 @@ class ObjectTypeEditlayout(QVBoxLayout):
self.addWidget(self.editline2) self.addWidget(self.editline2)
self.editlineList.extend([self.editline1, self.editline2]) self.editlineList.extend([self.editline1, self.editline2])
if self.dataType == 'DS-36': elif self.dataType == 'DS-36':
# layout1 = QHBoxLayout() # layout1 = QHBoxLayout()
# layout2 = QHBoxLayout() # layout2 = QHBoxLayout()
self.editline1.setPlaceholderText('EU_at_lOO %') self.editline1.setPlaceholderText('EU_at_lOO %')
@ -42,7 +42,7 @@ class ObjectTypeEditlayout(QVBoxLayout):
self.addWidget(self.editline4) self.addWidget(self.editline4)
self.editlineList.extend([self.editline1, self.editline2, self.editline3, 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.editline1.setPlaceholderText('仿真转换块值状况')
self.editline2.setPlaceholderText('仿真转换块值') self.editline2.setPlaceholderText('仿真转换块值')
self.editline3.setPlaceholderText('启用或者禁用仿真转换块(0:禁用, <>0:启用)') self.editline3.setPlaceholderText('启用或者禁用仿真转换块(0:禁用, <>0:启用)')
@ -52,7 +52,7 @@ class ObjectTypeEditlayout(QVBoxLayout):
self.addWidget(self.editline3) self.addWidget(self.editline3)
self.editlineList.extend([self.editline1, self.editline2, self.editline3]) self.editlineList.extend([self.editline1, self.editline2, self.editline3])
if self.dataType == '101': elif self.dataType == '101':
self.editline1.setPlaceholderText('请输入值') self.editline1.setPlaceholderText('请输入值')
self.editline2.setPlaceholderText('请输入状态码') self.editline2.setPlaceholderText('请输入状态码')
self.addWidget(self.editline1) self.addWidget(self.editline1)
@ -68,6 +68,7 @@ class ObjectTypeEditlayout(QVBoxLayout):
def getEditlineValue(self): def getEditlineValue(self):
valueList = [] valueList = []
print(self.editlineList,6777)
for editline in self.editlineList: for editline in self.editlineList:
value = editline.text() value = editline.text()
valueList.append(value) valueList.append(value)

@ -42,26 +42,36 @@ class TBType(Enum):
class BlockManage(): class BlockManage():
_instance = None _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 __init__(self, address = None): # def __new__(cls, address):
# if not cls._instance:
# cls._instance = super().__new__(cls)
# return cls._instance
def __init__(self, _isPa, address = None):
print(_isPa)
self._isPa = _isPa
self.address = address self.address = address
self.TBTypeList = []
if address: if address:
# pass # pass
self.initBlocks() self.initBlocks()
@property @property
def DPV1Master(self): def DPV1Master(self):
if not self._dpv1Master: if not self._dpv1MasterPA or not self._dpv1MasterDP:
self._dpv1Master = DPV1Master('192.168.3.10', 502) self._dpv1MasterPA = DPV1Master('192.168.3.10', 502)
return self._dpv1Master self._dpv1MasterDP = DPV1Master('192.168.1.10', 502)
if self._isPa:
return self._dpv1MasterPA
else:
return self._dpv1MasterDP
def initBlocks(self): def initBlocks(self):
print(self._isPa,5555)
if not self.DPV1Master.judgeSlave(self.address): if not self.DPV1Master.judgeSlave(self.address):
raise RuntimeError(f"连接从站{self.address}失败.") raise RuntimeError(f"连接从站{self.address}失败.")
self.blockDict = { self.blockDict = {
@ -69,6 +79,7 @@ class BlockManage():
BlockType.TB : [], BlockType.TB : [],
BlockType.FB : [], BlockType.FB : [],
} }
self.TBTypeList = []
dirHeadDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 0, length = 12) dirHeadDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 0, length = 12)
dirHeadDatas = struct.unpack('>6h', dirHeadDatas) dirHeadDatas = struct.unpack('>6h', dirHeadDatas)
DirID = dirHeadDatas[0] # 目录id DirID = dirHeadDatas[0] # 目录id
@ -110,7 +121,8 @@ class BlockManage():
block.blockIndex = i block.blockIndex = i
block.address = self.address block.address = self.address
block.addParms() block.addParms()
if not block.getTBType(): if typ == BlockType.TB:
self.TBTypeList.append(block.getTBType())
self.blockDict[typ].append(block) self.blockDict[typ].append(block)
# print(blkSlot, blkIndex) # print(blkSlot, blkIndex)
# print(self.blockDict) # print(self.blockDict)
@ -127,6 +139,7 @@ class BlockManage():
def writeParmValue(self, blockType, blockIndex, parmIndex, values): def writeParmValue(self, blockType, blockIndex, parmIndex, values):
block = self.resetBlockType(blockType, blockIndex) block = self.resetBlockType(blockType, blockIndex)
parm = block.parms[int(parmIndex)] parm = block.parms[int(parmIndex)]
# print(values)
result = parm.writeParm(values) result = parm.writeParm(values)
return result return result
@ -144,6 +157,8 @@ class BlockManage():
# return [1,1,1] # return [1,1,1]
return [len(self.blockDict[BlockType.PB]), len(self.blockDict[BlockType.TB]), len(self.blockDict[BlockType.FB])] return [len(self.blockDict[BlockType.PB]), len(self.blockDict[BlockType.TB]), len(self.blockDict[BlockType.FB])]
# def getTBTypes(self):
@classmethod @classmethod
def searchSlave(self, callback): def searchSlave(self, callback):
self.DPV1Master.searchSlave(callback) self.DPV1Master.searchSlave(callback)
@ -197,7 +212,19 @@ class Block():
return return
def getTBType(self): 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): def getParmIndex(self, blockType, paramName):
match blockType: match blockType:

@ -37,7 +37,8 @@ class Parm():
return self.unpackValue(value) return self.unpackValue(value)
def writeParm(self, values): 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) result = self.DPV1Master.writeParm(address = self.address, slot = self.slot, index = self.realIndex, length = self.size, valueByte = valueByte)
def unpackValue(self, value): def unpackValue(self, value):
@ -72,25 +73,25 @@ class Parm():
def packValue(self, values): def packValue(self, values):
match self.dataType: match self.dataType:
case 'Unsigned8': case 'Unsigned8':
return self.packU8(values) return self.packU8(values[0])
case 'Unsigned16': case 'Unsigned16':
return self.packU16(values) return self.packU16(values[0])
case 'Unsigned32': case 'Unsigned32':
return self.packU32(values) return self.packU32(values[0])
case 'Float': case 'Float':
return self.packFloat(values) return self.packFloat(values[0])
case '101': case '101':
return self.pack101(values) return self.pack101(*values)
case 'DS-32': case 'DS-32':
return self.packDS32(values) return self.packDS32(*values)
case 'DS-36': case 'DS-36':
return self.packDS36(values) return self.packDS36(*values)
case 'DS-50': case 'DS-50':
return self.packDS50(values) return self.packDS50(*values)
case 'OctetString' | 'VisibleString': case 'OctetString' | 'VisibleString':
return self.packStr(values) return self.packStr(values[0])
case 'FloatList2': case 'FloatList2':
return self.packFloatList2(values) return self.packFloatList2(*values)
case _: case _:
return return
@ -111,7 +112,7 @@ class Parm():
# print(value,2222) # print(value,2222)
# print(struct.unpack('{}s'.format(str(len(value))), value)[0]) # print(struct.unpack('{}s'.format(str(len(value))), value)[0])
try: try:
return value.decode('ASCII') return value.decode('ASCII', errors = 'ignore')
except Exception as e: except Exception as e:
print(e) print(e)
@ -119,7 +120,7 @@ class Parm():
valueByte, statusByte = value[:4], value[4].to_bytes(1, byteorder='little') valueByte, statusByte = value[:4], value[4].to_bytes(1, byteorder='little')
value = self.unpackFloat(valueByte) value = self.unpackFloat(valueByte)
status = self.unpackU8(statusByte) status = self.unpackU8(statusByte)
displayStr = '值:{} 状态:{}'.format(value, status) displayStr = '值:{}\r\n状态:{}'.format(value, status)
return displayStr return displayStr
def unpackDS32(self, value): def unpackDS32(self, value):
@ -136,11 +137,13 @@ class Parm():
numberOfParameters = self.unpackU16(value[15:17]) numberOfParameters = self.unpackU16(value[15:17])
addressOfView1 = self.unpackU16(value[17:19]) addressOfView1 = self.unpackU16(value[17:19])
numberOfViews = self.unpackU8(value[19:20]) numberOfViews = self.unpackU8(value[19:20])
return '' # print(clas, parentClass)
return parentClass
def unpackDS36(self, value): 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) EU100 = self.unpackFloat(EU100Byte)
EU0 = self.unpackFloat(EU0Byte) EU0 = self.unpackFloat(EU0Byte)
decPoint = self.unpackU8(decPointByte) decPoint = self.unpackU8(decPointByte)

Loading…
Cancel
Save