Questions tagged [termios]

Termios is Unix API for terminal I/O.

The anatomy of a program performing serial I/O with the help of termios is as follows:

  • Open serial device with standard Unix system call open(2)

  • Configure communication parameters and other interface properties (line discipline, etc.) with the help of specific termios functions and data structures.

  • Use standard Unix system calls read(2) and write(2) for reading from, and writing to the serial interface. Related system calls like readv(2) and writev(2) can be used, too. Multiple I/O techniques, like blocking, non-blocking, asynchronous I/O (select(2) or poll(2)) or signal-drive I/O (SIGIO signal) are also possible.

  • Close device with the standard Unix system call close(2) when done.

309 questions
34
votes
1 answer

Linux Blocking vs. non Blocking Serial Read

I have this code for reading from Serial in Linux , but i don't know what is the difference between blocking and non blocking in reading Serial Port and which one is better in which situation?
Mohsen Zahraee
  • 3,309
  • 5
  • 31
  • 45
17
votes
1 answer

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

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); …
chris12892
  • 1,634
  • 2
  • 18
  • 36
15
votes
1 answer

Where to obtain termios.h

In my particular situation, I am using MinGW/MSys. It doesn't contain termios.h. Turns out that it isn't a library that can be downloaded and installed (Google didn't found any). Termcap also doesn't include termios.h. From where can I get this…
Soergener
  • 703
  • 1
  • 6
  • 7
15
votes
1 answer

How to read a binary data over serial terminal in C program?

I read followed links and other sources, but didn't find answer for my question. Binary data over serial terminal Data gets corrupted during transmission over the serial port I communicate with my embedded device through a serial port. By default,…
Bakir
  • 193
  • 1
  • 2
  • 9
12
votes
1 answer

Why is Linux's pty driver replacing VEOFs with NULs?

It seems that the pty driver on Linux is replacing VEOF characters (^D, \4) with NUL bytes (\0) in the data already written from the master side if the terminal settings are changed with tcsetattr(TCSANOW) to non-canonical mode before reading it on…
user10678532
11
votes
2 answers

Linux - moving the console cursor visual

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…
user129186
  • 1,156
  • 2
  • 14
  • 30
10
votes
1 answer

PTY/TTY - What Can't You Do With Only Slave FD

Question: If I have a pty or tty master/slave pair, what can I not do with it if I only have the slave node's file descriptor? Or, put another way: what can I only do if I have the master node's file descriptor? My Current Understanding: I grok the…
mtraceur
  • 3,254
  • 24
  • 33
9
votes
2 answers

Unable to import termios package

I am using Python 3.7 and I need to import termios to mask a password input. But I am unable to find it on https://pypi.org/ import sys, tty, termios Traceback (most recent call last): File "", line 1, in import sys, tty,…
saiki68
  • 91
  • 1
  • 1
  • 4
8
votes
3 answers

CRTSCTS not define when compiling as C99

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…
CamW
  • 3,223
  • 24
  • 34
8
votes
1 answer

How do the CLOCAL and CRTSCTS Flags in termios.c_cflag Affect the Serial Port?

I want to configure a UART to use the Hardware Flow Control lines RTS and CTS in Linux. According to http://linux.die.net/man/3/termios, CRTSCTS enables RTS/CTS (hardware) flow control, and CLOCAL configures the serial port to ignore modem control…
Samuel
  • 8,063
  • 8
  • 45
  • 41
7
votes
2 answers

Python TTY Control

I guess I'm not clear on what what the function of the getty/agetty/mgetty programs are on a linux/unix machine. I can start a shell on a tty with something like this: TTY = '/dev/tty3' cpid = os.fork() if cpid == 0: os.closerange(0, 4) …
tMC
  • 18,105
  • 14
  • 62
  • 98
7
votes
1 answer

How to distinguish between Escape and Escape Sequence

My end goal is to distinguish between my pressing Esc (ASCII 27) on my keyboard, and me pressing the → key on my keyboard (which translates to a sequence of 27 91 67). I am using termios to put my terminal into non-Canonical mode. I think I…
Greg Schmit
  • 4,275
  • 2
  • 21
  • 36
7
votes
1 answer

Writing my own shell: How implement command history?

As an exercise in understanding my computer better, and as a tool, I'm writing my own shell in C++. Stephen Brennan's article on writing a simple shell was very helpful. However, what has me flummoxed is how to handle pressing up-arrow and…
uliwitness
  • 8,532
  • 36
  • 58
7
votes
1 answer

Prevent typed characters from being displayed (like disabling "echo" attribute in termios)

I'm writing a bash script in which I read single characters from the input. I do so using read -n 1 -s. -n 1 is to read only a single character; -s is "silent" mode, in which the typed characters won't be visible. The problem is, that when the…
leemes
  • 44,967
  • 21
  • 135
  • 183
6
votes
1 answer

C read call blocking on serial port operation

I am trying to write a C program in Linux to send and receive data from a microcontroller over the serial port. As a test, I have configured the microcontroller to immediately echo all characters sent. I have verified that this works in minicom…
FazJaxton
  • 7,544
  • 6
  • 26
  • 32
1
2 3
20 21