serial input


Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5619
Posted: 06:54am 11 Jun 2025      

  TassyJim said  
  Volhout said  
The problem is that you read 100 characters at a time.
Let's assume at a certain moment there are 105 characters in the UART buffer.
You read 100 (leaving 5) so LOC(#1) equals 5.

It loops, and you read 100. But there are only 5 in the buffer.
So it waits until it gets 100 characters, potentially eating 95 characters of the new message.


INPUT$() reads upto the given number and will return immediately with whatever there is. It does NOT wait.
Looping until LOC() = 0 is OK and a fast way to flush the buffer.

Jim


Thanks Jim, for correcting me.
I didn't know it would return immediately.
So why the DO LOOP. If you have a 256 buffer, why not use input$(255,#1)

Volhout