Add a function to query the state of the serial lines.
This commit is contained in:
parent
887d744e6d
commit
72ae3b9a86
@ -46,6 +46,13 @@ typedef enum serial_queue_t {
|
||||
SERIAL_QUEUE_BOTH = SERIAL_QUEUE_INPUT | SERIAL_QUEUE_OUTPUT
|
||||
} serial_queue_t;
|
||||
|
||||
typedef enum serial_line_t {
|
||||
SERIAL_LINE_DCD, // Data carrier detect
|
||||
SERIAL_LINE_CTS, // Clear to send
|
||||
SERIAL_LINE_DSR, // Data set ready
|
||||
SERIAL_LINE_RNG, // Ring indicator
|
||||
} serial_line_t;
|
||||
|
||||
int serial_errcode (void);
|
||||
const char* serial_errmsg (void);
|
||||
|
||||
@ -96,6 +103,8 @@ int serial_set_rts (serial_t *device, int level);
|
||||
int serial_get_received (serial_t *device);
|
||||
int serial_get_transmitted (serial_t *device);
|
||||
|
||||
int serial_get_line (serial_t *device, int line);
|
||||
|
||||
int serial_sleep (unsigned long timeout /* milliseconds */);
|
||||
|
||||
int serial_timer (void);
|
||||
|
||||
@ -670,6 +670,35 @@ serial_get_transmitted (serial_t *device)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_get_line (serial_t *device, int line)
|
||||
{
|
||||
if (device == NULL)
|
||||
return -1; // EINVAL (Invalid argument)
|
||||
|
||||
int status = 0;
|
||||
if (ioctl (device->fd, TIOCMGET, &status) != 0) {
|
||||
TRACE ("ioctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (line) {
|
||||
case SERIAL_LINE_DCD:
|
||||
return (status & TIOCM_CAR) == TIOCM_CAR;
|
||||
case SERIAL_LINE_CTS:
|
||||
return (status & TIOCM_CTS) == TIOCM_CTS;
|
||||
case SERIAL_LINE_DSR:
|
||||
return (status & TIOCM_DSR) == TIOCM_DSR;
|
||||
case SERIAL_LINE_RNG:
|
||||
return (status & TIOCM_RNG) == TIOCM_RNG;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_sleep (unsigned long timeout)
|
||||
{
|
||||
|
||||
@ -529,6 +529,35 @@ serial_get_transmitted (serial_t *device)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_get_line (serial_t *device, int line)
|
||||
{
|
||||
if (device == NULL)
|
||||
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
|
||||
|
||||
DWORD stats = 0;
|
||||
if (!GetCommModemStatus (device->hFile, &stats)) {
|
||||
TRACE ("GetCommModemStatus");
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (line) {
|
||||
case SERIAL_LINE_DCD:
|
||||
return (stats & MS_RLSD_ON) == MS_RLSD_ON;
|
||||
case SERIAL_LINE_CTS:
|
||||
return (stats & MS_CTS_ON) == MS_CTS_ON;
|
||||
case SERIAL_LINE_DSR:
|
||||
return (stats & MS_DSR_ON) == MS_DSR_ON;
|
||||
case SERIAL_LINE_RNG:
|
||||
return (stats & MS_RING_ON) == MS_RING_ON;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_sleep (unsigned long timeout)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user