Compare commits

...

7 Commits

5
.gitignore vendored

@ -14,6 +14,11 @@ o
*.code-workspace
*.json
*.spec
*.cmd
*.exe
*.api
Static/license.lic
.idea/.gitignore
/Static/influxDB/
/bin.build/
Static/InfluxDB.api

@ -1 +1 @@
jtTFa-rtobjdxWm7fKS7Tk2gZECrXwdM59799SddTcqDWDGiQTPEFYy5VW6IHgsAK5RZMtMLWmpZA3PaipOkmg==
CqVFdMGoG3esTzQAK6YgB1PvmFenxgAxoOsXE9AlWybUFYDq3SZbVLUk0xcLtjeJe_I269EzXzrnSQeBxRLcBQ==

@ -611,13 +611,13 @@ QCheckBox#userBox::indicator{
QCheckBox#userBox::indicator:checked{
image: url(Static/checkoff.png);
image: url(:/static/checkoff.png);
}
QCheckBox#userBox::indicator:enabled:unchecked{
image: url(Static/checkon.png);
image: url(:/static/checkon.png);
}
@ -714,7 +714,7 @@ QComboBox#timeBox::drop-down{
QComboBox#setBox::drop-down, QComboBox#ProTypeBox::drop-down,QComboBox#TcRtdTypeBox::drop-down, QComboBox#ModbusTypeBox::drop-down, QComboBox#timeBox::drop-down{
image: url(Static/down.png);
image: url(:/static/down.png);
}
@ -806,3 +806,52 @@ QListView#trendListView::item{
margin-bottom: 10px;
}
QMessageBox {
background-color: #f0f0f0;
color: black;
font-size: 14px;
border: 1px solid #cccccc;
border-radius: 5px;
padding: 5px;
}
QMessageBox QLabel {
color: black;
font-size: 14px;
}
QMessageBox QPushButton {
background-color: #e0e0e0;
color: black;
font-size: 14px;
border: 1px solid #cccccc;
border-radius: 5px;
padding: 5px;
min-width: 5em;
}
QMessageBox QPushButton:hover {
background-color: #f5f5f5;
}
QMessageBox QPushButton:pressed {
background-color: #e5e5e5;
}

@ -0,0 +1,25 @@
import os
fileType = ['png', 'ico']
with open('{}Qrc.qrc'.format('static'), 'w') as f:
f.write(
'''<RCC>
<qresource prefix="/static">
''')
for root, dirs, files in os.walk('..\\static'):
for file in files:
if file.split('.')[-1] in fileType:
print(file)
f.write(' <file alias="{}">{}</file>\r\n'.format(file, os.path.join(root,file)))
f.write('''
</qresource>
</RCC>
''')
cmd = 'pyrcc5 -o {}.py {}Qrc.qrc'.format('static','static')
os.system(cmd)

@ -1,4 +1,4 @@
engine-path: "C:\\Users\\zcw\\Desktop\\DCS\\Static\\influxDB\\engine"
http-bind-address: ":6324"
engine-path: "engine"
http-bind-address: ":8086"
storage-cache-max-memory-size: 268435456
bolt-path: "C:\\Users\\zcw\\Desktop\\DCS\\Static\\influxDB\\engine\\influxd.bolt"
bolt-path: "engine\\influxd.bolt"

File diff suppressed because it is too large Load Diff

@ -0,0 +1,42 @@
<RCC>
<qresource prefix="/static">
<file alias="add.png">..\static\add.png</file>
<file alias="checkoff.png">..\static\checkoff.png</file>
<file alias="checkon.png">..\static\checkon.png</file>
<file alias="clear.png">..\static\clear.png</file>
<file alias="close.png">..\static\close.png</file>
<file alias="delete.png">..\static\delete.png</file>
<file alias="down.png">..\static\down.png</file>
<file alias="export.png">..\static\export.png</file>
<file alias="file.png">..\static\file.png</file>
<file alias="import.png">..\static\import.png</file>
<file alias="max.png">..\static\max.png</file>
<file alias="message.png">..\static\message.png</file>
<file alias="min.png">..\static\min.png</file>
<file alias="new.png">..\static\new.png</file>
<file alias="newH.png">..\static\newH.png</file>
<file alias="normal.png">..\static\normal.png</file>
<file alias="open.png">..\static\open.png</file>
<file alias="openH.png">..\static\openH.png</file>
<file alias="pause.png">..\static\pause.png</file>
<file alias="Searc.png">..\static\Searc.png</file>
<file alias="search.png">..\static\search.png</file>
<file alias="setting.png">..\static\setting.png</file>
<file alias="settingH.png">..\static\settingH.png</file>
<file alias="start.png">..\static\start.png</file>
<file alias="startProtocol.png">..\static\startProtocol.png</file>
<file alias="trend.png">..\static\trend.png</file>
<file alias="trendH.png">..\static\trendH.png</file>
<file alias="userMag.png">..\static\userMag.png</file>
<file alias="userMagH.png">..\static\userMagH.png</file>
<file alias="userPic.png">..\static\userPic.png</file>
<file alias="varMag.png">..\static\varMag.png</file>
<file alias="varMagH.png">..\static\varMagH.png</file>
<file alias="zhjt.ico">..\static\zhjt.ico</file>
<file alias="zhjt.png">..\static\zhjt.png</file>
<file alias="nssm.ico">..\static\influxDB\nssm-2.24\src\nssm.ico</file>
</qresource>
</RCC>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

@ -19,6 +19,7 @@ from win32 import win32api, win32gui
from win32.lib import win32con
from windoweffect import WindowEffect, MINMAXINFO, NCCALCSIZE_PARAMS
from model.UserModel.UserManage import UserManage
from Static import static
class LoginWidget(QWidget):
BORDER_WIDTH = 5 #设圆角
@ -32,7 +33,7 @@ class LoginWidget(QWidget):
self.resize(306, 451)
self.picLabel = QLabel()
self.picLabel.setPixmap(QPixmap('static/userPic.png'))
self.picLabel.setPixmap(QPixmap(':/static/userPic.png'))
self.picLabel.setScaledContents(True)
self.userEdit = QLineEdit()

@ -1,4 +1,5 @@
import sys
import time
# sys.setrecursionlimit(10000)
@ -153,7 +154,7 @@ class MainWindow(QMainWindow):
self.leftWidget.createProject.clicked.connect(lambda: self.exButtonClicked(0))
self.leftWidget.varMag.clicked.connect(self.varShow)
self.leftWidget.trendMag.clicked.connect(lambda: self.exButtonClicked(2))
self.leftWidget.trendMag.clicked.connect(self.reFreshTrendWidget)
self.leftWidget.userMag.clicked.connect(lambda: self.exButtonClicked(3))
self.leftWidget.protocolMag.clicked.connect(self.showSetting)
@ -183,9 +184,13 @@ class MainWindow(QMainWindow):
# self.setAttribute(Qt.WA_TranslucentBackground) # 设置窗口背景透明
self.setWindowFlag(Qt.FramelessWindowHint)
def exButtonClicked(self, index):
if not Globals.getValue('currentPro') and index != 0:
return -1
self.rightWidget.setCurrentIndex(index)
print(index)
if index in [4, 5]:
return
Globals.setValue('SearchWidget', index)
@ -194,41 +199,45 @@ class MainWindow(QMainWindow):
if proType == -1:
return
elif proType in ['0', '1']:
self.rightWidget.setCurrentIndex(4)
self.TcpSettingWidget.setupUI()
if self.exButtonClicked(4) != -1:
self.TcpSettingWidget.setupUI()
elif proType in ['2', '3']:
self.rightWidget.setCurrentIndex(5)
self.RtuSettingWidget.setupUI()
if self.exButtonClicked(5) != -1:
self.RtuSettingWidget.setupUI()
def varShow(self):
proType = Globals.getValue('currentProType')
print(type(proType))
if proType == -1:
return
elif proType in ['0', '1', '2', '3']:
self.rightWidget.setCurrentIndex(1)
self.exButtonClicked(1)
Globals.setValue('SearchWidget', 1)
elif proType in ['4']:
self.rightWidget.setCurrentIndex(6)
self.exButtonClicked(6)
Globals.setValue('SearchWidget', 6)
elif proType in ['5']:
self.rightWidget.setCurrentIndex(7)
self.exButtonClicked(7)
Globals.setValue('SearchWidget', 7)
elif proType in ['6']:
self.rightWidget.setCurrentIndex(8)
self.exButtonClicked(8)
Globals.setValue('SearchWidget', 8)
elif proType in ['7']:
self.rightWidget.setCurrentIndex(9)
self.exButtonClicked(9)
self.ffWidget.initDevView()
Globals.setValue('SearchWidget', 9)
elif proType in ['8']:
self.rightWidget.setCurrentIndex(10)
self.exButtonClicked(10)
Globals.setValue('SearchWidget', 10)
elif proType in ['9']:
self.rightWidget.setCurrentIndex(11)
self.exButtonClicked(11)
Globals.setValue('SearchWidget', 11)
#枚举参数
#枚举参数
def reFreshTrendWidget(self):
self.trendWidget.getMems()
self.exButtonClicked(2)
def enum(self,**enums):
return type('Enum', (), enums)

@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QWidget, QSpacerItem, QHeaderView, QSizePolicy
from PyQt5.QtGui import QPixmap, QIcon
from Static import static
class MainLeft(QWidget):
def __init__(self):
@ -73,22 +73,22 @@ class MainLeft(QWidget):
self.userMag.setText("用户管理")
self.protocolMag.setText("通讯配置")
self.createProject.setIcon(QIcon('static/newH.png'))
# self.openProject.setIcon(QIcon('static/open.png'))
self.varMag.setIcon(QIcon('static/varMag.png'))
self.trendMag.setIcon(QIcon('static/trend.png'))
self.userMag.setIcon(QIcon('static/userMag.png'))
self.protocolMag.setIcon(QIcon('static/setting.png'))
self.createProject.setIcon(QIcon(':/static/newH.png'))
# self.openProject.setIcon(QIcon(':/static/open.png'))
self.varMag.setIcon(QIcon(':/static/varMag.png'))
self.trendMag.setIcon(QIcon(':/static/trend.png'))
self.userMag.setIcon(QIcon(':/static/userMag.png'))
self.protocolMag.setIcon(QIcon(':/static/setting.png'))
for btn in [self.createProject, self.varMag, self.trendMag, self.userMag, self.protocolMag]:
self.setBtn(btn)
# self.openProject.clicked.connect(lambda:self.openProject.setIcon(QIcon('static/openH.png')))
self.createProject.clicked.connect(lambda:self.createProject.setIcon(QIcon('static/newH.png')))
self.varMag.clicked.connect(lambda:self.varMag.setIcon(QIcon('static/varMagH.png')))
self.trendMag.clicked.connect(lambda:self.trendMag.setIcon(QIcon('static/trendH.png')))
self.userMag.clicked.connect(lambda:self.userMag.setIcon(QIcon('static/userMagH.png')))
self.protocolMag.clicked.connect(lambda:self.protocolMag.setIcon(QIcon('static/settingH.png')))
# self.openProject.clicked.connect(lambda:self.openProject.setIcon(QIcon(':/static/openH.png')))
self.createProject.clicked.connect(lambda:self.createProject.setIcon(QIcon(':/static/newH.png')))
self.varMag.clicked.connect(lambda:self.varMag.setIcon(QIcon(':/static/varMagH.png')))
self.trendMag.clicked.connect(lambda:self.trendMag.setIcon(QIcon(':/static/trendH.png')))
self.userMag.clicked.connect(lambda:self.userMag.setIcon(QIcon(':/static/userMagH.png')))
self.protocolMag.clicked.connect(lambda:self.protocolMag.setIcon(QIcon(':/static/settingH.png')))
self.createProject.setChecked(True)
self.createProject.setDown(True)
@ -109,45 +109,45 @@ class MainLeft(QWidget):
def eventFilter(self, object, event):
if object == self.createProject:
if event.type() == QtCore.QEvent.HoverEnter:
self.createProject.setIcon(QIcon('static/newH.png'))
self.createProject.setIcon(QIcon(':/static/newH.png'))
return True
if event.type() == QtCore.QEvent.HoverLeave and not self.createProject.isChecked():
self.createProject.setIcon(QIcon('static/new.png'))
self.createProject.setIcon(QIcon(':/static/new.png'))
return True
# if object == self.openProject:
# if event.type() == QtCore.QEvent.HoverEnter:
# self.openProject.setIcon(QIcon('static/openH.png'))
# self.openProject.setIcon(QIcon(':/static/openH.png'))
# return True
# if event.type() == QtCore.QEvent.HoverLeave and not self.openProject.isChecked():
# self.openProject.setIcon(QIcon('static/open.png'))
# self.openProject.setIcon(QIcon(':/static/open.png'))
# return True
if object == self.varMag:
if event.type() == QtCore.QEvent.HoverEnter:
self.varMag.setIcon(QIcon('static/varMagH.png'))
self.varMag.setIcon(QIcon(':/static/varMagH.png'))
return True
if event.type() == QtCore.QEvent.HoverLeave and not self.varMag.isChecked():
self.varMag.setIcon(QIcon('static/varMag.png'))
self.varMag.setIcon(QIcon(':/static/varMag.png'))
return True
if object == self.trendMag:
if event.type() == QtCore.QEvent.HoverEnter:
self.trendMag.setIcon(QIcon('static/trendH.png'))
self.trendMag.setIcon(QIcon(':/static/trendH.png'))
return True
if event.type() == QtCore.QEvent.HoverLeave and not self.trendMag.isChecked():
self.trendMag.setIcon(QIcon('static/trend.png'))
self.trendMag.setIcon(QIcon(':/static/trend.png'))
return True
if object == self.userMag:
if event.type() == QtCore.QEvent.HoverEnter:
self.userMag.setIcon(QIcon('static/userMagH.png'))
self.userMag.setIcon(QIcon(':/static/userMagH.png'))
return True
if event.type() == QtCore.QEvent.HoverLeave and not self.userMag.isChecked():
self.userMag.setIcon(QIcon('static/userMag.png'))
self.userMag.setIcon(QIcon(':/static/userMag.png'))
return True
if object == self.protocolMag:
if event.type() == QtCore.QEvent.HoverEnter:
self.protocolMag.setIcon(QIcon('static/settingH.png'))
self.protocolMag.setIcon(QIcon(':/static/settingH.png'))
return True
if event.type() == QtCore.QEvent.HoverLeave and not self.protocolMag.isChecked():
self.protocolMag.setIcon(QIcon('static/setting.png'))
self.protocolMag.setIcon(QIcon(':/static/setting.png'))
return True
return False
@ -159,9 +159,9 @@ class MainLeft(QWidget):
self.userMag.setDown(False)
self.protocolMag.setDown(False)
self.createProject.setIcon(QIcon('static/new.png'))
# self.openProject.setIcon(QIcon('static/open.png'))
self.varMag.setIcon(QIcon('static/varMag.png'))
self.trendMag.setIcon(QIcon('static/trend.png'))
self.userMag.setIcon(QIcon('static/userMag.png'))
self.protocolMag.setIcon(QIcon('static/setting.png'))
self.createProject.setIcon(QIcon(':/static/new.png'))
# self.openProject.setIcon(QIcon(':/static/open.png'))
self.varMag.setIcon(QIcon(':/static/varMag.png'))
self.trendMag.setIcon(QIcon(':/static/trend.png'))
self.userMag.setIcon(QIcon(':/static/userMag.png'))
self.protocolMag.setIcon(QIcon(':/static/setting.png'))

@ -7,6 +7,7 @@ from PyQt5.QtGui import QPixmap, QIcon
from UI.TrendManage.TrendWidget import TrendWidgets
from utils import Globals
from Static import static
class MainTop(QtWidgets.QWidget):
def __init__(self, MainWindow):
super().__init__()
@ -26,7 +27,7 @@ class MainTop(QtWidgets.QWidget):
self.searchEdit = QtWidgets.QLineEdit()
action = QtWidgets.QAction(self)
action.setIcon(QIcon('static/search.png'))
action.setIcon(QIcon(':/static/search.png'))
self.searchEdit.addAction(action, QtWidgets.QLineEdit.LeadingPosition)
self.searchEdit.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
self.searchEdit.setObjectName('searchEdit')
@ -37,17 +38,17 @@ class MainTop(QtWidgets.QWidget):
self.searchEdit.textChanged.connect(self.searchEditTextChanged)
# print(Globals.getValue('SearchWidget'))
self.minBtn = QtWidgets.QPushButton(QIcon('static/min.png'), '' ,self)
self.minBtn = QtWidgets.QPushButton(QIcon(':/static/min.png'), '' ,self)
self.minBtn.setObjectName("minBtn")
self.maxBtn = QtWidgets.QPushButton(QIcon('static/normal.png'), '' ,self)
self.maxBtn = QtWidgets.QPushButton(QIcon(':/static/normal.png'), '' ,self)
self.maxBtn.setObjectName("maxBtn")
self.closeBtn = QtWidgets.QPushButton(QIcon('static/close.png'), '' ,self)
self.closeBtn = QtWidgets.QPushButton(QIcon(':/static/close.png'), '' ,self)
self.closeBtn.setObjectName("closeBtn")
self.iconLabol.setText("ICON")
self.titleLabel.setText("信号发生装置")
self.iconLabol.setPixmap(QPixmap(':/static/zhjt.png').scaled(50,50))
self.titleLabel.setText(" 中国核电工程有限公司 龙仪ModBus测试工具")
self.closeBtn.clicked.connect(self.MainWindow.close)
self.minBtn.clicked.connect(self.MainWindow.showMinimized)
@ -66,8 +67,8 @@ class MainTop(QtWidgets.QWidget):
self.horizontalLayout.addWidget(self.maxBtn)
self.horizontalLayout.addWidget(self.closeBtn)
self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 1)
# self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 3)
self.horizontalLayout.setStretch(2, 3)
self.horizontalLayout.setStretch(3, 5)
self.horizontalLayout.setStretch(4, 5)
@ -100,14 +101,14 @@ class MainTop(QtWidgets.QWidget):
def showMax(self):
if self.MainWindow.isMaximized():
self.MainWindow.showNormal()
self.maxBtn.setIcon(QIcon('static/max.png'))
self.maxBtn.setIcon(QIcon(':/static/max.png'))
self.MainWindow.verticalLayout.setStretch(0, 1)
self.MainWindow.verticalLayout.setStretch(1, 15)
else:
self.MainWindow.showMaximized()
self.MainWindow.verticalLayout.setStretch(0, 1)
self.MainWindow.verticalLayout.setStretch(1, 18)
self.maxBtn.setIcon(QIcon('static/normal.png'))
self.maxBtn.setIcon(QIcon(':/static/normal.png'))
def mouseDoubleClickEvent(self, e): # 双击
self.showMax()

@ -233,14 +233,14 @@ class ProjectButtonDelegate(QItemDelegate):
def exchange_action(self):
# 切换工程按钮槽函数
sender = self.sender()
projectNumber = Globals.getValue('projectNumber')
if projectNumber == sender.index[0]:
projectName = Globals.getValue('currentPro')
if projectName == str(self.parent().model.datas[sender.index[0]][1]):
reply = QMessageBox.question(self.parent(),
'警告',
"工程已打开",
QMessageBox.Yes)
return
print(sender.index[0])
# print(sender.index[0])
if sender.index[0] in self.parent().model.editableList:
reply = QMessageBox.question(self.parent(),
'警告',
@ -249,10 +249,10 @@ class ProjectButtonDelegate(QItemDelegate):
return
self.loginWidget = LoginWidget()
self.loginWidget.show()
lastproType = Globals.getValue('currentProType')
ProjectManage.switchProject(str(self.parent().model.datas[sender.index[0]][1]), str(self.parent().model.datas[sender.index[0]][4]))
proType = Globals.getValue('currentProType')
if proType in ['0', '1', '2', '3']:
Globals.getValue('varTable').model.initTable()
elif proType in ['4']:
@ -267,7 +267,6 @@ class ProjectButtonDelegate(QItemDelegate):
Globals.getValue('HartSimulateTable').model.initTable()
Globals.getValue('userTable').model.initTable()
Globals.getValue('HistoryWidget').exchangeProject()
Globals.setValue('projectNumber', sender.index[0])
self.parent().proxy.invalidate()
@ -295,7 +294,7 @@ class ProjectButtonDelegate(QItemDelegate):
return
if sender.oldName:
if ProjectManage.editProject(name = sender.oldName, Nname = name, des = des):
if ProjectManage.editProject(name = sender.oldName, Nname = name, des = des, proType = proType):
reply = QMessageBox.question(self.parent(),
'警告',
"工程名相同",
@ -317,6 +316,7 @@ class ProjectButtonDelegate(QItemDelegate):
proMes.append('')
model.insert_data(proMes, rowIndex)
model.remove_row(rowIndex + 1)
self.parent().proxy.invalidate()
def delete_action(self):
@ -325,6 +325,8 @@ class ProjectButtonDelegate(QItemDelegate):
name = str(model.datas[sender.index[0]][1])
ProjectManage.deleteProject(name = name)
model.remove_row(sender.index[0])
if name == Globals.getValue('currentPro'):
Globals.setValue('currentPro', None)
class ProTypeBoxDelegate(ProjectButtonDelegate):
def __init__(self, parent=None):
@ -338,7 +340,7 @@ class ProTypeBoxDelegate(ProjectButtonDelegate):
setattr(self, comboBox, QComboBox(self.parent()))
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.index = [index.row(), index.column()]
if self.parent().model.datas[index.row()][index.column()] in range(10):

@ -8,7 +8,7 @@ from .ProjectTable import ProjectTableView
from .ProjectModel import ProjectTableModel
from model.ProjectModel.ProjectManage import ProjectManage
from Static import static
class ProjectWidgets(QtWidgets.QWidget):
def __init__(self):
@ -17,17 +17,17 @@ class ProjectWidgets(QtWidgets.QWidget):
self.setupUi()
def setupUi(self):
self.createBtn = QPushButton(QIcon('static/add.png'), '新建工程')
self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建工程')
self.createBtn.setObjectName('createBtn')
self.createBtn.setIconSize(QSize(22, 22))
self.createBtn.clicked.connect(self.createProject)
self.importBtn = QPushButton(QIcon('static/import.png'), '导入工程')
self.importBtn = QPushButton(QIcon(':/static/import.png'), '导入工程')
self.importBtn.setObjectName('importBtn')
self.importBtn.setIconSize(QSize(22, 22))
self.importBtn.clicked.connect(self.importProject)
self.exportBtn = QPushButton(QIcon('static/export.png'), '导出工程')
self.exportBtn = QPushButton(QIcon(':/static/export.png'), '导出工程')
self.exportBtn.setObjectName('exportBtn')
self.exportBtn.setIconSize(QSize(22, 22))
self.exportBtn.clicked.connect(self.exportPorject)

@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from utils import Globals
from UI.Main.Main import MainWindow
from model.ClientModel.Client import Client
from Static import static
@ -111,7 +111,7 @@ class RegisterWidget(QWidget):
self.setWindowTitle("Form")
# self.label.setText("TextLabel")
pix = QtGui.QPixmap(':/static/logo.png')
pix = QtGui.QPixmap(':/:/static/logo.png')
self.label.setPixmap(pix)
self.label.setScaledContents(True)
self.label.setMaximumSize(QSize(110,40))

@ -6,6 +6,7 @@ from matplotlib.backends.qt_compat import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import (FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure
from PyQt5.QtCore import QThread
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
@ -25,9 +26,9 @@ class ActualTrend(QtWidgets.QMainWindow):
self.varName = varName
self._main = QtWidgets.QWidget()
self.setCentralWidget(self._main)
layout = QtWidgets.QVBoxLayout(self._main)
_main = QtWidgets.QWidget()
self.setCentralWidget(_main)
layout = QtWidgets.QVBoxLayout(_main)
dynamic_canvas = FigureCanvas(Figure(figsize=(5, 3)))
@ -45,26 +46,23 @@ class ActualTrend(QtWidgets.QMainWindow):
self._timer = dynamic_canvas.new_timer(
1000, [(self._update_canvas, (), {})])
self._timer.start()
def _update_canvas(self):
# self.n += 1
varName = self.varName
varMM = ModbusVarManage.getByName(varName)
if varMM:
minY, maxY = ModbusVarManage.getByName(varName)[-2], ModbusVarManage.getByName(varName)[-1]
if not minY or not maxY:
minY = -100
maxY = 100
else:
minY = float(minY)
maxY = float(maxY)
self._dynamic_ax.clear()
acttime = time.strftime('%H:%M:%S', time.localtime(time.time()))
# print(acttime)
if varName != '':
uid = MBTCPMApp.backend.get('ModBus').decode('utf-8')
if MBTCPMApp.backend.get('ModBus') is not None:
uid = MBTCPMApp.backend.get('ModBus').decode('utf-8')
else:
return
# print(uid)
res = AsyncResult(uid) # 参数为task id
if res.result:
@ -76,6 +74,13 @@ class ActualTrend(QtWidgets.QMainWindow):
except Exception as e:
print(e)
if not varMM[-2] and not varMM[-1]:
minY = min(self.yQueue.list) - 5
maxY = max(self.yQueue.list) + 5
else:
minY = float(varMM[-2]) - float(5)
maxY = float(varMM[-1]) + float(5)
name_list = self.xQueue.list
value_list = np.array(self.yQueue.list)
pos_list = np.arange(len(name_list))
@ -85,8 +90,18 @@ class ActualTrend(QtWidgets.QMainWindow):
self._dynamic_ax.plot(pos_list, value_list, 'bo-', linewidth=2)
# 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()
def closeEvent(self, event):
# 判断是否点击了窗口的关闭按钮
if event.type() == event.Close:
self._timer.stop()
self.hide()
def showEvent(self, event):
self._timer.start()
if __name__ == "__main__":
qapp = QtWidgets.QApplication(sys.argv)

@ -22,7 +22,7 @@ import pyecharts.options as opts
from pyecharts.charts import Line
import numpy as np
from Static import static
class HistoryTrend(object):
def __init__(self, view):
@ -96,7 +96,7 @@ class TrendWidgets(QWidget):
self.proxy.setSourceModel(self.model)
self.listview.setModel(self.proxy)
self.delBtn = QtWidgets.QPushButton(QIcon('static/delete.png'), '删除记录', self)
self.delBtn = QtWidgets.QPushButton(QIcon(':/static/delete.png'), '删除记录', self)
self.delBtn.setObjectName('delBtn')
self.delBtn.setIconSize(QSize(22, 22))
self.delBtn.clicked.connect(self.deleteMem)
@ -114,6 +114,8 @@ class TrendWidgets(QWidget):
Globals.setValue('HistoryWidget', self)
def deleteMem(self):
if not self.memLsit:
return
self.historyDB.mem = self.memLsit[self.timeBox.currentIndex()]
self.historyDB.deleteMem()
InfluxMem.deleteMem(self.historyDB.mem)
@ -173,16 +175,17 @@ class TrendWidgets(QWidget):
def exchangeProject(self):
self.timeBox.clear()
self.memLsit = []
self.getMems()
self.refreshList(0)
self.trendWebView.setHtml('')
def getMems(self):
# 获取所有的趋势表
mems = InfluxMem.get_all()
self.proName = Globals.getValue('currentPro')
# self.timeBox.clear()
if not self.proName:
return
self.timeBox.clear()
if mems is 'Error':
return
for x in mems:
@ -195,14 +198,16 @@ class TrendWidgets(QWidget):
def refreshList(self, index):
# 更新变量列表
self.getMems()
self.model.clear()
if self.memLsit == []:
return
self.historyDB.mem = self.memLsit[index]
# self.historyDB.startTime = int(float(self.memLsit[index]))
# print(self.memLsit[index])
tagSet = self.historyDB.queryVarName()
self.model.clear()
# if not tagSet:
# QMessageBox.information(self, '提示', '当前工程历史趋势已损坏')
# return
for tag in tagSet:
item = QStandardItem(str(tag))
item.setCheckable(True)

@ -15,23 +15,23 @@ from .UserModel import UserTableModel
from utils import Globals
from model.UserModel.UserManage import UserManage
from Static import static
class UserWidgets(QtWidgets.QWidget):
def __init__(self, parent=None):
super(UserWidgets, self).__init__(parent)
self.setAttribute(Qt.WA_StyledBackground, True)
self.createBtn = QPushButton(QIcon('static/add.png'), '添加用户')
self.createBtn = QPushButton(QIcon(':/static/add.png'), '添加用户')
self.createBtn.setObjectName('forceBtn')
self.createBtn.setIconSize(QSize(22, 22))
self.createBtn.clicked.connect(self.createUser)
# self.importBtn = QPushButton(QIcon('static/import.png'), '导入变量')
# self.importBtn = QPushButton(QIcon(':/static/import.png'), '导入变量')
# self.importBtn.setObjectName('importBtn')
# self.importBtn.setIconSize(QSize(22, 22))
self.delBtn = QPushButton(QIcon('static/delete.png'), '批量删除')
self.delBtn = QPushButton(QIcon(':/static/delete.png'), '批量删除')
self.delBtn.setObjectName('delBtn')
self.delBtn.setIconSize(QSize(22, 22))
self.delBtn.clicked.connect(self.deleteUser)

@ -10,7 +10,7 @@ from PyQt5.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel,
QWidget)
from protocol.Celery.MBTCPMaster import app
from Static import static
class MessageWidget(QWidget):
def __init__(self, parent=None):
super(MessageWidget, self).__init__(parent)
@ -60,11 +60,11 @@ class MessageWidget(QWidget):
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 2)
self.setWindowTitle('报文查看')
self.setWindowIcon(QIcon('./Static/file.png'))
self.setWindowIcon(QIcon('./:/static/file.png'))
self.recvLabel.setText(QCoreApplication.translate("Form", u"\u63a5\u6536\u5230\u62a5\u6587", None))
self.sendLabel.setText(QCoreApplication.translate("Form", u"\u53d1\u9001\u7684\u62a5\u6587", None))
self.clearButton.setText("清空报文")
self.reButton.setText(QCoreApplication.translate("Form", u"\u505c\u6b62\u5237\u65b0", None))
self.reButton.setText('停止刷新')
self.decimaButton.setText('切换进制')
self.timer = QTimer(self)
@ -89,8 +89,10 @@ class MessageWidget(QWidget):
def stopRe(self):
if self.timer.isActive():
self.timer.stop()
self.reButton.setText('开始刷新')
else:
self.timer.start()
self.reButton.setText('停止刷新')
def addText(self):
self.recvEdit.clear()

@ -5,7 +5,7 @@ import qtawesome
from PyQt5 import QtGui,QtCore,QtWidgets
from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant, QSize
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QTableView, QMessageBox, QComboBox
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QTableView, QMessageBox, QComboBox, QStyleOptionViewItem
from protocol.Celery.MBTCPMaster import app as MBTCPMApp
@ -58,7 +58,7 @@ class VarTableModel(QAbstractTableModel):
def initTable(self):
self.datas = []
self.editableList = []
self.table.parent.initIcon()
proType = Globals.getValue('currentProType')
@ -76,6 +76,7 @@ class VarTableModel(QAbstractTableModel):
self.checkList = ['Unchecked'] * len(self.datas)
# self.layoutChanged.emit()
self.table.proxy.invalidate()
self.refreshComboBox()
def append_data(self, x):
@ -194,6 +195,24 @@ class VarTableModel(QAbstractTableModel):
self.datas[sourceRow], self.datas[destinationChild] = self.datas[destinationChild], self.datas[sourceRow]
self.table.proxy.invalidate()
def refreshComboBox(self):
# print(self.table.rowCount())
for i in range(len(self.datas)):
cbRow = str('cb' + str(i) + '5')
index = self.index(i, 5)
delegate = self.table.itemDelegate(index)
delegate.paint(self.table, QStyleOptionViewItem(), index)
try:
comboBox = getattr(delegate, cbRow)
except Exception as e:
continue
if self.datas[i][5] in [0, 1]:
comboBox.setCurrentIndex(self.datas[i][5])
elif self.datas[i][5] in [3, 4]:
comboBox.setCurrentIndex(self.datas[i][5] - 1)
else:
comboBox.setCurrentIndex(-1)
class ModBusTCPSlaveModel(VarTableModel):
def __init__(self, header, data: list, table = None):
'''
@ -211,10 +230,17 @@ class ModBusTCPSlaveModel(VarTableModel):
class VarButtonDelegate(QItemDelegate):
"""该类用于向单元格中添加按钮 任务表格"""
trendWidgetDict = {}
def __init__(self, parent=None):
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):
if not self.parent().indexWidget(index):
button1 = QPushButton(
@ -253,6 +279,7 @@ class VarButtonDelegate(QItemDelegate):
comboBox.addItem('BADC', 3)
comboBox.addItem('DCBA', 4)
comboBox.setCurrentText(self.parent().model.datas[index.row()][index.column()])
# comboBox.setMinimumWidth(30)
comboBox.currentIndexChanged.connect(self.indexChange)
@ -376,23 +403,26 @@ class VarButtonDelegate(QItemDelegate):
else:
varMes = model.datas[sender.index[0]]
name, des, varType, slaveID, address, min, max, order = str(varMes[3]), str(varMes[4]), str(varMes[5]), str(varMes[6]), str(varMes[7]), str(varMes[8]), str(varMes[9]), str(varMes[-1])
print(name, des, varType, slaveID, address, min, max, order)
# print(name, des, varType, slaveID, address, min, max, order)
if not name or not varType:
reply = QMessageBox.question(self.parent(),
'警告',
"有字段为空",
QMessageBox.Yes)
return
sender.isEdit = True
checkbox.setEnabled(False)
model.editableList.remove(sender.index[0])
if sender.oldName:
ModbusVarManage.editVar(name = sender.oldName, Nname = name, des = des, varType = varType, slaveID = slaveID, address = address, min = min, max = max, order = order)
if sender.oldName and ModBusVar.getByName(sender.oldName):
if sender.oldName == name or [varMes[3] for varMes in model.datas].count(name) < 2:
ModbusVarManage.editVar(name = sender.oldName, Nname = name, des = des, varType = varType, slaveID = slaveID, address = address, min = min, max = max, order = order)
else:
QMessageBox.information(self.parent(), '提示', '已有同名变量')
return
else:
ModbusVarManage.createVar(varName = name, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = order)
res = ModbusVarManage.createVar(varName = name, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = order)
if res:
QMessageBox.information(self.parent(), '提示', '已有同名变量')
return
sender.setIcon(qtawesome.icon('fa.pencil', color='#4c8cf2'))
rowIndex = sender.index[0]
varMes = ModbusVarManage.getByName(name)
@ -401,6 +431,10 @@ class VarButtonDelegate(QItemDelegate):
varMes.insert(2, '')
model.insert_data(varMes, rowIndex)
model.remove_row(rowIndex + 1)
sender.isEdit = True
checkbox.setEnabled(False)
model.editableList.remove(sender.index[0])
def delete_action(self):
@ -415,22 +449,23 @@ class VarButtonDelegate(QItemDelegate):
if model.table.parent._isPopenOpen:
sender = self.sender()
name = str(model.datas[sender.index[0]][3])
trend = ActualTrend(varName = name)
trend = self.trendWidget(varName = name)
trend.show()
class ModbusTypeBox(VarButtonDelegate):
class ModbusTypeBox(QItemDelegate):
def __init__(self, parent=None):
super(ModbusTypeBox, self).__init__(parent)
def paint(self, painter, option, index):
if not self.parent().indexWidget(index):
if index.column() == 5 and index.row() not in self.parent().model.editableList:
data = self.parent().model.datas[index.row()]
comBox = str('cb' + str(index.row()) + str(index.column()))
setattr(self, comBox, QComboBox(self.parent()))
# try:
# comboBox = getattr(self, comBox)
# except:
setattr(self, comBox, QComboBox())
comboBox = getattr(self, comBox)
# comboBox = getattr(self, comBox)
item = ['Coil Status', 'Input Status', 'Input Register', 'Holding Register']
comboBox.addItems(item)
@ -451,6 +486,7 @@ class ModbusTypeBox(VarButtonDelegate):
comboBox.setObjectName('ModbusTypeBox')
comboBox.setEditable(True)
comboBox.lineEdit().setAlignment(Qt.AlignCenter)
# comboBox.setMinimumWidth(200)
# comboBox.setEnabled(False)
h_box_layout = QHBoxLayout()
h_box_layout.addWidget(comboBox)
@ -474,6 +510,7 @@ class ModbusTypeBox(VarButtonDelegate):
index,
widget
)
self.parent().openPersistentEditor(index)
def indexChange(self):
sender = self.sender()

@ -190,9 +190,13 @@ class TcRtdButtonDelegate(VarButtonDelegate):
QMessageBox.Yes)
return
mv = temToMv(varType, float(value))
mv += float(compensation)
if not mv and mv != 0:
reply = QMessageBox.question(self.parent(),
'警告',
"输入值有误",
QMessageBox.Yes)
return
mv += float(compensation)
model.table.mvList[sender.index[0]] = mv
model.table.valueList[sender.index[0]] = float(value)
forceVars = Globals.getValue('forceVars')

@ -1,6 +1,7 @@
import time
from PyQt5.QtCore import QThread, pyqtSignal
from UI.TrendManage.ActualTrendWidget import ActualTrend
from protocol.TCP.RTDTC import RTDTCClient
from protocol.TCP.Analog import AnalogClient
from protocol.FF.FFSimulate import FFSimulate
@ -111,3 +112,6 @@ class HartSimulateThread(FFThread):
self.window.valueList = self.HartSimulate.readValue()
except Exception as e:
print(e)

@ -100,6 +100,7 @@ class VarTableView(QTableView):
self.header.setSectionResizeMode(0, QHeaderView.Fixed)
self.header.resizeSection(0, 70)
class HartTableView(VarTableView):

@ -19,7 +19,7 @@ from protocol.Celery.MBTCPSlave import app as MBTCPSApp
from protocol.TCP.TemToMv import temToMv
from protocol.TCP.Analog import getRealAO
import re
from Static import static
class VarWidgets(QtWidgets.QWidget):
_isPopenOpen = False
def __init__(self, parent=None):
@ -29,37 +29,37 @@ class VarWidgets(QtWidgets.QWidget):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
self.createBtn = QPushButton(QIcon('static/add.png'), '新建变量')
self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
self.createBtn.setObjectName('createBtn')
self.createBtn.setIconSize(QSize(22, 22))
self.createBtn.clicked.connect(self.createVar)
self.forceBtn = QPushButton(QIcon('static/start.png'), '批量强制')
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
self.forceBtn.setObjectName('forceBtn')
self.forceBtn.setIconSize(QSize(22, 22))
self.forceBtn.clicked.connect(self.forceVar)
self.clearBtn = QPushButton(QIcon('static/clear.png'), '清除颜色')
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
self.clearBtn.setObjectName('clearBtn')
self.clearBtn.setIconSize(QSize(22, 22))
self.clearBtn.clicked.connect(self.clearColour)
self.importBtn = QPushButton(QIcon('static/import.png'), '导入变量')
self.importBtn = QPushButton(QIcon(':/static/import.png'), '导入变量')
self.importBtn.setObjectName('importBtn')
self.importBtn.setIconSize(QSize(22, 22))
self.importBtn.clicked.connect(self.importVar)
self.exportBtn = QPushButton(QIcon('static/export.png'), '导出变量')
self.exportBtn = QPushButton(QIcon(':/static/export.png'), '导出变量')
self.exportBtn.setObjectName('exportBtn')
self.exportBtn.setIconSize(QSize(22, 22))
self.exportBtn.clicked.connect(self.exportVar)
self.messageBtn = QPushButton(QIcon('static/message.png'), '查看报文')
self.messageBtn = QPushButton(QIcon(':/static/message.png'), '查看报文')
self.messageBtn.setObjectName('messageBtn')
self.messageBtn.setIconSize(QSize(22, 22))
self.messageBtn.clicked.connect(self.showMessage)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)
@ -268,7 +268,8 @@ class VarWidgets(QtWidgets.QWidget):
path = QFileDialog.getOpenFileName(self, "Choose File", "./","VarExcel (*.xlsx);;All Files (*)")[0]
if not path:
return
ModbusVarManage.importModbusVar(path)
result = ModbusVarManage.importModbusVar(path)
QMessageBox.question(self.parent(), '提示', result, QMessageBox.Yes)
self.varView.model.initTable()
def exportVar(self):
@ -286,17 +287,17 @@ class VarWidgets(QtWidgets.QWidget):
ProjectManage.startProtocol()
self._isPopenOpen = True
self.startProtocolBtn.setText('停止通讯')
self.startProtocolBtn.setIcon(QIcon('static/pause.png'))
self.startProtocolBtn.setIcon(QIcon(':/static/pause.png'))
else:
ProjectManage.closePopen()
self._isPopenOpen = False
self.startProtocolBtn.setText('开始通讯')
self.startProtocolBtn.setIcon(QIcon('static/startProtocol.png'))
self.startProtocolBtn.setIcon(QIcon(':/static/startProtocol.png'))
def initIcon(self):
self._isPopenOpen = False
self.startProtocolBtn.setText('开始通讯')
self.startProtocolBtn.setIcon(QIcon('static/startProtocol.png'))
self.startProtocolBtn.setIcon(QIcon(':/static/startProtocol.png'))
class HartWidgets(VarWidgets):
@ -306,7 +307,7 @@ class HartWidgets(VarWidgets):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)
@ -351,24 +352,24 @@ class TcRtdWidgets(VarWidgets):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
# self.createBtn = QPushButton(QIcon('static/add.png'), '新建变量')
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
# self.createBtn.setObjectName('createBtn')
# self.createBtn.setIconSize(QSize(22, 22))
# self.createBtn.clicked.connect(self.createVar)
self.forceBtn = QPushButton(QIcon('static/start.png'), '批量强制')
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
self.forceBtn.setObjectName('forceBtn')
self.forceBtn.setIconSize(QSize(22, 22))
self.forceBtn.clicked.connect(self.forceVar)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)
self.clearBtn = QPushButton(QIcon('static/clear.png'), '清除颜色')
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
self.clearBtn.setObjectName('clearBtn')
self.clearBtn.setIconSize(QSize(22, 22))
self.clearBtn.clicked.connect(self.clearColour)
@ -463,22 +464,22 @@ class AnalogWidgets(VarWidgets):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
# self.createBtn = QPushButton(QIcon('static/add.png'), '新建变量')
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
# self.createBtn.setObjectName('createBtn')
# self.createBtn.setIconSize(QSize(22, 22))
# self.createBtn.clicked.connect(self.createVar)
self.forceBtn = QPushButton(QIcon('static/start.png'), '批量强制')
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
self.forceBtn.setObjectName('forceBtn')
self.forceBtn.setIconSize(QSize(22, 22))
self.forceBtn.clicked.connect(self.forceVar)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)
self.clearBtn = QPushButton(QIcon('static/clear.png'), '清除颜色')
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
self.clearBtn.setObjectName('clearBtn')
self.clearBtn.setIconSize(QSize(22, 22))
self.clearBtn.clicked.connect(self.clearColour)
@ -577,22 +578,22 @@ class FFSimulateWidgets(VarWidgets):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
# self.createBtn = QPushButton(QIcon('static/add.png'), '新建变量')
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
# self.createBtn.setObjectName('createBtn')
# self.createBtn.setIconSize(QSize(22, 22))
# self.createBtn.clicked.connect(self.createVar)
self.forceBtn = QPushButton(QIcon('static/start.png'), '批量强制')
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
self.forceBtn.setObjectName('forceBtn')
self.forceBtn.setIconSize(QSize(22, 22))
self.forceBtn.clicked.connect(self.forceVar)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)
self.clearBtn = QPushButton(QIcon('static/clear.png'), '清除颜色')
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
self.clearBtn.setObjectName('clearBtn')
self.clearBtn.setIconSize(QSize(22, 22))
self.clearBtn.clicked.connect(self.clearColour)
@ -673,7 +674,7 @@ class HartSimulateWidgets(VarWidgets):
def setupUI(self):
self.setAttribute(Qt.WA_StyledBackground, True)
self.startProtocolBtn = QPushButton(QIcon('static/startProtocol.png'), '开始通讯')
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
self.startProtocolBtn.setObjectName('startProtocolBtn')
self.startProtocolBtn.setIconSize(QSize(22, 22))
self.startProtocolBtn.clicked.connect(self.startProtocol)

@ -8,6 +8,7 @@ import time
import sys
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create('Fusion'))

@ -107,7 +107,7 @@ class register:
# str = str
k = des(self.Des_Key, CBC, self.Des_IV, pad=None, padmode=PAD_PKCS5)
EncryptStr = k.encrypt(str)
print(type(EncryptStr))
# print(type(EncryptStr))
return base64.b64encode(EncryptStr) # 转base64编码返回
# 获取注册码,验证
@ -123,7 +123,7 @@ class register:
key_decrypted = str(self.DesDecrypt())
if content != 0 and key_decrypted != 0:
if content != key_decrypted:
print("wrong register code, please check and input your register code again:")
# print("wrong register code, please check and input your register code again:")
self.regist()
elif content == key_decrypted:
return True

@ -20,7 +20,7 @@ def parseDate(date_string: str):
class HistoryDBManage():
org = "DCS"
# bucket = "history"
url = "http://localhost:6324"
url = "http://localhost:8086"
def __init__(self, bucket, mem = None, isCelery = True):
self.getToken(isCelery)
@ -95,7 +95,11 @@ class HistoryDBManage():
|> range(start: {})\
|> filter(fn:(r) => r._measurement == "{}")\
|> filter(fn:(r) => r._field == "value")'.format(self.bucket, self.startTime, self.mem)
results = self.queryApi.query(query, org = self.org)
try:
results = self.queryApi.query(query, org = self.org)
except Exception as e:
BucketsApi(self.client).create_bucket(bucket_name = self.bucket, org = self.org)
return tagSet
for result in results:
for record in result.records:
tagSet.add(record['varName'])

@ -109,15 +109,18 @@ class ProjectManage(object):
# 删除工程
name = str(name)
# print(name)
print(Globals.getValue('currentPro'))
# print(Globals.getValue('currentPro'))
Client.initDB()
if name == Globals.getValue('currentPro'):
Globals.getValue('currentProDB').close()
if not Project.getByName(name):
print('不存在的工程', Project.getByName(name))
return
try:
shutil.rmtree(os.path.join('project', name))
if name == Globals.getValue('currentPro'):
self.closePopen()
Globals.getValue('currentProDB').close()
Globals.setValue('currentPro', None)
QTimer.singleShot(1000, lambda:shutil.rmtree(os.path.join('project', name)))
except OSError as e:
print(e)
Project.deleteProject(name = name)
@ -150,6 +153,8 @@ class ProjectManage(object):
if proType == '7':
Globals.getValue('FFThread').start()
# initDB
@classmethod
def closePopen(self):
@ -256,24 +261,50 @@ class ProjectManage(object):
curTime = float("{:.5f}".format(curTime))
cursor.execute('insert into InfluxMem (mem) values ({})'.format(str(curTime)))
historyDB = HistoryDBManage(mem = curTime, bucket = projectName, isCelery = False)
historyDB = HistoryDBManage(mem = curTime, bucket = projectName, isCelery = True)
return historyDB
@classmethod
def editProject(self, name, Nname, des):
def editProject(self, name, Nname, des, proType):
# 修改工程信息
name = str(name)
Nname = str(Nname)
des = str(des)
Client.initDB()
if Project.getByName(Nname):
if name == Nname:
if name == Globals.getValue('currentPro'):
self.editCurProject(name, Nname, proType, des)
return
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
QTimer.singleShot(1000, lambda:os.rename(os.path.join('project', name), os.path.join('project', Nname)))
elif Project.getByName(Nname):
return '已有同名工程'
elif not Project.getByName(name):
print('不存在的工程')
return
else:
if name == Globals.getValue('currentPro'):
self.editCurProject(name, Nname, proType, des)
return
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
os.rename(os.path.join('project', name), os.path.join('project', Nname))
QTimer.singleShot(1000, lambda:os.rename(os.path.join('project', name), os.path.join('project', Nname)))
@classmethod
def editCurProject(self, name, Nname, proType, des):
self.closePopen()
Globals.getValue('currentProDB').close()
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
QTimer.singleShot(1000, lambda:self.reNameCurProDir(name, Nname, proType))
Globals.getValue('MainWindow').varWidget.initIcon()
Globals.setValue('currentPro', Nname)
@classmethod
def reNameCurProDir(self, name, Nname, proType):
os.rename(os.path.join('project', name), os.path.join('project', Nname))
self.switchProject(Nname, proType)
@classmethod
def getAllProject(self):
@ -346,14 +377,14 @@ class ProjectManage(object):
zipf.extractall('project')
project = Project()
projectList = []
projectList = []
for n in zipProjects:
jsonPath = os.path.join('project', n, 'config', 'config.json')
with open(jsonPath, 'r') as f:
data = json.load(f)
proType = data['ProjectType']
des = data['description']
project = Project()
project.createProject(n, proType, des)
projectList.append(n)

@ -44,27 +44,39 @@ class ModbusVarManage(object):
maxIndex = index
# 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:
print('表头错误')
# print('表头错误')
return '表头错误'
errorConList = []
for index, row in enumerate(list(ws.iter_rows())[1:]):
try:
l = [str(x.value) for x in row]
varName = l[nameIndex]
varType = l[typeIndex]
des = l[desIndex]
des = '' if l[desIndex] == 'None' else l[desIndex]
address = l[addrIndex]
slaveID = l[slaveIndex]
min = l[minIndex]
max = l[maxIndex]
ModBusVarModel = ModBusVar()
if ModBusVarModel.getByName(varName):
ModBusVarModel.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVarModel.varName == varName)
min = '' if l[minIndex] == 'None' else l[minIndex]
max = '' if l[maxIndex] == 'None' else l[maxIndex]
if {varName, varType, address, slaveID} & {'None'}:
errorConList.append('{}行导入失败,有关键字段为空'.format(str(index + 1)))
continue
if varType not in ['0', '1', '3', '4']:
errorConList.append('{}行导入失败,变量类型有误'.format(str(index + 1)))
continue
if ModBusVar.getByName(varName):
ModBusVar.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVar.varName == varName).execute()
else:
ModBusVarModel = ModBusVar()
ModBusVarModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int')
except Exception as e:
print(e)
return '{}行导入出错'.format(index + 1)
errorConList.append('{}行导入失败,{}'.format(str(index + 1), str(e)))
continue
else:
if errorConList:
return '\r\n'.join(errorConList)
else:
return '导入成功'
@classmethod
def exportModbusVar(self, excelPath):
@ -96,7 +108,7 @@ class ModbusVarManage(object):
max = str(max)
order = order
if ModBusVar.getByName(name):
print('已有同名变量')
return 1
else:
varModel = ModBusVar()
varModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = order)

@ -94,7 +94,7 @@ def setValue(self, name, varType, slaveID, address, value, order): # 写入变
slaveID = int(slaveID)
address = int(address) - self.offset
varType = str(varType)
print(address, 555555555555555555)
# print(address, 555555555555555555)
if varType == '4':
self.TcpModbus.writeSingleRegister(slaveId = slaveID, address = address, outputValue = value, order = order)
elif varType == '0':

@ -1,5 +1,5 @@
from pythonnet import load
load('coreclr')
# load('coreclr')
import clr # 与其他模块不同此处不直接导入pythonnet 而是导入clrpython与c#交互核心)
dll_path = 'protocol\\FF\\NationalInstruments.Fieldbus' # 为了方便理解这里给到dll所在的绝对路径且包含dll文件本身
clr.AddReference(dll_path) #加载c#库

@ -15,12 +15,12 @@ class HartProtocol(object):
for index, address in enumerate(self.addressList):
value = self.rtuMaster.readHoldingRegisters(slaveId = 1, startAddress = address, varNums = 2, order = 'ABCD')
valueList.append(value)
print(self.addressList, valueList)
# print(self.addressList, valueList)
return valueList
def writeValue(self, devIndex, elemIndex, value):
address = self.addressList[devIndex * 5 + elemIndex]
print(address)
# print(address)
self.rtuMaster.writeSingleRegister(slaveId = 1, address = address, outputValue = value, order = 'DCBA')
if __name__ == '__main__':

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

@ -3,7 +3,7 @@ def _init():#初始化
_globalDict = {}
_globalDict['ModBusTcp'] = 0
_globalDict['ModBusRtu'] = 1
_globalDict['currentPro'] = -1 # 当前工程名
_globalDict['currentPro'] = 0 # 当前工程名
_globalDict['currentProDB'] = 0 # 当前工程的数据库连接
_globalDict['varTable'] = 0 # 变量表
_globalDict['userTable'] = 0 # 用户表

Loading…
Cancel
Save