termios

CRTSCTS not define when compiling as C99

落爺英雄遲暮 提交于 2019-12-06 01:06:22
问题 I'm writing some serial code on a raspberry pi and switched to C99. When I did I started getting the error "error: ‘CRTSCTS’ undeclared (first use in this function)" $ c99 -M serial01.c | grep termios.h /usr/include/termios.h /usr/include/arm-linux-gnueabihf/bits/termios.h \ $ gcc -M serial01.c | grep termios.h /usr/include/termios.h /usr/include/arm-linux-gnueabihf/bits/termios.h \ using -M reveals 2 termios.h headers. the former does not contain a definition for CRTSCTS and the latter does.

Check for extra characters in Linux terminal buffer

♀尐吖头ヾ 提交于 2019-12-05 07:22:46
问题 I try to implement getch() function in Python, which should also return list of chars for special keys like F1-F12 and arrow keys. These special keys generate several chars in a sequence. Therefore getch() reads one char in blocking mode and then should check if there are extra chars in input buffer to fetch them too. I am using ioctl call together with termios.FIONREAD to get the number of bytes in the input buffer. It catches non-special key presses stacked in buffer, but misses extra

Linux - moving the console cursor visual

吃可爱长大的小学妹 提交于 2019-12-04 09:43:53
问题 I'm currently designing a CLI interface for linux, and for various reasons I am not able to use ncurses . I am using exclusively C++ and the Qt framework. Therefore, in order to have a user-friendly interface, I have to run this getch loop in a separate thread: https://stackoverflow.com/a/912796/3605689 Which basically means I have to implement all basic functionalities (such as backspace) by myself. I have already implemented command completion and command history(like when you press tab or

CRTSCTS not define when compiling as C99

十年热恋 提交于 2019-12-04 07:36:31
I'm writing some serial code on a raspberry pi and switched to C99. When I did I started getting the error "error: ‘CRTSCTS’ undeclared (first use in this function)" $ c99 -M serial01.c | grep termios.h /usr/include/termios.h /usr/include/arm-linux-gnueabihf/bits/termios.h \ $ gcc -M serial01.c | grep termios.h /usr/include/termios.h /usr/include/arm-linux-gnueabihf/bits/termios.h \ using -M reveals 2 termios.h headers. the former does not contain a definition for CRTSCTS and the latter does. I assume the standard c89 is using the good one and c99 not but I'm not sure since the result of the

How to make arrow keys and backspace work correctly when asking input from user in C program using termios.h?

拈花ヽ惹草 提交于 2019-12-03 13:43:16
问题 So I have the following code which basically just reads characters user inputs and prints them until 'q' is entered. #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<termios.h> int main(void) { char c; static struct termios oldtio, newtio; tcgetattr(0, &oldtio); newtio = oldtio; newtio.c_lflag &= ~ICANON; newtio.c_lflag &= ~ECHO; tcsetattr(0, TCSANOW, &newtio); printf("Give text: "); fflush(stdout); while (1) { read(0, &c, 1); printf("%c", c); fflush(stdout); if (c == 'q') {

How to make arrow keys and backspace work correctly when asking input from user in C program using termios.h?

落爺英雄遲暮 提交于 2019-12-03 04:44:22
So I have the following code which basically just reads characters user inputs and prints them until 'q' is entered. #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<termios.h> int main(void) { char c; static struct termios oldtio, newtio; tcgetattr(0, &oldtio); newtio = oldtio; newtio.c_lflag &= ~ICANON; newtio.c_lflag &= ~ECHO; tcsetattr(0, TCSANOW, &newtio); printf("Give text: "); fflush(stdout); while (1) { read(0, &c, 1); printf("%c", c); fflush(stdout); if (c == 'q') { break; } } printf("\n"); tcsetattr(0, TCSANOW, &oldtio); return 0; } In the beginning of the main

Linux - moving the console cursor visual

泄露秘密 提交于 2019-12-03 03:51:18
I'm currently designing a CLI interface for linux, and for various reasons I am not able to use ncurses . I am using exclusively C++ and the Qt framework. Therefore, in order to have a user-friendly interface, I have to run this getch loop in a separate thread: https://stackoverflow.com/a/912796/3605689 Which basically means I have to implement all basic functionalities (such as backspace) by myself. I have already implemented command completion and command history(like when you press tab or uparrow/downarrow in linux), but I can't figure out how to implement leftarrow/rightarrow (aka seeking

Raspberry Pi UART program in C using termios receives garbage (Rx and Tx are connected directly)

大兔子大兔子 提交于 2019-11-29 11:35:40
I have a simple program written in C which uses termios to send a basic string to the Raspberry Pi UART and attempts to read and output the response. The Rx and Tx pins on the Raspberry Pi are connected with a jumper so whatever is sent should be immediately received. Despite the program outputting that it successfully sent and received 5 characters for the chosen string ('Hello'), trying to print the contents of the buffer just produces one or two garbage characters. The program: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include

Detecting if a character device has disconnected in Linux in with termios api (c++)

笑着哭i 提交于 2019-11-28 07:03:29
问题 I am using the termios api in Linux to communicate with a serial device. I'm trying to detect if the device has disconnected so I can try to reconnect after some timeout. I have the following example code: while(1) { FD_ZERO(&rfds); FD_SET(tty_fd, &rfds); // have tried checking fcntl(tty_fd, F_GETFL); too // Blocking call to wait until we have data select(tty_fd+1, &rfds, NULL, NULL, NULL); // While we have data, collect it while (read(tty_fd, &c, 1)>0 && bytesRead++<200) { serialBuffer.push

Raspberry Pi UART program in C using termios receives garbage (Rx and Tx are connected directly)

守給你的承諾、 提交于 2019-11-28 05:14:58
问题 I have a simple program written in C which uses termios to send a basic string to the Raspberry Pi UART and attempts to read and output the response. The Rx and Tx pins on the Raspberry Pi are connected with a jumper so whatever is sent should be immediately received. Despite the program outputting that it successfully sent and received 5 characters for the chosen string ('Hello'), trying to print the contents of the buffer just produces one or two garbage characters. The program: #include