Absolutly lost in ASYNCIO... please help #11369
Replies: 4 comments 3 replies
-
You are not lost, you are on the right track!!! Having 3 coros and uasyncio.gather seems perfect.
Some devices generate interrupts. That allows to serve the device with lower latency. In the interrupt service routine, you could for example read data from the device and store in a preallocated array and then use ThreadSafeFlag to signal that information is available. In coro_Device() you await that event and process the data with more time. For many situations, this additional complexity is not necessary, and it may be sufficient to poll the device periodically. Again, https://github.com/peterhinch/micropython-async is a invaluable resource for this topic. Servicing interrupts can be tricky, there are many restrictions (https://docs.micropython.org/en/latest/reference/isr_rules.html), so I think polling is preferable if the latency to serve the device allows that. |
Beta Was this translation helpful? Give feedback.
-
To add some general points about sockets in The other approach, which is simplest in most cases, is to use the stream mechanism. This uses polling of a blocking socket via |
Beta Was this translation helpful? Give feedback.
-
This should be a starting point. To make this code ready for production, exception handling and network error handling should be added. At least, a global asyncio exception handler should be added (see https://github.com/peterhinch/micropython-async/blob/master/v3/docs/TUTORIAL.md#511-global-exception-handler). Network reads should have timeout and exception handling. The code below can be tested with the curl command on the PC.
|
Beta Was this translation helpful? Give feedback.
-
It completly works!!! In a easiest way than synchro socket mode!!! Thank you very very much !!! To everyone, but specially @bixb922 and @peterhinch obviously. Now I'm gonna programing the device usung poll strategy. Thanks again. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone.
I've been reading a lot of documentation about asynio but I can't find wich methods use to reach the following objective:
All executing "at the same time" asynchronous. Waiting all the time for "interrups" of BT, Wifi or pin inputs.
Here is my code:
¿Somebody could help me to find the exact methods I must use to execute this code continuously without getting stuck in any coro and to be the sensation like different 3 threads waiting for interruptions?
Thanks to everyone.
Best regards.
Beta Was this translation helpful? Give feedback.
All reactions