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

2 years ago
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
2 years ago
from utils.DBModels.DeviceModels import DeviceDB
2 years ago
# from utils.DBModels.ClientModels import DeviceDB
2 years ago
jsonCon = json.dumps([{
"id": 0,
"type": "AO",
"nums": 4,
"bytes": 2,
},
{
"id": 1,
"type": "AI",
"nums": 8,
"bytes": 4,
}])
class Area():
2 years ago
startAddress = None
2 years ago
endAddress = None
bytes = None
2 years ago
type = None
addressList = []
2 years ago
def __init__(self):
2 years ago
pass
2 years ago
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,
2 years ago
2 years ago
}])
else:
jsonCon = json.loads(DeviceDB.getByName(deviceName=deviceName).areaJson)
id = jsonCon[-1]["id"] + 1
jsonCon.append({
"id": id,
"type": type,
"nums": nums,
"bytes": bytes,
2 years ago
2 years ago
})
areaJson = json.dumps(jsonCon)
DeviceDB.update(areaJson=areaJson).where(DeviceDB.deviceName == deviceName).execute()
2 years ago
2 years ago
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