ModbusPack
zhangxuxutm 2 years ago
parent 4f32597f3d
commit c62691fdf3

@ -48,7 +48,7 @@ class MainTop(QtWidgets.QWidget):
self.closeBtn.setObjectName("closeBtn") self.closeBtn.setObjectName("closeBtn")
self.iconLabol.setPixmap(QPixmap(':/static/zhjt.png').scaled(50,50)) self.iconLabol.setPixmap(QPixmap(':/static/zhjt.png').scaled(50,50))
self.titleLabel.setText("信号发生装置") self.titleLabel.setText(" 中国核电工程有限公司 龙仪ModBus测试工具")
self.closeBtn.clicked.connect(self.MainWindow.close) self.closeBtn.clicked.connect(self.MainWindow.close)
self.minBtn.clicked.connect(self.MainWindow.showMinimized) self.minBtn.clicked.connect(self.MainWindow.showMinimized)

@ -340,7 +340,7 @@ class ProTypeBoxDelegate(ProjectButtonDelegate):
setattr(self, comboBox, QComboBox(self.parent())) setattr(self, comboBox, QComboBox(self.parent()))
cmBox = getattr(self, comboBox) cmBox = getattr(self, comboBox)
item = ['MODBUSTCP 主站模式', 'MODBUSTCP 从站模式', 'MODBUSRTU 主站模式', 'MODBUSRTU 从站模式','HART', 'TCRTD', 'AO/DO/PI', 'FF', 'FF模拟', 'HART模拟'] item = ['MODBUSTCP 主站模式', 'MODBUSTCP 从站模式', 'MODBUSRTU 主站模式', 'MODBUSRTU 从站模式']
cmBox.addItems(item) cmBox.addItems(item)
cmBox.index = [index.row(), index.column()] cmBox.index = [index.row(), index.column()]
if self.parent().model.datas[index.row()][index.column()] in range(10): if self.parent().model.datas[index.row()][index.column()] in range(10):

@ -91,12 +91,17 @@ class ActualTrend(QtWidgets.QMainWindow):
self._dynamic_ax.plot(pos_list, value_list, 'bo-', linewidth=2) self._dynamic_ax.plot(pos_list, value_list, 'bo-', linewidth=2)
# self._dynamic_ax.set_xlim(0,10) # self._dynamic_ax.set_xlim(0,10)
self._dynamic_ax.set_ylim(minY, maxY) self._dynamic_ax.set_ylim(minY, maxY)
# print(id(self._dynamic_ax))
self._dynamic_ax.figure.canvas.draw() self._dynamic_ax.figure.canvas.draw()
def closeEvent(self, event): def closeEvent(self, event):
# 判断是否点击了窗口的关闭按钮 # 判断是否点击了窗口的关闭按钮
if event.type() == event.Close: if event.type() == event.Close:
self._timer.stop() self._timer.stop()
self.hide()
def showEvent(self, event):
self._timer.start()
if __name__ == "__main__": if __name__ == "__main__":
qapp = QtWidgets.QApplication(sys.argv) qapp = QtWidgets.QApplication(sys.argv)

@ -58,7 +58,7 @@ class VarTableModel(QAbstractTableModel):
def initTable(self): def initTable(self):
self.datas = [] self.datas = []
self.editableList = []
self.table.parent.initIcon() self.table.parent.initIcon()
proType = Globals.getValue('currentProType') proType = Globals.getValue('currentProType')
@ -230,10 +230,17 @@ class ModBusTCPSlaveModel(VarTableModel):
class VarButtonDelegate(QItemDelegate): class VarButtonDelegate(QItemDelegate):
"""该类用于向单元格中添加按钮 任务表格""" """该类用于向单元格中添加按钮 任务表格"""
trendWidgetDict = {}
def __init__(self, parent=None): def __init__(self, parent=None):
super(VarButtonDelegate, self).__init__(parent) super(VarButtonDelegate, self).__init__(parent)
def trendWidget(self, varName):
if varName not in self.trendWidgetDict:
trendWidget = ActualTrend(varName = varName)
self.trendWidgetDict[varName] = trendWidget
return self.trendWidgetDict[varName]
def paint(self, painter, option, index): def paint(self, painter, option, index):
if not self.parent().indexWidget(index): if not self.parent().indexWidget(index):
button1 = QPushButton( button1 = QPushButton(
@ -442,7 +449,7 @@ class VarButtonDelegate(QItemDelegate):
if model.table.parent._isPopenOpen: if model.table.parent._isPopenOpen:
sender = self.sender() sender = self.sender()
name = str(model.datas[sender.index[0]][3]) name = str(model.datas[sender.index[0]][3])
trend = ActualTrend(varName = name) trend = self.trendWidget(varName = name)
trend.show() trend.show()
class ModbusTypeBox(QItemDelegate): class ModbusTypeBox(QItemDelegate):
@ -450,11 +457,15 @@ class ModbusTypeBox(QItemDelegate):
super(ModbusTypeBox, self).__init__(parent) super(ModbusTypeBox, self).__init__(parent)
def paint(self, painter, option, index): def paint(self, painter, option, index):
if index.column() == 5: if index.column() == 5 and index.row() not in self.parent().model.editableList:
data = self.parent().model.datas[index.row()] data = self.parent().model.datas[index.row()]
comBox = str('cb' + str(index.row()) + str(index.column())) comBox = str('cb' + str(index.row()) + str(index.column()))
# try:
# comboBox = getattr(self, comBox)
# except:
setattr(self, comBox, QComboBox()) setattr(self, comBox, QComboBox())
comboBox = getattr(self, comBox) comboBox = getattr(self, comBox)
# comboBox = getattr(self, comBox)
item = ['Coil Status', 'Input Status', 'Input Register', 'Holding Register'] item = ['Coil Status', 'Input Status', 'Input Register', 'Holding Register']
comboBox.addItems(item) comboBox.addItems(item)

@ -346,14 +346,14 @@ class ProjectManage(object):
zipf.extractall('project') zipf.extractall('project')
project = Project() projectList = []
projectList = []
for n in zipProjects: for n in zipProjects:
jsonPath = os.path.join('project', n, 'config', 'config.json') jsonPath = os.path.join('project', n, 'config', 'config.json')
with open(jsonPath, 'r') as f: with open(jsonPath, 'r') as f:
data = json.load(f) data = json.load(f)
proType = data['ProjectType'] proType = data['ProjectType']
des = data['description'] des = data['description']
project = Project()
project.createProject(n, proType, des) project.createProject(n, proType, des)
projectList.append(n) projectList.append(n)

@ -44,9 +44,8 @@ class ModbusVarManage(object):
maxIndex = index maxIndex = index
# print(IDIndex, slaveIndex, nameIndex, desIndex, typeIndex, addrIndex, minIndex, maxIndex) # print(IDIndex, slaveIndex, nameIndex, desIndex, typeIndex, addrIndex, minIndex, maxIndex)
if IDIndex == None or slaveIndex == None or nameIndex == None or desIndex == None or typeIndex == None or addrIndex == None or minIndex == None or maxIndex == None: if IDIndex == None or slaveIndex == None or nameIndex == None or desIndex == None or typeIndex == None or addrIndex == None or minIndex == None or maxIndex == None:
# print('表头错误') print('表头错误')
return '表头错误' return '表头错误'
for index, row in enumerate(list(ws.iter_rows())[1:]): for index, row in enumerate(list(ws.iter_rows())[1:]):
try: try:
l = [str(x.value) for x in row] l = [str(x.value) for x in row]
@ -57,14 +56,14 @@ class ModbusVarManage(object):
slaveID = l[slaveIndex] slaveID = l[slaveIndex]
min = l[minIndex] min = l[minIndex]
max = l[maxIndex] max = l[maxIndex]
ModBusVarModel = ModBusVar() if ModBusVar.getByName(varName):
if ModBusVarModel.getByName(varName): ModBusVar.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVar.varName == varName).execute()
ModBusVarModel.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVarModel.varName == varName)
else: else:
ModBusVarModel = ModBusVar()
ModBusVarModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int') ModBusVarModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int')
except Exception as e: except Exception as e:
print(e) print(e)
return '{}行导入出错'.format(index + 1) print('{}行导入出错'.format(index + 1))
@classmethod @classmethod
def exportModbusVar(self, excelPath): def exportModbusVar(self, excelPath):

@ -77,6 +77,7 @@ class ModBusVar(BaseModel):
except: except:
return False return False
# 删除变量 # 删除变量
@classmethod @classmethod
def deleteVar(cls, name): def deleteVar(cls, name):

Loading…
Cancel
Save