Getting input from console by reading UART_0

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Getting input from console by reading UART_0

Postby zliudr » Sat Nov 16, 2019 10:30 pm

I want to do some simple async input via UART_0 and pass that through to other UARTs. Instead of doing scanf or getc, can I simply read UART_0 or will that cause core to crash since some other task is probably monitoring UART_0 and I suspect read and write on uarts are not thread safe (and shouldn't be anyway).

I would like to read stdin without having to hit enter, in case you wonder why I wanted to do this.

Thanks.

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: Getting input from console by reading UART_0

Postby mikemoy » Sun Nov 17, 2019 12:12 am

int ch = fgetc(stdin);

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: Getting input from console by reading UART_0

Postby zliudr » Sun Nov 17, 2019 12:25 am

Thanks Mike!

I just tried getchar(). It looks like getchar() does NOT block execution so I can get characters in real time but if I copy/paste, it is too fast to catch all characters. I have a 100ms delay in the loop that catches the characters. Isn't there a buffer for console input?

Will getc(stdin) have a buffer but then has to wait for enter? I'll try and post back.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: Getting input from console by reading UART_0

Postby zliudr » Sun Nov 17, 2019 12:30 am

No, getc() also doesn't seem to be buffered. I copy and pasted 14 bytes of text to console, and esp32 got about 8. Why is it not buffered? :roll:

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: Getting input from console by reading UART_0

Postby mikemoy » Mon Nov 18, 2019 3:31 am

You need to create your own buffering scheme. There is an example of this in the examples directory.

Who is online

Users browsing this forum: Google [Bot] and 118 guests