main
“zcw” 2 years ago
parent f08f3fce2d
commit 69f073aab2

@ -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()

@ -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': # 小端模式

Loading…
Cancel
Save