From 69f073aab2d241e9b58f0273795ab7dd53dac365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Czcw=E2=80=9D?= Date: Mon, 11 Sep 2023 14:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/ProjectModel/DeviceManage.py | 4 +++- protocol/ModBus/TCPMaster.py | 27 ++++----------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/model/ProjectModel/DeviceManage.py b/model/ProjectModel/DeviceManage.py index abe2707..1b2e121 100644 --- a/model/ProjectModel/DeviceManage.py +++ b/model/ProjectModel/DeviceManage.py @@ -66,11 +66,13 @@ class Device(): self.outputEndAddress = endAddress - def editArea(self, index, order, bytes): + def editArea(self, index, type, order, bytes): if type in ["DI", "AI"]: + self.inputAreas[index].type = type self.inputAreas[index].order = order self.inputAreas[index].bytes = bytes elif type in ["AO", "DO"]: + self.outputAreas[index].type = type self.outputAreas[index].order = order self.outputAreas[index].bytes = bytes # self.recalculateAddress() diff --git a/protocol/ModBus/TCPMaster.py b/protocol/ModBus/TCPMaster.py index 291b95a..90a000a 100644 --- a/protocol/ModBus/TCPMaster.py +++ b/protocol/ModBus/TCPMaster.py @@ -18,35 +18,16 @@ class TcpMaster(): # hooks.install_hook("modbus_tcp.TcpMaster.after_recv", afterRecv) # hooks.install_hook("modbus_tcp.TcpMaster.after_send", afterSend) - def writeMultipleRegister(self, slaveId, address, outputValue, order = 'ABCD'): + def writeMultipleRegister(self, slaveId, address, outputValue): try: - valueByte = [] - for i in outputValue: - if '.' not in str(i): - valueByte = outputValue - self.master.execute(slaveId, cst.WRITE_MULTIPLE_REGISTERS, starting_address=address, - output_value=valueByte) - else: - if order == 'ABCD': # 大端模式 - valueByte=(floatToABCD(i)) - elif order == 'DCBA': # 小端模式 - valueByte = floatToDCBA(outputValue) - elif order == 'BADC': - valueByte = floatToBADC(outputValue) - elif order == 'CDAB': - valueByte = floatToCDAB(outputValue) - self.master.execute(slaveId, cst.WRITE_MULTIPLE_REGISTERS, starting_address = address, output_value=valueByte) - address = address + 2 + self.master.execute(slaveId, cst.WRITE_MULTIPLE_REGISTERS, starting_address = address, output_value=valueByte) except Exception as e: return 'error' - def readHoldingRegisters(self, slaveId, startAddress, varNums, order = 'ABCD'): + def readHoldingRegisters(self, slaveId, startAddress, varNums): try: - if order == 'int': - value = self.master.execute(slaveId, cst.READ_HOLDING_REGISTERS, startAddress, varNums)[0] - else: - value = self.master.execute(slaveId, cst.READ_HOLDING_REGISTERS, startAddress, varNums) + value = self.master.execute(slaveId, cst.READ_HOLDING_REGISTERS, startAddress, varNums) # if order == 'ABCD': # 大端模式 # valueByte = ABCDToFloat(value) # elif order == 'DCBA': # 小端模式