From: Uwe Hermann Date: Mon, 26 Nov 2012 16:01:15 +0000 (+0100) Subject: serial: Initial code for setting DTR/RTS. X-Git-Tag: dsupstream~527 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=700dcd5caa1d7569469cd7823add6ffd2ed5a2ee;p=libsigrok.git serial: Initial code for setting DTR/RTS. Currently disabled until option parsing is in place. --- diff --git a/hardware/common/serial.c b/hardware/common/serial.c index bdf02163..4920ece2 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -32,6 +32,7 @@ #endif #include #include +#include #include #include "libsigrok.h" #include "libsigrok-internal.h" @@ -285,7 +286,6 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf, SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, int bits, int parity, int stopbits, int flowcontrol) { - if (!serial) { sr_dbg("Invalid serial port."); return SR_ERR; @@ -341,6 +341,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, #else struct termios term; speed_t baud; + int ret, controlbits; if (tcgetattr(serial->fd, &term) < 0) { sr_err("tcgetattr() error on port %s (fd %d): %s.", @@ -504,6 +505,25 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, sr_err("tcsetattr() error: %s.", strerror(errno)); return SR_ERR; } + +#if 0 + /* TODO: Make configurable via driver options. */ + + sr_spew("Configuring RTS to 1/high."); + controlbits = TIOCM_RTS; + if ((ret = ioctl(serial->fd, TIOCMBIC, &controlbits)) < 0) { + sr_err("Error setting RTS to 1: %s.", strerror(errno)); + return SR_ERR; + } + + sr_spew("Configuring DTR to 0/low."); + controlbits = TIOCM_DTR; + if ((ret = ioctl(serial->fd, TIOCMBIS, &controlbits)) < 0) { + sr_err("Error setting DTR to 0: %s.", strerror(errno)); + return SR_ERR; + } +#endif + #endif return SR_OK;