You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.5 KiB
Python
109 lines
2.5 KiB
Python
import json
|
|
|
|
import collections
|
|
import time
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QMdiArea, QAction, QInputDialog, QDialog, QFormLayout, QLineEdit, \
|
|
QMdiSubWindow, QDialogButtonBox, QWidget, QComboBox, QTabBar, QTabWidget, QGridLayout, QLabel, QPushButton, QSpacerItem, QSizePolicy, QHBoxLayout, QTableWidget
|
|
|
|
from model.ProjectModel.DeviceManage import DevicesManange
|
|
from protocol.ModBus.TCPMaster import TcpMaster
|
|
from utils.DBModels.DeviceModels import DeviceDB
|
|
|
|
# from utils.DBModels.ClientModels import DeviceDB
|
|
|
|
jsonCon = json.dumps([{
|
|
"id": 0,
|
|
"type": "AO",
|
|
"nums": 4,
|
|
"bytes": 2,
|
|
},
|
|
{
|
|
"id": 1,
|
|
"type": "AI",
|
|
"nums": 8,
|
|
"bytes": 4,
|
|
}])
|
|
|
|
|
|
class Area():
|
|
startAddress = None
|
|
endAddress = None
|
|
bytes = None
|
|
type = None
|
|
addressList = []
|
|
valueType = 'ABCD'
|
|
def __init__(self):
|
|
pass
|
|
|
|
|
|
def writeValues(self):
|
|
self.masterWriteValues = TcpMaster('127.0.0.2', 502)
|
|
self.slaveWriteValues = TcpMaster('127.0.0.1', 502)
|
|
print(self.masterValues,'sssssss')
|
|
self.masterWriteValues.writeSingleRegister(1, 0, self.masterValues)
|
|
self.slaveWriteValues.writeSingleRegister(1, 0, self.slaveRealtimeValue)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Devices():
|
|
areas = []
|
|
startAddress = None
|
|
endAddress = None
|
|
|
|
|
|
def __init__(self, jsonCon=[]):
|
|
for areaJson in jsonCon:
|
|
self.areas.append(Area(areaJson))
|
|
|
|
def addAreas(self, type, nums, bytes, deviceName):
|
|
if DeviceDB.getByName(deviceName=deviceName).areaJson is None:
|
|
jsonCon = ([{
|
|
"id": 1,
|
|
"type": type,
|
|
"nums": nums,
|
|
"bytes": bytes,
|
|
|
|
}])
|
|
else:
|
|
jsonCon = json.loads(DeviceDB.getByName(deviceName=deviceName).areaJson)
|
|
id = jsonCon[-1]["id"] + 1
|
|
jsonCon.append({
|
|
"id": id,
|
|
"type": type,
|
|
"nums": nums,
|
|
"bytes": bytes,
|
|
|
|
})
|
|
areaJson = json.dumps(jsonCon)
|
|
DeviceDB.update(areaJson=areaJson).where(DeviceDB.deviceName == deviceName).execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getAllDevice(self):
|
|
# 查询所有设备
|
|
devices = DeviceDB.get_all()
|
|
if devices is 'error':
|
|
return
|
|
l = []
|
|
for x in devices:
|
|
l.append([x.deviceName, x.proType, x.masterSlaveModel, x.areaJson])
|
|
return l
|
|
|
|
def writeAreas(self):
|
|
pass
|
|
|
|
|
|
|
|
|
|
|