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{
@ -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{

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 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
@ -339,4 +378,26 @@ class BlockParameterManageWidget(QWidget):
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:
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()

@ -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)

@ -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 __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.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,7 +121,8 @@ class BlockManage():
block.blockIndex = i
block.address = self.address
block.addParms()
if not block.getTBType():
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:

@ -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)

Loading…
Cancel
Save