|
|
|
@ -6,7 +6,7 @@ from model.ProjectModel.AreaManage import Area
|
|
|
|
|
|
|
|
|
|
class Device():
|
|
|
|
|
areas = []
|
|
|
|
|
startAddress = None
|
|
|
|
|
startAddress = 0
|
|
|
|
|
endAddress = 0
|
|
|
|
|
protocolType = None
|
|
|
|
|
masterOrSlave = None
|
|
|
|
@ -16,21 +16,42 @@ class Device():
|
|
|
|
|
|
|
|
|
|
def addArea(self, type, nums, bytes):
|
|
|
|
|
area = Area()
|
|
|
|
|
area.startAddress = self.endAddress
|
|
|
|
|
area.type = type
|
|
|
|
|
area.startAddress = 0 if not self.startAddress else: self.endAddress + 1
|
|
|
|
|
area.length = self.getLength(nums, bytes)
|
|
|
|
|
area.endAddress = startAddress + length
|
|
|
|
|
self.endAddress = area.endAddress
|
|
|
|
|
area.addressList = list(range(area.startAddress, area.endAddress + 1, bytes))
|
|
|
|
|
areas.append(area)
|
|
|
|
|
|
|
|
|
|
def delArea(self, index):
|
|
|
|
|
self.areas.pop(index)
|
|
|
|
|
self.recalculateAddress()
|
|
|
|
|
|
|
|
|
|
def recalculateAddress(self):
|
|
|
|
|
for index, area in enumerate(self.areas):
|
|
|
|
|
area.startAddress = self.startAddress
|
|
|
|
|
area.endAddress = area.startAddress + area.length
|
|
|
|
|
area.addressList = list(range(area.startAddress, area.endAddress + 1, area.bytes))
|
|
|
|
|
else:
|
|
|
|
|
self.endAddress = area.endAddress
|
|
|
|
|
|
|
|
|
|
def editAreaType(self, index, type):
|
|
|
|
|
self.areas[index].type = type
|
|
|
|
|
|
|
|
|
|
def editAreaValueType(self, index, varType):
|
|
|
|
|
self.areas[index].valueType = varType
|
|
|
|
|
|
|
|
|
|
def getArea(self, index):
|
|
|
|
|
return self.areas[index]
|
|
|
|
|
|
|
|
|
|
def getLength(self, nums, bytes):
|
|
|
|
|
length = int(nums) * int(bytes)
|
|
|
|
|
if length % 2 != 0:
|
|
|
|
|
length = (length + 1) // 2
|
|
|
|
|
else:
|
|
|
|
|
length = length / 2
|
|
|
|
|
area.endAddress = startAddress + length
|
|
|
|
|
self.endAddress = area.endAddress
|
|
|
|
|
for index, address in range(area.startAddress, area.endAddress):
|
|
|
|
|
if index % bytes == 0 and self.protocolType == 'DP':
|
|
|
|
|
area.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getValueLength(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def writeAreas(self):
|
|
|
|
@ -38,7 +59,6 @@ class Device():
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def delAreas(self, deviceName, ids):
|
|
|
|
|
|
|
|
|
|
jsonCon = json.loads(DeviceDB.getByName(deviceName=deviceName).areaJson)
|
|
|
|
|
for id in ids:
|
|
|
|
|
jsonCon.pop(id - 1)
|
|
|
|
@ -64,6 +84,8 @@ class Device():
|
|
|
|
|
jsonCons = json.loads(jsonConsStr)
|
|
|
|
|
return jsonCons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DevicesManange():
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.dpMasterDevices = collections.OrderedDict()
|
|
|
|
@ -94,6 +116,28 @@ class DevicesManange():
|
|
|
|
|
device.startAddress = curProDict.values[-1].endAddress + 1
|
|
|
|
|
curProDict[deviceName] = device
|
|
|
|
|
|
|
|
|
|
def initDevices(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def delDevice(self):
|
|
|
|
|
for devicesDict in [self.paMasterDevices, self.paSlaveDevices, self.dpMasterDevices, self.dpSlaveDevices]:
|
|
|
|
|
if deviceName in devicesDict:
|
|
|
|
|
del deviceDict[deviceName]
|
|
|
|
|
self.recalculateAddress()
|
|
|
|
|
|
|
|
|
|
def recalculateAddress(self, deviceDict):
|
|
|
|
|
for devicesDict in [self.paMasterDevices, self.paSlaveDevices, self.dpMasterDevices, self.dpSlaveDevices]:
|
|
|
|
|
for index, (deviceName, device) in enumerate(ordered_dict.items()):
|
|
|
|
|
device.startAddress = 0 in index = 0 else: device = previousDevice.endAddress + 1
|
|
|
|
|
device.recalculateAddress()
|
|
|
|
|
previousDevice = device
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getDevice(self, deviceName):
|
|
|
|
|
for devicesDict in [self.paMasterDevices, self.paSlaveDevices, self.dpMasterDevices, self.dpSlaveDevices]:
|
|
|
|
|
if deviceName in devicesDict:
|
|
|
|
|
return devicesDict[deviceName]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def addAreas(self, type, nums, bytes, deviceName):
|
|
|
|
|
if DeviceDB.getByName(deviceName=deviceName).areaJson is None:
|
|
|
|
|