Added a function to assert or clear a break condition.
This commit is contained in:
parent
25d8fc0969
commit
dea1ae1518
1
serial.h
1
serial.h
@ -68,6 +68,7 @@ int serial_drain (serial *device);
|
||||
|
||||
int serial_send_break (serial *device);
|
||||
|
||||
int serial_set_break (serial *device, int level);
|
||||
int serial_set_dtr (serial *device, int level);
|
||||
int serial_set_rts (serial *device, int level);
|
||||
|
||||
|
||||
@ -457,7 +457,7 @@ serial_read (serial* device, void* data, unsigned int size)
|
||||
TRACE ("gettimeofday");
|
||||
return -1;
|
||||
}
|
||||
timersub (&now, ×tamp ,&delta);
|
||||
timersub (&now, ×tamp, &delta);
|
||||
long elapsed = delta.tv_sec * 1000 + delta.tv_usec / 1000;
|
||||
if (elapsed >= device->timeout)
|
||||
timeout = 0;
|
||||
@ -566,6 +566,23 @@ serial_send_break (serial *device)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_set_break (serial *device, int level)
|
||||
{
|
||||
if (device == NULL)
|
||||
return -1; // EINVAL (Invalid argument)
|
||||
|
||||
int action = (level ? TIOCSBRK : TIOCCBRK);
|
||||
|
||||
if (ioctl (device->fd, action, NULL) != 0) {
|
||||
TRACE ("ioctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
serial_set_status (int fd, int value, int level)
|
||||
{
|
||||
|
||||
@ -419,6 +419,27 @@ serial_send_break (serial* device)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
serial_set_break (serial *device, int level)
|
||||
{
|
||||
if (device == NULL)
|
||||
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
|
||||
|
||||
if (level) {
|
||||
if (!SetCommBreak (device->hFile)) {
|
||||
TRACE ("SetCommBreak");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (!ClearCommBreak (device->hFile)) {
|
||||
TRACE ("ClearCommBreak");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
serial_set_dtr (serial* device, int level)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user