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.
UART read data with a delay.
UART read data with a delay.
Last edited by prem111 on Wed Aug 11, 2021 7:57 pm, edited 1 time in total.
Re: UART read data with a delay.
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().
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().
Re: UART read data with a delay.
Roberthh wrote: ↑Wed Aug 11, 2021 9:10 amYou 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
Re: UART read data with a delay.
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:
Of course my packet len is 256, in example 1024.
I do not know if I calculate the checksum correctly, and i do not know data write correctly.PACKET [1024 + 2] = DATE [1024] + CHKSUM [2]
Of course my packet len is 256, in example 1024.
Re: UART read data with a delay.
How could I tell if I do not know what the whole package is expected to do.
Re: UART read data with a delay.
Thanks for help !
Last edited by prem111 on Wed Aug 11, 2021 7:57 pm, edited 1 time in total.