Repository navigation
Open
Description
Hi all,
how to create an RTU slave with umodbus on the COM6 port?
Can I query it with "minimalmodbus"?
#!/usr/bin/env python
from serial import Serial
from collections import defaultdict
from umodbus.server.serial import get_server
from umodbus.server.serial.rtu import RTUServer
s = Serial('COM6')
print(s)
s.timeout = 10
data_store = defaultdict(int)
app = get_server(RTUServer, s)
@app.route(slave_ids=[1], function_codes=[3, 4], addresses=list(range(0, 32)))
def read_data_store(slave_id, function_code, address):
"""" Return value of address. """
return data_store[address]
@app.route(slave_ids=[1], function_codes=[6, 16], addresses=list(range(0, 32)))
def write_data_store(slave_id, function_code, address, value):
"""" Set value for address. """
data_store[address] = value
write_data_store(1,16,3,784)
write_data_store(1,16,24,678)
rdata1 = read_data_store(1,4,3)
print(rdata1)
rdata2 = read_data_store(1,4,24)
print(rdata2)
if __name__ == '__main__':
try:
app.serve_forever()
print(rdata1)
finally:
app.shutdown()
app.server_close()
With "minimalmodbus" I don't get any answer.
minimalmodbus.Instrument<id=0x9abcd0, address=1, mode=rtu, close_port_after_each_call=False, precalculate_read_size=True, debug=True, serial=Serial<id=0x9ab930, open=True>(port='COM1', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)>
Is this the right procedure ?
Thanks
Metadata
Metadata
Assignees
Labels
No labels
Activity
OrangeTux commentedon Jan 2, 2020
Can you post the code of your client?
patfrench commentedon Jan 2, 2020
ok !
maybe a problem connection with my converter ?
patfrench commentedon Jan 3, 2020
Hi,
I'm sorry : problem connection between RS485 adaptator
The code of my master
Doesn't work every time. problem time ? i am on same PC
Thanks