UART read data with a delay.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

UART read data with a delay.

Post by prem111 » Wed Aug 11, 2021 8:14 am

Hi, im have problem in my update library (link below).

In def write16 (272 line), The module echoes what it got, unfortunately my response data is delayed, what am I doing wrong? I would be very grateful for your help !



RuntimeError("Response doesn't match send data")

Sorry to write about it here, but the users here are my hope.
Last edited by prem111 on Wed Aug 11, 2021 7:57 pm, edited 1 time in total.

User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: UART read data with a delay.

Post by Roberthh » Wed Aug 11, 2021 9:10 am

You did not tell which board you are using, but the general principle is the same. When you call uart.write(), the device will start to send the data you have provided. There are various buffers in the send stack and the uart hardware itself. So the call to write() will return after it has put the data into these buffers. The transmitting can continue to happen even after the return. If you call then immediately read(), you will only get what has been sent (and received) so far, not the full message. uart.read((n) will return up to n bytes, but may return less if a timeout occurs.
One solution for you is to set a timeout for read matching the number of bytes sent and the data rate. Or you can simply wait a while before calling read().

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: UART read data with a delay.

Post by prem111 » Wed Aug 11, 2021 11:59 am

Roberthh wrote:
Wed Aug 11, 2021 9:10 am
You did not tell which board you are using, but the general principle is the same. When you call uart.write(), the device will start to send the data you have provided. There are various buffers in the send stack and the uart hardware itself. So the call to write() will return after it has put the data into these buffers. The transmitting can continue to happen even after the return. If you call then immediately read(), you will only get what has been sent (and received) so far, not the full message. uart.read((n) will return up to n bytes, but may return less if a timeout occurs.
One solution for you is to set a timeout for read matching the number of bytes sent and the data rate. Or you can simply wait a while before calling read().

Thanks Roberthh

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: UART read data with a delay.

Post by prem111 » Wed Aug 11, 2021 1:28 pm

Im have one another question, in def _write_data (544 line), I'm not sure if it does the right thing for the package following this example:
PACKET [1024 + 2] = DATE [1024] + CHKSUM [2]
I do not know if I calculate the checksum correctly, and i do not know data write correctly.

Of course my packet len is 256, in example 1024.

User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: UART read data with a delay.

Post by Roberthh » Wed Aug 11, 2021 1:42 pm

How could I tell if I do not know what the whole package is expected to do.

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: UART read data with a delay.

Post by prem111 » Wed Aug 11, 2021 1:47 pm

Thanks for help !
Last edited by prem111 on Wed Aug 11, 2021 7:57 pm, edited 1 time in total.

Post Reply