]> sigrok.org Git - libsigrok.git/blobdiff - hardware/common/serial.c
serial: Removed flag OPOST (turn off all output processing).
[libsigrok.git] / hardware / common / serial.c
index 306b889c7db007cdd052733776a5229841e56e35..ebc6979763100a2399a5d9678ed666c16caa81db 100644 (file)
@@ -548,7 +548,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
                return SR_ERR;
        }
 
-       term.c_iflag &= ~(IXON | IXOFF);
+       term.c_iflag &= ~(IXON | IXOFF | IXANY);
        term.c_cflag &= ~CRTSCTS;
        switch (flowcontrol) {
        case 0:
@@ -561,7 +561,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
                break;
        case 2:
                sr_spew("Configuring XON/XOFF flow control.");
-               term.c_iflag |= IXON | IXOFF;
+               term.c_iflag |= (IXON | IXOFF | IXANY);
                break;
        default:
                sr_err("Unsupported flow control setting %d.", flowcontrol);
@@ -569,7 +569,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
        }
 
        term.c_iflag &= ~IGNPAR;
-       term.c_cflag &= ~(PARODD | PARENB);
+       term.c_cflag &= ~(PARENB | PARODD);
        switch (parity) {
        case SERIAL_PARITY_NONE:
                sr_spew("Configuring no parity.");
@@ -590,7 +590,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
 
        /* Turn off all serial port cooking. */
        term.c_iflag &= ~(ISTRIP | INLCR | ICRNL);
-       term.c_oflag &= ~(ONLCR | OCRNL | ONOCR);
+       term.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR);
 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
        term.c_oflag &= ~OFILL;
 #endif
@@ -598,6 +598,9 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
        /* Disable canonical mode, and don't echo input characters. */
        term.c_lflag &= ~(ICANON | ECHO);
 
+       /* Ignore modem status lines; enable receiver */
+       term.c_cflag |= (CLOCAL | CREAD);
+
        /* Write the configured settings. */
        if (tcsetattr(serial->fd, TCSADRAIN, &term) < 0) {
                sr_err("tcsetattr() error: %s.", strerror(errno));
@@ -786,7 +789,8 @@ SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
                if (g_get_monotonic_time() - start > timeout_ms)
                        /* Timeout */
                        break;
-               g_usleep(2000);
+               if (len < 1)
+                       g_usleep(2000);
        }
        if (*buflen)
                sr_dbg("Received %d: '%s'.", *buflen, *buf);
@@ -867,7 +871,8 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
                        sr_dbg("Detection timed out after %dms.", time);
                        break;
                }
-               g_usleep(byte_delay_us);
+               if (len < 1)
+                       g_usleep(byte_delay_us);
        }
 
        *buflen = ibuf;