libgslutil
1.2.3
|
Functions | |
int | serial_port_open (const char *path, int flags, int baud)) |
Open serial port for I/O. More... | |
int | serial_port_setbaud (int fd, int baud) |
Set baud rate of serial port. More... | |
Routines for opening and initialising serial ports.
CLOCAL
(undocumented, but widely used). However, these flags actually have the same bitmask! This has been resolved by defining a new GSL_SERIAL_PORT_CONTROL_LINES bit, with a different value and a different sense compared to CLOCAL
, but this of course requires an audit of all users to ensure the serial port is in the correct mode. int serial_port_open | ( | const char * | path, |
int | flags, | ||
int | baud | ||
) |
Open serial port for I/O.
path | Path to device node. |
flags | Flags to open with. |
baud | Baud rate. |
-1 | on error |
A convenience function that opens the serial port path O_RDWR | O_NOCTTY. flags may contain GSL_NONBLOCK to open for non-blocking I/O, and GSL_SERIAL_PORT_CONTROL_LINES to inhibit the CLOCAL
bit (i.e. to honour the serial port control lines). If setting non-blocking mode or setting the requested baud rate fails, the file descriptor will be closed and -1 returned.
This automatically sets the port for raw serial mode, 8 data bits, no parity, 1 stop bit etc.
int serial_port_setbaud | ( | int | fd, |
int | baud | ||
) |
Set baud rate of serial port.
fd | Serial port file descriptor. |
baud | New baud rate. |
0 | on success. |
-1 | on error. |
Sets the baud rate of a serial port fd to the value in baud. This value is the actual numerical baud rate, not a constant (as per cfsetspeed(3)
). Passing a B
... constant will cause incorrect results.
If the baud rate is not a standard rate, this function will try to set the non-standard rate using the divisor method. If the requested baud rate cannot be matched to within 5%, an error will be returned. If the requested baud rate is not an integral divisor of the crystal frequency, two stop bits will be turned on.
This will only change the baud rate and stop bits, not any of the other port settings.