]> sigrok.org Git - libsigrok.git/commitdiff
serial: RTS/DTR support on Windows/MinGW.
authorUwe Hermann <redacted>
Sun, 2 Dec 2012 12:41:49 +0000 (13:41 +0100)
committerUwe Hermann <redacted>
Sun, 2 Dec 2012 12:41:49 +0000 (13:41 +0100)
hardware/common/serial.c

index b9ef46d4cda23960e2035a571d2296a687810db9..6c8f63b0fe75d8289e7840d9bf59717b546e527f 100644 (file)
@@ -305,7 +305,8 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf,
  * @return SR_OK upon success, SR_ERR upon failure.
  */
 SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
-               int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr)
+                             int bits, int parity, int stopbits,
+                             int flowcontrol, int rts, int dtr)
 {
        if (!serial) {
                sr_dbg("Invalid serial port.");
@@ -314,12 +315,12 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
 
        if (serial->fd == -1) {
                sr_dbg("Cannot configure unopened serial port %s (fd %d).",
-                               serial->port, serial->fd);
+                      serial->port, serial->fd);
                return SR_ERR;
        }
 
        sr_spew("Setting serial parameters on port %s (fd %d).", serial->port,
-                       serial->fd);
+               serial->fd);
 
 #ifdef _WIN32
        DCB dcb;
@@ -357,6 +358,22 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
        dcb.Parity = NOPARITY; /* TODO: Don't hardcode. */
        dcb.StopBits = ONESTOPBIT; /* TODO: Don't hardcode. */
 
+       if (rts != -1) {
+               sr_spew("Setting RTS %s.", rts ? "high" : "low");
+               if (rts)
+                       dcb.fRtsControl = RTS_CONTROL_ENABLE;
+               else
+                       dcb.fRtsControl = RTS_CONTROL_DISABLE;
+       }
+
+       if (dtr != -1) {
+               sr_spew("Setting DTR %s.", dtr ? "high" : "low");
+               if (rts)
+                       dcb.fDtrControl = DTR_CONTROL_ENABLE;
+               else
+                       dcb.fDtrControl = DTR_CONTROL_DISABLE;
+       }
+
        if (!SetCommState(hdl, &dcb))
                return SR_ERR;
 #else