Hi,
I'm looking for a modbus library for micropython that will allow me to set up my ESP32 board as a modbus RTU (serial) slave.
Has anyone had any experience getting either pymodbus or umodbus working with a recent micropython on an ESP32?
Links here:
pymodbus: https://github.com/riptideio/pymodbus
umodbus: https://github.com/AdvancedClimateSystems/umodbus/
Thanks,
Justin.
Modbus libraries with micropython - pymodbus and umodbus
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Modbus libraries with micropython - pymodbus and umodbus
I suggest you do a forum search. This has been discussed before but I'm not sure if anyone has implemented a solution.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Modbus libraries with micropython - pymodbus and umodbus
Yeah I did a forum search before posting. I could only find old data and nothing definitive about serial RTU slaves (modbus server).
However, for reference, I did find this when Googling: https://github.com/sfera-labs/pycom-modbus which looks promising.
Cheers,
Justin.
However, for reference, I did find this when Googling: https://github.com/sfera-labs/pycom-modbus which looks promising.
Cheers,
Justin.
Re: Modbus libraries with micropython - pymodbus and umodbus
Hello,
I did some research and it could be that in order to properly
support the Modbus RTU protocol the drive enable signal
either has to be supported by hardware (RTS pin) or
in the driver by interrupts:
Ref. ST Application note AN3070 regarding the Driver Enable signal:
https://www.st.com/resource/en/applicat ... 249778.pdf
For some application with low speed it could be that it is acceptable
to handle this signal in user space code (as is done by pycom-modbus).
Ref : https://minimalmodbus.readthedocs.io/en ... ation.html
I suspect commercial system like PLC will not waste any bandwidth and immediately
send a reply inside the Modbus RTU timing frame and this would probably lead
to a partial read when handle this signal in user space code.
Currently the Micropython does not support this signal, but should be easy to add.
This could be done by passing "flow = RS485" to the driver and the interrupt
set up to drive the RST pin when transmitting.
Also address filtering should ideally be handled by the driver as messages
from the master is read by all slaves and could flood the user application
otherwise. For example by passing a address byte string to match:
slave_address = b'\x02'
to match at the start of message.
Runar
I did some research and it could be that in order to properly
support the Modbus RTU protocol the drive enable signal
either has to be supported by hardware (RTS pin) or
in the driver by interrupts:
Ref. ST Application note AN3070 regarding the Driver Enable signal:
https://www.st.com/resource/en/applicat ... 249778.pdf
For some application with low speed it could be that it is acceptable
to handle this signal in user space code (as is done by pycom-modbus).
Ref : https://minimalmodbus.readthedocs.io/en ... ation.html
I suspect commercial system like PLC will not waste any bandwidth and immediately
send a reply inside the Modbus RTU timing frame and this would probably lead
to a partial read when handle this signal in user space code.
Currently the Micropython does not support this signal, but should be easy to add.
This could be done by passing "flow = RS485" to the driver and the interrupt
set up to drive the RST pin when transmitting.
Also address filtering should ideally be handled by the driver as messages
from the master is read by all slaves and could flood the user application
otherwise. For example by passing a address byte string to match:
slave_address = b'\x02'
to match at the start of message.
Runar
Re: Modbus libraries with micropython - pymodbus and umodbus
Hi,
Just proposed an implementation to pass flow control argument: https://github.com/micropython/micropython/pull/5567
--
Germain
Just proposed an implementation to pass flow control argument: https://github.com/micropython/micropython/pull/5567
--
Germain
Re: Modbus libraries with micropython - pymodbus and umodbus
Hi!
I never used any software flow control for RS485 at least for "standard" 485 IC's.
Below is what I used for years, and tested up to 115200 (that's just for concept of proof), but in field never used that speed.
https://www.programmersought.com/article/43706543/
Hope this help
I never used any software flow control for RS485 at least for "standard" 485 IC's.
Below is what I used for years, and tested up to 115200 (that's just for concept of proof), but in field never used that speed.
https://www.programmersought.com/article/43706543/
Hope this help