hi,
is there any readline /writeline implementation based on the asynchronous periph/uart implementation?
I want to use the uart in a arduino style and I miss an (blocking) interface like:
char buf[100];
int buf_size = 100;
int timeout = 100; //ms
int num_of_bytes = readline(uart, buf, buf_size, timeout);
also
int num_of_bytes_written = writeline(uart, line, line_len, timeout);
Best
Christian
hauke
26 January 2015 14:34
#2
Hi Christian,
as far as I know it's not in riot directly, but you coult implement it in a couple of lines (simplified -> no error handling...):
char buf[100];
int num_of_bytes = readline_stdin(buf, sizeof(buf));
OR
int num_of_bytes = readline(UART_x, buf, sizeof(buf);
int readline_stdin(char *buf, int size) {
int i = 0;
char c;
do {
c = getchar(); /** part of stdio.h */
buf[i++] = c;
} while (c == '\n');
return i;
}
int readline(uart_t uart, char *buf, int size) {
int i = 0;
char c;
do {
uart_read_blocking(uart, &c);
buf[i++] = c;
} while (c != '\n');
return i;
}
same for writing...
Cheers,
Hauke
hauke
26 January 2015 14:38
#3
Oh, forgot -> have a look at the system call _read and _write implementations (e.g. for the stm32f0), for the case UART0 is not defined, there you got a pretty good template how to implement some read/writeline features without using the uart_x_blocking functions....
Cheers,
Hauke