linux - [Solved-1 Solution] How to open, read, and write from serial port in C - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to open, read, and write from serial port in C ?
Linux - Solution 1:
- The values for speed are B115200, B230400, B9600, B19200, B38400, B57600, B1200, B2400, B4800, etc.
- The values for parity are 0 (meaning no parity), PARENB|PARODD (enable parity and use odd), PARENB (enable parity and use even), PARENB|PARODD|CMSPAR (mark parity), and PARENB|CMSPAR (space parity).
- "Blocking" sets whether a read() on the port waits for the specified number of characters to arrive.
- Setting no blocking means that a read() returns however many characters are available without waiting for more, up to the buffer limit.
CMSPAR is needed only for choosing mark and space parity, which is uncommon. My header file /usr/include/bits/termios.h enables definition of CMSPAR only if the preprocessor symbol __USE_MISC is defined. That definition occurs (in features.h) with
The introductory comments of <features.h> :
To make the program treat the received data as ASCII codes, compile the program with the symbol DISPLAY_STRING, e.g.