![]() |
libserial
1.6.2
RoadNarrows Roboitics Serial Library
|
RS-232 serial device communication declarations and defines. More...
#include "rnr/rnrconfig.h"
Go to the source code of this file.
Macros | |
#define | EOL_CRLF "\r\n" |
#define | EOL_LFCR "\n\r" |
#define | EOL_CR "\r" |
#define | EOL_NL "\n" |
Functions | |
int | SerDevOpen (const char *sSerDevName, int nBaudRate, int nByteSize, int cParity, int nStopBits, bool_t bRtsCts, bool_t bXonXoff) |
Open and configure serial device for communication. More... | |
int | SerDevClose (int fd) |
Close serial device port. More... | |
ssize_t | SerDevReadLine (int fd, char buffer[], size_t count, char *eol, uint_t usec) |
Read a ASCII character line from the serial device. More... | |
ssize_t | SerDevWriteLine (int fd, char *buffer, char *eol, uint_t usec) |
Write null-terminated ASCII character line to serial device. More... | |
int | SerDevGetc (int fd, uint_t usec) |
Get 1 character from the serial device. More... | |
int | SerDevPutc (int fd, byte_t byte, uint_t usec) |
Put one character to serial device. More... | |
ssize_t | SerDevRead (int fd, byte_t *buffer, size_t count, uint_t usec) |
Read from the serial device. More... | |
ssize_t | SerDevWrite (int fd, byte_t *buffer, size_t count, uint_t usec) |
Write to serial device. More... | |
ssize_t | SerDevFIFOInputCount (int fd) |
Determine the number of bytes in the input FIFO of the serial device. More... | |
ssize_t | SerDevFIFOInputFlush (int fd) |
Flush the input FIFO buffer, discarding all data in buffer. More... | |
void | SerDevFIFOOutputFlush (int fd) |
Flush output FIFO buffer, discarding all data in buffer. More... | |
void | SerDevFIFOOutputDrain (int fd) |
Transmit (drain) all data written to the output FIFO buffer. More... | |
INLINE_IN_H bool_t | SerDevIsInputDataPresent (int fd) |
Checks to see if there are bytes in the input queue availabe to be read. More... | |
int | SerDevSetBaudRate (int fd, int nBaudRate) |
Set the baudrate. More... | |
int | SerDevSetByteSize (int fd, int nByteSize) |
Set the byte size. More... | |
int | SerDevSetParity (int fd, int cParity) |
Set the parity. More... | |
int | SerDevSetStopBits (int fd, int nStopBitgs) |
Set the number of stop bits. More... | |
int | SerDevSetHwFlowControl (int fd, bool_t bRtsCts) |
Set hardware flow control state. More... | |
int | SerDevSetSwFlowControl (int fd, bool_t bXonXoff) |
Set software flow control state. More... | |
int | SerDevAssertRTS (int fd) |
Assert RTS (request to send). More... | |
int | SerDevDeassertRTS (int fd) |
De-assert RTS (request to send). More... | |
int | SerDevAssertCTS (int fd) |
Assert RTS (clear to send). More... | |
int | SerDevDeassertCTS (int fd) |
De-assert RTS (clear to send). More... | |
RS-232 serial device communication declarations and defines.
Ported from ipser.h (RoadNarrows)
Definition in file serdev.h.
int SerDevAssertCTS | ( | int | fd | ) |
Assert RTS (clear to send).
fd | File descriptor to the opened serial device. |
Definition at line 1500 of file serdev.c.
Referenced by SerDevDeassertCTS(), and SerDevIsInputDataPresent().
int SerDevAssertRTS | ( | int | fd | ) |
Assert RTS (request to send).
fd | File descriptor to the opened serial device. |
Definition at line 1458 of file serdev.c.
Referenced by SerDevDeassertCTS(), and SerDevIsInputDataPresent().
int SerDevClose | ( | int | fd | ) |
Close serial device port.
fd | File descriptor to the opened serial device. |
int SerDevDeassertCTS | ( | int | fd | ) |
De-assert RTS (clear to send).
fd | File descriptor to the opened serial device. |
Definition at line 1521 of file serdev.c.
References SerDevAssertCTS(), SerDevAssertRTS(), and SerDevDeassertRTS().
Referenced by SerDevIsInputDataPresent().
int SerDevDeassertRTS | ( | int | fd | ) |
De-assert RTS (request to send).
fd | File descriptor to the opened serial device. |
Definition at line 1479 of file serdev.c.
Referenced by SerDevDeassertCTS(), and SerDevIsInputDataPresent().
ssize_t SerDevFIFOInputCount | ( | int | fd | ) |
Determine the number of bytes in the input FIFO of the serial device.
The input FIFO holds data received but not read.
fd | File descriptor to the opened serial device. |
Definition at line 1146 of file serdev.c.
References SERDEV_FIONREAD, SerDevFIFOInputFlush(), SERDEVLOG, SERDEVLOGNL, and SerDevRead().
Referenced by SerDevFIFOInputFlush(), and SerDevIsInputDataPresent().
ssize_t SerDevFIFOInputFlush | ( | int | fd | ) |
Flush the input FIFO buffer, discarding all data in buffer.
The input FIFO holds data received but not read.
This function does not block.
fd | File descriptor to the opened serial device. |
Definition at line 1202 of file serdev.c.
References SerDevFIFOInputCount().
Referenced by SerDevFIFOInputCount().
void SerDevFIFOOutputDrain | ( | int | fd | ) |
Transmit (drain) all data written to the output FIFO buffer.
The output FIFO holds data written to the device but not transmitted.
This function blocks until all of the FIFO data has been transmitted.
fd | File descriptor to the opened serial device. |
void SerDevFIFOOutputFlush | ( | int | fd | ) |
Flush output FIFO buffer, discarding all data in buffer.
The output FIFO holds data written to the device but not transmitted.
This function does not block.
fd | File descriptor to the opened serial device. |
int SerDevGetc | ( | int | fd, |
uint_t | usec | ||
) |
Get 1 character from the serial device.
Read 1 character from the serial device input. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the read can block indefinitely.
fd | File descriptor to the opened serial device. |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the read. If usec == 0, then the read will block indefinitely until count bytes are read or an I/O error occurred. |
Definition at line 843 of file serdev.c.
References fdset_nowarn().
Referenced by SerDevReadLine().
INLINE_IN_H bool_t SerDevIsInputDataPresent | ( | int | fd | ) |
Checks to see if there are bytes in the input queue availabe to be read.
fd | File descriptor to the opened serial device. |
Definition at line 325 of file serdev.h.
References SerDevAssertCTS(), SerDevAssertRTS(), SerDevDeassertCTS(), SerDevDeassertRTS(), SerDevFIFOInputCount(), SerDevSetBaudRate(), SerDevSetByteSize(), SerDevSetHwFlowControl(), SerDevSetParity(), SerDevSetStopBits(), and SerDevSetSwFlowControl().
int SerDevOpen | ( | const char * | sSerDevName, |
int | nBaudRate, | ||
int | nByteSize, | ||
int | cParity, | ||
int | nStopBits, | ||
bool_t | bRtsCts, | ||
bool_t | bXonXoff | ||
) |
Open and configure serial device for communication.
sSerDevName | Serial device port name (e.g. /dev/ttyS0). |
nBaudRate | Baud rate. |
nByteSize | Bytes size in bits 5...8. |
cParity | Parity. One of: 'N', 'E', 'O' |
nStopBits | Number of stop bits 1, 2 |
bRtsCts | Do [not] use hardware flow control. |
bXonXoff | Do [not] use software flow control. |
Definition at line 663 of file serdev.c.
References SerDevConfigure().
int SerDevPutc | ( | int | fd, |
byte_t | byte, | ||
uint_t | usec | ||
) |
Put one character to serial device.
Write 1 character to the serial device output. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the write can block indefinitely.
fd | File descriptor to the opened serial device. |
byte | Character to write. |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the write. If usec == 0, then the write will block indefinitely until count bytes are written or an I/O error occurred. |
Definition at line 910 of file serdev.c.
References fdset_nowarn().
ssize_t SerDevRead | ( | int | fd, |
byte_t * | buffer, | ||
size_t | count, | ||
uint_t | usec | ||
) |
Read from the serial device.
Read up to count bytes into buffer from the serial device input. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the read can block indefinitely.
Note the the bytes read can be less than the count.
fd | File descriptor to the opened serial device. |
buffer | Output read buffer. |
count | Number of bytes to read. |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the read. If usec == 0, then the read will block indefinitely until count bytes are read or an I/O error occurred. |
Definition at line 976 of file serdev.c.
References fdset_nowarn(), SERDEVLOG, timer_elapsed(), and timer_mark().
Referenced by SerDevFIFOInputCount().
ssize_t SerDevReadLine | ( | int | fd, |
char | buffer[], | ||
size_t | count, | ||
char * | eol, | ||
uint_t | usec | ||
) |
Read a ASCII character line from the serial device.
Read up to count bytes into buffer from the serial device input. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the read can block indefinitely.
The end-of-line sequence defines the end of the line. It is stripped from the return buffer.
fd | File descriptor to the opened serial device. | |
[out] | buffer | Output read buffer. |
count | Number of bytes to read. | |
eol | End-of-line character sequence > 0. | |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the read. If usec == 0, then the read will block indefinitely until count bytes are read or an I/O error occurred. |
Definition at line 720 of file serdev.c.
References SerDevGetc(), timer_elapsed(), and timer_mark().
int SerDevSetBaudRate | ( | int | fd, |
int | nBaudRate | ||
) |
Set the baudrate.
fd | File descriptor to the opened serial device. |
nBaudRate | Baud rate. |
Definition at line 1230 of file serdev.c.
References SERDEV_GET_BAUDRATE, and SERDEV_NO_ATTR.
Referenced by SerDevIsInputDataPresent().
int SerDevSetByteSize | ( | int | fd, |
int | nByteSize | ||
) |
Set the byte size.
fd | File descriptor to the opened serial device. |
nByteSize | Bytes size in bits 5...8. |
Definition at line 1266 of file serdev.c.
References NOTBITS.
Referenced by SerDevIsInputDataPresent().
int SerDevSetHwFlowControl | ( | int | fd, |
bool_t | bRtsCts | ||
) |
Set hardware flow control state.
fd | File descriptor to the opened serial device. |
bRtsCts | Do [not] use hardware flow control. |
Definition at line 1350 of file serdev.c.
References NOTBITS, SERDEV_GET_ATTR, and SERDEV_NO_ATTR.
Referenced by SerDevIsInputDataPresent().
int SerDevSetParity | ( | int | fd, |
int | cParity | ||
) |
Set the parity.
fd | File descriptor to the opened serial device. |
cParity | Parity. One of: 'N', 'E', 'O' |
Definition at line 1297 of file serdev.c.
References NOTBITS.
Referenced by SerDevIsInputDataPresent().
int SerDevSetStopBits | ( | int | fd, |
int | nStopBitgs | ||
) |
Set the number of stop bits.
fd | File descriptor to the opened serial device. |
nStopBits | Number of stop bits 1, 2 |
Definition at line 1326 of file serdev.c.
References NOTBITS.
Referenced by SerDevIsInputDataPresent().
int SerDevSetSwFlowControl | ( | int | fd, |
bool_t | bXonXoff | ||
) |
Set software flow control state.
fd | File descriptor to the opened serial device. |
bXonXoff | Do [not] use software flow control. |
Definition at line 1410 of file serdev.c.
References NOTBITS, SERDEV_GET_ATTR, and SERDEV_NO_ATTR.
Referenced by SerDevIsInputDataPresent().
ssize_t SerDevWrite | ( | int | fd, |
byte_t * | buffer, | ||
size_t | count, | ||
uint_t | usec | ||
) |
Write to serial device.
Write up to count bytes from the buffer to the serial device output. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the write can block indefinitely.
Note that the number of bytes written can be less than the count.
fd | File descriptor to the opened serial device. |
buffer | Input write buffer. |
count | Number of of bytes to write. |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the write. If usec == 0, then the write will block indefinitely until count bytes are written or an I/O error occurred. |
Definition at line 1061 of file serdev.c.
References fdset_nowarn(), SERDEVLOG, timer_elapsed(), and timer_mark().
Referenced by SerDevWriteLine().
ssize_t SerDevWriteLine | ( | int | fd, |
char * | buffer, | ||
char * | eol, | ||
uint_t | usec | ||
) |
Write null-terminated ASCII character line to serial device.
Write line plus end-of-line sequence. This call is non-blocking if the timeout value usec is greater than zero. Otherwise the write can block indefinitely.
fd | File descriptor to the opened serial device. | |
[in] | buffer | Buffer to write. |
eol | End-of-line character sequence to append to buffer output. | |
usec | Timeout in microseconds. If usec > 0, an upper timeout limit is placed on the write. If usec == 0, then the write will block indefinitely until count bytes are written or an I/O error occurred. |
Definition at line 812 of file serdev.c.
References SerDevWrite().