I am using a MAX1486 and need to set DE = 1 pin for transmitting and DE = 0 for receiving.
Did anybody do this before?
It works the first time the client polls the data. But then the server seems to hear its own answer (server/sync.py handles it on line 107) and after that the server will not answer any more.
Please find code at the end.
Thank you in advance.
scadad-server - DEBUG - scada_server.py:316 - SCADA Modbus Table update daemon started.
scadad-server - INFO - scada_server.py:701 - Start ModbusSerialServer with server address '1'
scadad-server - INFO - scada_server.py:702 - Baudrate: 38400, 8 N 1
scadad-server - DEBUG - scada_server.py:192 - Started thread to serve client
pymodbus.server.sync - DEBUG - sync.py:40 - Client Connected [/dev/ttyS4:/dev/ttyS4]
pymodbus.server.sync - DEBUG - sync.py:107 - 0x1 0x4 0x9c 0x3f 0x0 0x5 0x2e 0x55
pymodbus.server.sync - DEBUG - sync.py:122 - send: 01040a000007dc00070006000e5953
pymodbus.server.sync - DEBUG - sync.py:107 - 0x1 0x4 0xa 0x0 0x0 0x7 0xdc 0x0 0x7 0x0 0x6 0x0 0xe 0x59 0x53
pymodbus.server.sync - DEBUG - sync.py:107 - 0x1 0x4 0x9c 0x3f 0x0 0x5 0x2e 0x55
pymodbus.server.sync - DEBUG - sync.py:107 - 0x1 0x4 0x9c 0x3f 0x0 0x5 0x2e 0x55
class MyModbusSingleRequestHandler(ModbusSingleRequestHandler):
def send(self, message):
''' Send a request (string) to the network
:param message: The unencoded modbus response
'''
# HALF-Duplex, set DE=1 to transmit
os.system("echo '1' > /sys/class/gpio/gpio88/value")
to_return = ModbusSingleRequestHandler.send(self, message)
# HALF-Duplex, set DE=0 to receive again
os.system("echo '0' > /sys/class/gpio/gpio88/value")
return to_return
class MyModbusSerialServer(ModbusSerialServer):
def __init__(self, context, framer=None, identity=None, **kwargs):
#call constructor from parent class
ModbusSerialServer.__init__(self, context, framer=ModbusRtuFramer, identity=identity, **kwargs)
def My_build_handler(self):
request = self.socket
request.send = request.write
request.recv = request.read
handler = MyModbusSingleRequestHandler(request,
(self.device, self.device), self)
return handler
def serve_forever(self):
log.debug("Started thread to serve client")
handler = self.My_build_handler()
while True: handler.handle()
def mani(debug):
s = MyModbusSerialServer(context, bytesize=bytesize, parity=parity,
stopbits=stopbits, baudrate=baudrate, port="/dev/ttyS4",
timeout=0.1)
try:
log.info("Start ModbusSerialServer with server address '%i'" % ServerUnitId)
log.info("Baudrate: %s, %s %s %s", baudrate, bytesize, parity, stopbits)
s.serve_forever()
except KeyboardInterrupt:
#stop modbus server and thread
s.server_close()
t.running = False