diff --git a/Static/Main.qss b/Static/Main.qss index a1be309..5f182f1 100644 --- a/Static/Main.qss +++ b/Static/Main.qss @@ -4,6 +4,20 @@ QComboBox#dataTypeCombox, QComboBox#orderCombox{ } + + +QComboBox#modeCombox{ + + background-color: #f0f0f0; + + border: none; + + height: 43px; + + font-size: 40px; + +} + QComboBox#tbcombox{ background-color: #f0f0f0; @@ -17,10 +31,30 @@ QComboBox#tbcombox{ border-radius: 5px; margin-left: -10px; + 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{ image: url(Static/down.png); @@ -308,7 +342,7 @@ QPushButton#tbparameBtn{ border: none; - width: 54.75px; + width: 140.75px; height: 40px; @@ -381,6 +415,8 @@ QPushButton#refreshButton{ border: none; + size: 100px; + } diff --git a/Static/PA块信息表.xlsx b/Static/PA块信息表.xlsx index 4728f8e..5f0907d 100644 Binary files a/Static/PA块信息表.xlsx and b/Static/PA块信息表.xlsx differ diff --git a/Static/PA块信息表all.xlsx b/Static/PA块信息表all.xlsx new file mode 100644 index 0000000..1bad873 Binary files /dev/null and b/Static/PA块信息表all.xlsx differ diff --git a/Static/UnitTable.xlsx b/Static/UnitTable.xlsx index db66608..fa99afc 100644 Binary files a/Static/UnitTable.xlsx and b/Static/UnitTable.xlsx differ diff --git a/UI/BlockParameterManageWidget.py b/UI/BlockParameterManageWidget.py index bb26b13..e7fe3c7 100644 --- a/UI/BlockParameterManageWidget.py +++ b/UI/BlockParameterManageWidget.py @@ -49,7 +49,7 @@ class TbCombox(QComboBox): def initUI(self): # 创建ComboBox - self.addItems(["压力转换块 ", "温度转换块", "物位转换块", "流量转换块"]) + self.addItems(["压力转换块", "温度转换块", "物位转换块", "流量转换块"]) self.setEditable(True) # 设置为可编辑以应用样式表隐藏文本 self.setObjectName('tbcombox') diff --git a/UI/BlockParameterModel.py b/UI/BlockParameterModel.py index 30789bb..7c35fef 100644 --- a/UI/BlockParameterModel.py +++ b/UI/BlockParameterModel.py @@ -1,19 +1,22 @@ import imp +import time from operator import imod import typing import re # from matplotlib.pyplot import box import qtawesome 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, \ QComboBox, QStyledItemDelegate, QVBoxLayout, QSplitter + from UI.LoadingDataWidget import LoadingDataWidget from UI.ObjectTypeEditlayout import ObjectTypeEditlayout - from utils import Globals +from utils.DBModels.DeviceParModels import * + class VarTableModel(QAbstractTableModel): ''' 变量表模型类''' def __init__(self, header, data: list, table = None): @@ -48,6 +51,9 @@ class VarTableModel(QAbstractTableModel): print("列索引超出范围") return # 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.table.proxy.invalidate() # self.layoutChanged.emit() # 通知视图数据已更改 @@ -163,6 +169,7 @@ class VarButtonDelegate(QItemDelegate): refreshButton.setObjectName("refreshButton") refreshButton.clicked.connect(self.refreshData) refreshButton.index = [index.row(), index.column()] + refreshButton.setIconSize(QSize(50,50)) readORwirte = self.parent().model.datas[index.row()][5] if 'w' not in readORwirte: @@ -194,8 +201,10 @@ class VarButtonDelegate(QItemDelegate): elif objectType == 'SENSOR_UNIT': comboxUnit = QComboBox() comboxUnit.setObjectName('modeCombox') - comboxUnit.addItems(["kPa", "bar", "psi", 'inHg']) - comboxUnit.setCurrentIndex(-1) + comboxUnit.addItem('下拉选择') + comboxUnit.addItems([x[1] for x in self.parent().allUnitList]) + + comboxUnit.currentIndexChanged.connect(lambda index, comboxUnit = comboxUnit : self.startAction(modelIndex = index, comboxUnit = comboxUnit)) boxLayout.addWidget(comboxUnit, 10) boxLayout.addWidget(refreshButton,1) @@ -207,8 +216,11 @@ class VarButtonDelegate(QItemDelegate): boxLayout.addWidget(startActionBtn) boxLayout.addWidget(refreshButton) + startActionBtn.setObjectName('startActionBtn') + startActionBtn.setIconSize(QSize(50,50)) + boxLayout.setContentsMargins(0, 0, 0, 0) widget = QWidget() @@ -231,16 +243,11 @@ class VarButtonDelegate(QItemDelegate): values = [] #修改单位 if comboxUnit: - match str(modelIndex): - case '0': - values.append('1133') - case '1': - values.append('1137') #kPa(1133),bar(1137).psi(1141),inHg(1155) - case '2': - values.append('1141') - case '3': - values.append('1155') - + if modelIndex == 0: + return + else: + values = [self.parent().allUnitList[modelIndex - 1][0]] + # print(values) #修改操作模式 else: if modelIndex or str(modelIndex) == '0' : @@ -268,8 +275,9 @@ class VarButtonDelegate(QItemDelegate): "请输入强制值或数字", QMessageBox.Yes) return - print(values,555) + # print(values,555) res = blockManage.writeParmValue(blockType, blockIndex, parmIndex, values) + time.sleep(0.4) self.refreshData() def refreshData(self): diff --git a/UI/BlockParameterView.py b/UI/BlockParameterView.py index be73b12..1f19476 100644 --- a/UI/BlockParameterView.py +++ b/UI/BlockParameterView.py @@ -43,6 +43,7 @@ class ParmView(QTableView): self.dbModel = dbModel self.blcokIndex = blcokIndex self.blockType = blockType + self.allUnitList = UnitTable.getAbleUint() self.setHeader() self.setupUi() self.setData() diff --git a/UI/EditAddressWidget.py b/UI/EditAddressWidget.py index 4e73f50..592fdd2 100644 --- a/UI/EditAddressWidget.py +++ b/UI/EditAddressWidget.py @@ -145,7 +145,7 @@ class EditAddressWidget(QDialog): # print(index) def addCheckItem(self): - self.GSDData = GsdParser.parseGsdFiles('C:\\Users\\zcw\\Desktop\\海南profibus\\现场仪表GSD') + self.GSDData = GsdParser.parseGsdFiles() # deviceTypeCombox for GSDDict in self.GSDData: self.deviceTypeCombox.addItem(GSDDict['modelName']) diff --git a/model/ConfigModel/GSDManage.py b/model/ConfigModel/GSDManage.py index 4d609c2..8dc9fb0 100644 --- a/model/ConfigModel/GSDManage.py +++ b/model/ConfigModel/GSDManage.py @@ -4,7 +4,8 @@ import re class GsdParser: @classmethod - def parseGsdFiles(cls, folderPath): + def parseGsdFiles(cls): + folderPath = 'D:\\EnTalk PROFIBUS Manager\\GSD' gsdData = [] for filename in os.listdir(folderPath): if filename.lower().endswith('.gsd'): diff --git a/model/ProjectModel/ParmManage.py b/model/ProjectModel/ParmManage.py index fc43a1b..0da9f88 100644 --- a/model/ProjectModel/ParmManage.py +++ b/model/ProjectModel/ParmManage.py @@ -37,7 +37,7 @@ class Parm(): return self.unpackValue(value) def writeParm(self, values): - print(*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) diff --git a/protocol/ModBus/DPV1Master.py b/protocol/ModBus/DPV1Master.py index 85f4393..f3e7e0f 100644 --- a/protocol/ModBus/DPV1Master.py +++ b/protocol/ModBus/DPV1Master.py @@ -137,13 +137,16 @@ class DPV1Master(): def editDevAddress(self, oldAddress, newAddress, identNumer): oldAddressHex = oldAddress.to_bytes(length=1, byteorder='little') newAddressHex = newAddress.to_bytes(1, byteorder='little') - idHighHex = identNumer[:2].to_bytes(1, byteorder='little') - idLowHex = identNumer[2:].to_bytes(1, byteorder='little') + # print(identNumer) + 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 - editAddressDate = struct.unpack('>hh', editAddressStream) + # print(editAddressStream) + editAddressDate = struct.unpack('>hhhh', editAddressStream) + # print(editAddressDate) self.writeMultipleRegister(1, 750, self.resetData) self.writeMultipleRegister(1, 750, editAddressDate) - time.sleep(0.3) + time.sleep(0.4) value = self.readHoldingRegisters(1, 750, 2) if value[0] == 57344: result = '修改错误' diff --git a/utils/DBModels/DeviceParModels.py b/utils/DBModels/DeviceParModels.py index aea6c21..aeb31e5 100644 --- a/utils/DBModels/DeviceParModels.py +++ b/utils/DBModels/DeviceParModels.py @@ -147,30 +147,41 @@ class UnitTable(BaseModel): unitValue = CharField() unitSymbol = CharField() description = CharField() + state = CharField() createTime = CharField() # 查询设备是否存在 + @classmethod - def getallParame(cls): - devices = cls.get_all() - if devices is 'error': - return + def getByValue(cls, unitValue): + try: + return cls.get(cls.unitValue == str(unitValue)) + except Exception as e: + return + @classmethod + def getAbleUint(cls): + units = cls.select().where(cls.state == '1') + # print(units,444) l = [] - for x in devices: - l.append([x.unitValue, x.unitSymbol, x.description]) + for unit in units: + l.append([unit.unitValue, unit.unitSymbol]) return l @classmethod - def getByValue(cls, unitValue): + def getUnitSymbolByUnitValue(cls, unitValue): try: - return cls.get(cls.unitValue == str(unitValue)) + unit = cls.get(cls.unitValue == unitValue) + return unit.unitSymbol except Exception as e: - return + # print(e) + return + # print(units,444) - def addParame(self, unitValue, unitSymbol, description): + def addParame(self, unitValue, unitSymbol, description, state): self.unitValue = unitValue self.unitSymbol = unitSymbol self.description = description + self.state = state self.createTime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') # print(self.createTime) self.save() diff --git a/utils/DBModels/InitParameterDB.py b/utils/DBModels/InitParameterDB.py index 113c186..1bdc777 100644 --- a/utils/DBModels/InitParameterDB.py +++ b/utils/DBModels/InitParameterDB.py @@ -22,6 +22,8 @@ class InitParameterDB(): parameters = pd.read_excel('static/UnitTable.xlsx', sheet_name = 'UnitTable') for index, row in parameters.iterrows(): parameter = row.values - clsblockName = UnitTable() + clsblockName = UnitTable() + if not clsblockName.getByValue(parameter[0]): - clsblockName.addParame(unitValue = parameter[0], unitSymbol = parameter[1], description = parameter[2]) \ No newline at end of file + clsblockName.addParame(unitValue = parameter[0], unitSymbol = parameter[1], description = parameter[2], state = parameter[3]) + # print(UnitTable.getAbleUint()) \ No newline at end of file