|
|
|
|
@ -4,6 +4,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QGridLay
|
|
|
|
|
QHBoxLayout, QMessageBox, QSplitter, QRadioButton
|
|
|
|
|
|
|
|
|
|
from UI.ProfibusWidgets.SoftKeyBoardEdit import SoftKeyBoardEdit
|
|
|
|
|
from utils import Globals
|
|
|
|
|
|
|
|
|
|
class ForceButton(QPushButton):
|
|
|
|
|
def __init__(self, number = None, valueLabel = None, valueEdit = None, qualityValueLabel = None, \
|
|
|
|
|
@ -31,6 +32,7 @@ class RightAreaWidgets(QWidget):
|
|
|
|
|
self.qualityLabel = {}
|
|
|
|
|
self.areaWidget = areaWidget
|
|
|
|
|
self.devicesManange = self.areaWidget.devicesManange
|
|
|
|
|
self.protocolManage = Globals.getValue('protocolManage')
|
|
|
|
|
self.order = order
|
|
|
|
|
self.byteLineEdit = byteLineEdit
|
|
|
|
|
self.dataType = dataType
|
|
|
|
|
@ -205,6 +207,45 @@ class RightAreaWidgets(QWidget):
|
|
|
|
|
def readValues(self, curIndex):
|
|
|
|
|
# print(curIndex)
|
|
|
|
|
if not self.force:
|
|
|
|
|
# 优先通过ProtocolManage读取(这样可以获取RPC同步的值)
|
|
|
|
|
if self.valueName and self.protocolManage:
|
|
|
|
|
try:
|
|
|
|
|
value = self.protocolManage.readVariableValue(self.valueName)
|
|
|
|
|
if value is not None:
|
|
|
|
|
# 处理从ProtocolManage获取的值
|
|
|
|
|
if isinstance(value, dict) and 'value' in value:
|
|
|
|
|
actualValue = value['value']
|
|
|
|
|
qualityValue = value.get('quality', '0x00')
|
|
|
|
|
else:
|
|
|
|
|
actualValue = value
|
|
|
|
|
qualityValue = '0x00'
|
|
|
|
|
|
|
|
|
|
# 更新UI显示
|
|
|
|
|
if self.dataType in ['AI', 'AO']:
|
|
|
|
|
# 模拟量显示
|
|
|
|
|
if 0 in self.areaLabel:
|
|
|
|
|
self.areaLabel[0].setText(str(actualValue))
|
|
|
|
|
if 0 in self.qualityLabel:
|
|
|
|
|
self.qualityLabel[0].setText(str(qualityValue))
|
|
|
|
|
else:
|
|
|
|
|
# 离散量显示
|
|
|
|
|
for index, label in self.areaLabel.items():
|
|
|
|
|
if isinstance(actualValue, list) and index < len(actualValue):
|
|
|
|
|
bitValue = actualValue[index]
|
|
|
|
|
if bitValue == 1:
|
|
|
|
|
label.setText('ON')
|
|
|
|
|
label.setChecked(True)
|
|
|
|
|
else:
|
|
|
|
|
label.setText('OFF')
|
|
|
|
|
label.setChecked(False)
|
|
|
|
|
else:
|
|
|
|
|
label.setText('OFF')
|
|
|
|
|
label.setChecked(False)
|
|
|
|
|
return
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"通过ProtocolManage读取变量 {self.valueName} 失败: {e}")
|
|
|
|
|
|
|
|
|
|
# 回退到直接从设备读取
|
|
|
|
|
device = self.devicesManange.getDevice(self.deviceName)
|
|
|
|
|
values, qualityValueList = device.getAreaValues(curIndex)
|
|
|
|
|
# print(qualityValueList)
|
|
|
|
|
@ -225,7 +266,7 @@ class RightAreaWidgets(QWidget):
|
|
|
|
|
self.areaLabel[index].setText(str(value))
|
|
|
|
|
for index, value in enumerate(qualityValueList):
|
|
|
|
|
self.qualityLabel[index].setText(str(value))
|
|
|
|
|
# print(self.areaLabel[index],values)
|
|
|
|
|
# print(self.areaLabel[index],values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -248,7 +289,20 @@ class RightAreaWidgets(QWidget):
|
|
|
|
|
if valueList is None:
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList, qualityValueList = qualityValueList)
|
|
|
|
|
# 通过ProtocolManage写入,以便触发RPC同步
|
|
|
|
|
if self.valueName and self.protocolManage:
|
|
|
|
|
# 构造写入值(包含质量值)
|
|
|
|
|
writeValue = {
|
|
|
|
|
'value': float(value),
|
|
|
|
|
'quality': qualityValue
|
|
|
|
|
}
|
|
|
|
|
success = self.protocolManage.writeVariableValue(self.valueName, writeValue)
|
|
|
|
|
if not success:
|
|
|
|
|
# 如果ProtocolManage写入失败,回退到直接写入
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList, qualityValueList = qualityValueList)
|
|
|
|
|
else:
|
|
|
|
|
# 如果没有变量名或ProtocolManage不可用,使用直接写入
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList, qualityValueList = qualityValueList)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def DIDOForceValues(self):
|
|
|
|
|
@ -261,7 +315,15 @@ class RightAreaWidgets(QWidget):
|
|
|
|
|
if valueList is None:
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList)
|
|
|
|
|
# 通过ProtocolManage写入,以便触发RPC同步
|
|
|
|
|
if self.valueName and self.protocolManage:
|
|
|
|
|
success = self.protocolManage.writeVariableValue(self.valueName, value)
|
|
|
|
|
if not success:
|
|
|
|
|
# 如果ProtocolManage写入失败,回退到直接写入
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList)
|
|
|
|
|
else:
|
|
|
|
|
# 如果没有变量名或ProtocolManage不可用,使用直接写入
|
|
|
|
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList)
|
|
|
|
|
if sender.isChecked():
|
|
|
|
|
sender.setText('ON')
|
|
|
|
|
else:
|
|
|
|
|
|