serial input


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3348
Posted: 12:46am 12 Jun 2025      

  Quote  INPUT$(n,#c) will wait until n characters have arrived from channel #c won't it?

  Manual, Functions said  INPUT$(nbr, [#]fnbr)
Will return a string composed of ‘nbr’ characters read from a file or serial communications port opened as 'fnbr'.
This function will return as many characters as are in the file or receive buffer up to ‘nbr’.
If there are no characters available it will immediately return with an empty string.
#0 can be used which refers to the console's input buffer.
The # is optional. Also see the OPEN command.
So no it won't wait.
The manual could be changed to read " This function will return as many characters as are in the file or receive buffer up to ‘nbr’, removing them from the buffer."
If there are more than n characters in the buffer the rest remain and Loc(#x) is adjusted.
In my previous program changing 255 to 11 (g$ = Input$(11,#1)) shows this.
> LIST
' Serial Rx test program on Pico B
SetPin gp1,gp0, com1 : Open "COM1:115200" As #1
g$ = Input$(255,#1) : g$="" 'purge the Rx buffer
Do
Do While Loc(#1) = 0 : Loop 'wait for data to start arriving

Pause 2 'allow time for the rest if the message to arrive
        'increase for longer message or lower baud rate
Print Loc(#1); " Bytes in Rx buffer",
g$ = Input$(11,#1)
Print g$;
Loop
>
> RUN
21 Bytes in Rx buffer  12-06-2025  10 Bytes in Rx buffer       11:02:15
21 Bytes in Rx buffer  12-06-2025  10 Bytes in Rx buffer       11:02:16
21 Bytes in Rx buffer  12-06-2025  10 Bytes in Rx buffer       11:02:17
21 Bytes in Rx buffer  12-06-2025  10 Bytes in Rx buffer       11:02:18
21 Bytes in Rx buffer  12-06-2025  10 Bytes in Rx buffer       11:02:19

Edited 2025-06-12 11:25 by phil99