Comments (7)
Hi!
Any idea?
Thank you in advance!
from awesome-micropython.
Hi @beyonlo
I'm not familiar with the linked library, or how deeply integrated it is with the pycom boards.
Have you reached out to them to see if they are working on a micropython version, or could provide any tips for porting it?
from awesome-micropython.
Hello @mcauser
Thank you for the reply.
Before answering you I did a research about your comments/suggestions.
I not reached the pycom, but they worked with damien with the ESP32 port, in that time (years ago). Here is the repo about MicroPython running on Pycom boards that are the ESP32 https://github.com/pycom/pycom-micropython-sigfox and here is the doc modules from them https://docs.pycom.io/firmwareapi/pycom/
So, I think that the most things is like on official MicroPython, but some do not have on Pycom MicoPython, like as uasyncio. I'm not a especilist in MicroPython, so I can't to tell much more.
ModBus Slave has two modes: the RTU that use the UART, and, the TCP Server, where this second use the sockets. In my review in the code (with my knowloges) I think that the ModBus RTU will be easier to port/work on official MicroPython because use just UART API. About the ModBus TCP where I would like to use with uasyncio with other applications, I wil need to learning a bit more.
I will to try to study/research/learning a bit more to try fix the errors when running in official MicroPython and try to works and change the API/socket :)
Any other tip will be great.
Ps: anyway, I will also keep looking on the internet if there is a ModBus Slave library for MicroPython :)
Thank you very much.
from awesome-micropython.
@beyonlo maybe I'm a few months to late to solve your issue. I had the same topic, so I forked, cleaned and improved the lib of https://github.com/sfera-labs/exo-sense-py-modbus into https://github.com/brainelectronics/micropython-modbus
It's available via upip
at https://pypi.org/project/micropython-modbus/
May you're also interested in a ModBus RTU-TCP bridge, so you can e.g. access a RTU slave device through a MicroPython TCP master device, as I did it here: https://github.com/brainelectronics/micropython-modules#modbus-bridge
from awesome-micropython.
Hello @brainelectronics
@beyonlo maybe I'm a few months to late to solve your issue. I had the same topic, so I forked, cleaned and improved the lib of https://github.com/sfera-labs/exo-sense-py-modbus into https://github.com/brainelectronics/micropython-modbus It's available via
upip
at https://pypi.org/project/micropython-modbus/May you're also interested in a ModBus RTU-TCP bridge, so you can e.g. access a RTU slave device through a MicroPython TCP master device, as I did it here: https://github.com/brainelectronics/micropython-modules#modbus-bridge
Great!! Excellent work!
I checked there in github and I noticed two things:
1. I see that the Master and Slave (the RTU and TCP) are all blocking. I mean, that the requests/response will block all application while not finish the operation. Do you have plans to use the uasyncio to have all that working in non-blocking operations (asynchronous mode)? That will be amazing.
I'm not expert, so I do not know what all is needed to be modified to works in all non-blocking, but I have tips that I beliave that you already know:
a) RTU: For non-blocking operations on the RTU (Master and Slave) the use of UART with asyncio.StreamReader()
and asyncio.StreamWriter()
instead uart.read()
and uart.write()
I think will be enough.
b) TCP: For the TCP using the uasyncio too, but the socket need to be created as non-blocking I think. Something like this:
import usocket as socket
sock = socket.socket()
sock.setblocking(False)
2. I see that the the RTU do not works with RS485, just with Serial RS232 and pure UART, because I see that has just tx and rx pins, not an extra pin (necessary for RS485), like as enable/disable the extra pin to send/receive data using ModBus protocol over RS485. Do you have plans to add support to works in RS485 too?
Thank you so much the this amazing work!
from awesome-micropython.
@beyonlo, thank you for the feedback!
Yes, I'm planning to go for a non blocking Implementations but I don't know when this will happen. Hopefully within the next two weeks, but I can't promise anything. But hey, how about a PR from your side :)
Regarding your missing control pin for modbus, you can either use a module with an built in flow control (simply search for "uart rs485 module") or use the control pin of Serial class that parameter is also available on the ModbusRTU class. It's there but I haven't tested it. It's a leftover from the forked repo.
from awesome-micropython.
Hello @brainelectronics
Yes, I'm planning to go for a non blocking Implementations but I don't know when this will happen. Hopefully within the next two weeks, but I can't promise anything.
That's great. Do not worry if will be exactly in the next two weeks :) The important is that you already has that intention, because non blocking (for TCP and RTU) is the perfect!
But hey, how about a PR from your side :)
I have no experience enough to do a PR for that, sorry. That example about the non-blocking socket (for the TCP) I get from this project that started to write a MicroPython ModBus protocol, but unfortunatly the author has no intention to finish him :(
https://github.com/eydam-prototyping/mp_modbus/blob/master/mp_modbus_slave.py#L161
For the non blocking on the RTU, that same project has a method that looks like works as non-blocking https://github.com/eydam-prototyping/mp_modbus/blob/master/mp_modbus_slave.py#L109 but that method is not using the asyncio.StreamReader(uart)
and asyncio.StreamWriter(uart)
, just uart.read()
, uart.write()
, uart.readline()
. But accordly with @peterhinch docs (he wrote many docs about uasyncio/non-blocking), is need to use asyncio.StreamReader(uart)
and asyncio.StreamWriter(uart)
to UART works really as non blocking, like as this example from him https://github.com/peterhinch/micropython-async/blob/master/v3/as_demos/auart.py
Regarding your missing control pin for modbus, you can either use a module with an built in flow control (simply search for "uart rs485 module") or use the control pin of Serial class that parameter is also available on the ModbusRTU class. It's there but I haven't tested it. It's a leftover from the forked repo.
Ohh, sorry, I was looking for a name like as "enable pin". I didn't notice about that name "control pin" (ctrl_pin
) - that is, of course, better than "enable" :) Well, with that ctrl_pin
, so the modbus are ready to works in RS485. I will test it soon :)
Thank you in advance!
from awesome-micropython.
Related Issues (20)
- Add HX710 driver HOT 1
- Add Husky Lens drivers HOT 1
- Add TCA9548A drivers HOT 1
- Add P10 32*16 LED panel display driver HOT 1
- Suggestion: Add utility to freeze file system and allow to mount it HOT 1
- Add Garmin Lidar LIte v3hp library HOT 1
- Add micropython-generic-thermistor HOT 1
- Add LD2410 Human Presence Sensor HOT 1
- Add YX5300 Serial MP3 Player HOT 1
- L3GD20H + LSM303DLHC based IMU driver include in Zumu Robot driver set HOT 1
- Add additional i2c LCD driver HOT 1
- add greyscale epaper display driver HOT 1
- Remove ad9850_signalgen HOT 1
- Add amazon.com to BOT_ALLOW_LIST for awesome_bot workflow HOT 1
- Machine Vision
- Add Max31865 RTD Temperature IC driver HOT 1
- Add a driver for the CS1237 24 bit ADC and for the HX710 24 bit ADC. HOT 2
- Add bitstruct-micropython
- New MAX7219 7 segment library
- Web-based file manager and webserver for ESP32
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome-micropython.