main
zcwBit 1 year ago
parent 9dde7437bb
commit 7797fb03c6

@ -4,6 +4,20 @@ QComboBox#dataTypeCombox, QComboBox#orderCombox{
} }
QComboBox#modeCombox{
background-color: #f0f0f0;
border: none;
height: 43px;
font-size: 40px;
}
QComboBox#tbcombox{ QComboBox#tbcombox{
background-color: #f0f0f0; background-color: #f0f0f0;
@ -17,10 +31,30 @@ QComboBox#tbcombox{
border-radius: 5px; border-radius: 5px;
margin-left: -10px; margin-left: -10px;
font-size: 20px; font-size: 20px;
} }
QComboBox#modeCombox::drop-down{
image: url(Static/down.png);
subcontrol-origin: padding;
subcontrol-position: top right;
background-color: #f0f0f0;
width: 20px;
border:none;
border-radius: 5px;
}
QComboBox#tbcombox::drop-down{ QComboBox#tbcombox::drop-down{
image: url(Static/down.png); image: url(Static/down.png);
@ -308,7 +342,7 @@ QPushButton#tbparameBtn{
border: none; border: none;
width: 54.75px; width: 140.75px;
height: 40px; height: 40px;
@ -381,6 +415,8 @@ QPushButton#refreshButton{
border: none; border: none;
size: 100px;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -49,7 +49,7 @@ class TbCombox(QComboBox):
def initUI(self): def initUI(self):
# 创建ComboBox # 创建ComboBox
self.addItems(["压力转换块 ", "温度转换块", "物位转换块", "流量转换块"]) self.addItems(["压力转换块", "温度转换块", "物位转换块", "流量转换块"])
self.setEditable(True) # 设置为可编辑以应用样式表隐藏文本 self.setEditable(True) # 设置为可编辑以应用样式表隐藏文本
self.setObjectName('tbcombox') self.setObjectName('tbcombox')

@ -1,19 +1,22 @@
import imp import imp
import time
from operator import imod from operator import imod
import typing import typing
import re import re
# from matplotlib.pyplot import box # from matplotlib.pyplot import box
import qtawesome import qtawesome
from PyQt5 import QtGui,QtCore,QtWidgets from PyQt5 import QtGui,QtCore,QtWidgets
from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant, QSize from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant, QSize, QTimer
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QPushButton, QMessageBox, QLineEdit, \ from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QPushButton, QMessageBox, QLineEdit, \
QComboBox, QStyledItemDelegate, QVBoxLayout, QSplitter QComboBox, QStyledItemDelegate, QVBoxLayout, QSplitter
from UI.LoadingDataWidget import LoadingDataWidget from UI.LoadingDataWidget import LoadingDataWidget
from UI.ObjectTypeEditlayout import ObjectTypeEditlayout from UI.ObjectTypeEditlayout import ObjectTypeEditlayout
from utils import Globals from utils import Globals
from utils.DBModels.DeviceParModels import *
class VarTableModel(QAbstractTableModel): class VarTableModel(QAbstractTableModel):
''' 变量表模型类''' ''' 变量表模型类'''
def __init__(self, header, data: list, table = None): def __init__(self, header, data: list, table = None):
@ -48,6 +51,9 @@ class VarTableModel(QAbstractTableModel):
print("列索引超出范围") print("列索引超出范围")
return return
# for row in range(self.rowCount()): # for row in range(self.rowCount()):
if self.datas[row][2] in ['SENSOR_UNIT']:
unit = UnitTable.getUnitSymbolByUnitValue(value)
value = unit if unit else value
self.datas[row][6] = value self.datas[row][6] = value
self.table.proxy.invalidate() self.table.proxy.invalidate()
# self.layoutChanged.emit() # 通知视图数据已更改 # self.layoutChanged.emit() # 通知视图数据已更改
@ -163,6 +169,7 @@ class VarButtonDelegate(QItemDelegate):
refreshButton.setObjectName("refreshButton") refreshButton.setObjectName("refreshButton")
refreshButton.clicked.connect(self.refreshData) refreshButton.clicked.connect(self.refreshData)
refreshButton.index = [index.row(), index.column()] refreshButton.index = [index.row(), index.column()]
refreshButton.setIconSize(QSize(50,50))
readORwirte = self.parent().model.datas[index.row()][5] readORwirte = self.parent().model.datas[index.row()][5]
if 'w' not in readORwirte: if 'w' not in readORwirte:
@ -194,8 +201,10 @@ class VarButtonDelegate(QItemDelegate):
elif objectType == 'SENSOR_UNIT': elif objectType == 'SENSOR_UNIT':
comboxUnit = QComboBox() comboxUnit = QComboBox()
comboxUnit.setObjectName('modeCombox') comboxUnit.setObjectName('modeCombox')
comboxUnit.addItems(["kPa", "bar", "psi", 'inHg']) comboxUnit.addItem('下拉选择')
comboxUnit.setCurrentIndex(-1) comboxUnit.addItems([x[1] for x in self.parent().allUnitList])
comboxUnit.currentIndexChanged.connect(lambda index, comboxUnit = comboxUnit : self.startAction(modelIndex = index, comboxUnit = comboxUnit)) comboxUnit.currentIndexChanged.connect(lambda index, comboxUnit = comboxUnit : self.startAction(modelIndex = index, comboxUnit = comboxUnit))
boxLayout.addWidget(comboxUnit, 10) boxLayout.addWidget(comboxUnit, 10)
boxLayout.addWidget(refreshButton,1) boxLayout.addWidget(refreshButton,1)
@ -208,7 +217,10 @@ class VarButtonDelegate(QItemDelegate):
boxLayout.addWidget(refreshButton) boxLayout.addWidget(refreshButton)
startActionBtn.setObjectName('startActionBtn') startActionBtn.setObjectName('startActionBtn')
startActionBtn.setIconSize(QSize(50,50))
boxLayout.setContentsMargins(0, 0, 0, 0) boxLayout.setContentsMargins(0, 0, 0, 0)
widget = QWidget() widget = QWidget()
@ -231,16 +243,11 @@ class VarButtonDelegate(QItemDelegate):
values = [] values = []
#修改单位 #修改单位
if comboxUnit: if comboxUnit:
match str(modelIndex): if modelIndex == 0:
case '0': return
values.append('1133') else:
case '1': values = [self.parent().allUnitList[modelIndex - 1][0]]
values.append('1137') #kPa(1133),bar1137).psi(1141),inHg(1155) # print(values)
case '2':
values.append('1141')
case '3':
values.append('1155')
#修改操作模式 #修改操作模式
else: else:
if modelIndex or str(modelIndex) == '0' : if modelIndex or str(modelIndex) == '0' :
@ -268,8 +275,9 @@ class VarButtonDelegate(QItemDelegate):
"请输入强制值或数字", "请输入强制值或数字",
QMessageBox.Yes) QMessageBox.Yes)
return return
print(values,555) # print(values,555)
res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values) res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values)
time.sleep(0.4)
self.refreshData() self.refreshData()
def refreshData(self): def refreshData(self):

@ -43,6 +43,7 @@ class ParmView(QTableView):
self.dbModel = dbModel self.dbModel = dbModel
self.blcokIndex = blcokIndex self.blcokIndex = blcokIndex
self.blockType = blockType self.blockType = blockType
self.allUnitList = UnitTable.getAbleUint()
self.setHeader() self.setHeader()
self.setupUi() self.setupUi()
self.setData() self.setData()

@ -145,7 +145,7 @@ class EditAddressWidget(QDialog):
# print(index) # print(index)
def addCheckItem(self): def addCheckItem(self):
self.GSDData = GsdParser.parseGsdFiles('C:\\Users\\zcw\\Desktop\\海南profibus\\现场仪表GSD') self.GSDData = GsdParser.parseGsdFiles()
# deviceTypeCombox # deviceTypeCombox
for GSDDict in self.GSDData: for GSDDict in self.GSDData:
self.deviceTypeCombox.addItem(GSDDict['modelName']) self.deviceTypeCombox.addItem(GSDDict['modelName'])

@ -4,7 +4,8 @@ import re
class GsdParser: class GsdParser:
@classmethod @classmethod
def parseGsdFiles(cls, folderPath): def parseGsdFiles(cls):
folderPath = 'D:\\EnTalk PROFIBUS Manager\\GSD'
gsdData = [] gsdData = []
for filename in os.listdir(folderPath): for filename in os.listdir(folderPath):
if filename.lower().endswith('.gsd'): if filename.lower().endswith('.gsd'):

@ -37,7 +37,7 @@ class Parm():
return self.unpackValue(value) return self.unpackValue(value)
def writeParm(self, values): def writeParm(self, values):
print(*values) # print(*values)
valueByte = self.packValue(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)

@ -137,13 +137,16 @@ class DPV1Master():
def editDevAddress(self, oldAddress, newAddress, identNumer): def editDevAddress(self, oldAddress, newAddress, identNumer):
oldAddressHex = oldAddress.to_bytes(length=1, byteorder='little') oldAddressHex = oldAddress.to_bytes(length=1, byteorder='little')
newAddressHex = newAddress.to_bytes(1, byteorder='little') newAddressHex = newAddress.to_bytes(1, byteorder='little')
idHighHex = identNumer[:2].to_bytes(1, byteorder='little') # print(identNumer)
idLowHex = identNumer[2:].to_bytes(1, byteorder='little') idHighHex = int(identNumer[:2], 16).to_bytes(1, byteorder='little')
idLowHex = int(identNumer[2:], 16).to_bytes(1, byteorder='little')
editAddressStream = b'\x03' + oldAddressHex + b'\x00'+ newAddressHex + b'\x00' + idHighHex + b'\x00' + idLowHex editAddressStream = b'\x03' + oldAddressHex + b'\x00'+ newAddressHex + b'\x00' + idHighHex + b'\x00' + idLowHex
editAddressDate = struct.unpack('>hh', editAddressStream) # print(editAddressStream)
editAddressDate = struct.unpack('>hhhh', editAddressStream)
# print(editAddressDate)
self.writeMultipleRegister(1, 750, self.resetData) self.writeMultipleRegister(1, 750, self.resetData)
self.writeMultipleRegister(1, 750, editAddressDate) self.writeMultipleRegister(1, 750, editAddressDate)
time.sleep(0.3) time.sleep(0.4)
value = self.readHoldingRegisters(1, 750, 2) value = self.readHoldingRegisters(1, 750, 2)
if value[0] == 57344: if value[0] == 57344:
result = '修改错误' result = '修改错误'

@ -147,30 +147,41 @@ class UnitTable(BaseModel):
unitValue = CharField() unitValue = CharField()
unitSymbol = CharField() unitSymbol = CharField()
description = CharField() description = CharField()
state = CharField()
createTime = CharField() createTime = CharField()
# 查询设备是否存在 # 查询设备是否存在
@classmethod @classmethod
def getallParame(cls): def getByValue(cls, unitValue):
devices = cls.get_all() try:
if devices is 'error': return cls.get(cls.unitValue == str(unitValue))
except Exception as e:
return return
@classmethod
def getAbleUint(cls):
units = cls.select().where(cls.state == '1')
# print(units,444)
l = [] l = []
for x in devices: for unit in units:
l.append([x.unitValue, x.unitSymbol, x.description]) l.append([unit.unitValue, unit.unitSymbol])
return l return l
@classmethod @classmethod
def getByValue(cls, unitValue): def getUnitSymbolByUnitValue(cls, unitValue):
try: try:
return cls.get(cls.unitValue == str(unitValue)) unit = cls.get(cls.unitValue == unitValue)
return unit.unitSymbol
except Exception as e: except Exception as e:
# print(e)
return return
# print(units,444)
def addParame(self, unitValue, unitSymbol, description): def addParame(self, unitValue, unitSymbol, description, state):
self.unitValue = unitValue self.unitValue = unitValue
self.unitSymbol = unitSymbol self.unitSymbol = unitSymbol
self.description = description self.description = description
self.state = state
self.createTime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') self.createTime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
# print(self.createTime) # print(self.createTime)
self.save() self.save()

@ -23,5 +23,7 @@ class InitParameterDB():
for index, row in parameters.iterrows(): for index, row in parameters.iterrows():
parameter = row.values parameter = row.values
clsblockName = UnitTable() clsblockName = UnitTable()
if not clsblockName.getByValue(parameter[0]): if not clsblockName.getByValue(parameter[0]):
clsblockName.addParame(unitValue = parameter[0], unitSymbol = parameter[1], description = parameter[2]) clsblockName.addParame(unitValue = parameter[0], unitSymbol = parameter[1], description = parameter[2], state = parameter[3])
# print(UnitTable.getAbleUint())
Loading…
Cancel
Save