-
Our system is using ESP32 serial port heavily (we do a lot of processing on a lot of data) I just noticed an issue that when the system is busy, some data get lot on serial port. Here is my code of processing serial data:
I'm trying to accumulate data from port and process them when timeout happens.
Basically, the processing takes ~300-500ms. And to my understanding, during that time the onReadable() callback cannot be called, since it's a JS function. So, if I understand correctly, it may be necessary to modify the serial.c code to include a software buffer? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You are correct that the serial implementation uses the hardware FIFO and that can overflow if not read often enough. Depending on the baud rate, your 300-500 ms processing has the potential for overflows. One solution would be to add a software buffer to the serial implementation. That shouldn't be too difficult. Another approach would be to move the serial I/O to a worker. The worker runs in parallel, and can accumulate the data before passing it to the main task for processing. That has the advantage of keeping everything in JavaScript/TypeScript and being portable. I recall you mentioning that your hardware has lots of RAM, so a few KB for the worker won't be a concern. FWIW – your
Note that the |
Beta Was this translation helpful? Give feedback.
-
@phoddie quick question regarding using worker: from the document, it said there is a way to use worker class (instead of module? I guess...)
I'm still receiving an error message from the runtime stating that it cannot locate the 'simpleworker' module. Where I should place this class? |
Beta Was this translation helpful? Give feedback.
You are correct that the serial implementation uses the hardware FIFO and that can overflow if not read often enough. Depending on the baud rate, your 300-500 ms processing has the potential for overflows.
One solution would be to add a software buffer to the serial implementation. That shouldn't be too difficult. Another approach would be to move the serial I/O to a worker. The worker runs in parallel, and can accumulate the data before passing it to the main task for processing. That has the advantage of keeping everything in JavaScript/TypeScript and being portable. I recall you mentioning that your hardware has lots of RAM, so a few KB for the worker won't be a concern.
FWIW – your
on…