1

I'm trying to write a library to read data from a serial device, a Mipex-02 gas sensor. Unfortunately, my code doesn't seem to open the serial connection properly, and I can't figure out why.

The full source code is available on github, specifically, here's the configuration of the serial connection:

    MipexSensor::MipexSensor(string devpath) {
        if (!check_dev_path(devpath))
            throw "Invalid devpath";
        this->path = devpath;
        this->debugout_ = false;
        this->sensor.SetBaudRate(SerialStreamBuf::BAUD_9600);
        this->sensor.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
        this->sensor.SetNumOfStopBits(1);
        this->sensor.SetParity(SerialStreamBuf::PARITY_NONE);
        this->sensor.SetFlowControl(SerialStreamBuf::FLOW_CONTROL_NONE);
        this->last_concentration = this->last_um = this->last_ur = this->last_status = 0;
        cout << "Connecting to "<< devpath << endl;
        this->sensor.Open(devpath);
    }

I think the meaning of the enums here are obvious enough. The values are from the instruction manual:

UART characteristics: exchange rate – 9600 baud, 8-bit message, 1 stop bit, without check for parity

So at first I was using interceptty to test it, and it worked perfectly fine. But when I tried to connect to the device directly, I couldn't read anything. the RX LED flashes on the devices so clearly the program manages to send something, but -unlike with interceptty- the TX LED never flash.

So I don't know if it's sending data incorrectly, if it's not sending all of it, and I can't even sniff the connection since it only happens when interceptty isn't in the middle. Interceptty's command-line is interceptty -s 'ispeed 9600 ospeed 9600 -parenb -cstopb -ixon cs8' -l /dev/ttyUSB0 (-s options are passed to stty) which is in theory the same options set in the code.

Thanks in advance.

  • FLOW_CONTROL_NONE is wishful thinking that rarely matches reality. In practice, serial devices do pay attention to the handshake signals and won't send anything if DTR or RTS are turned off. Any utility, like interceptty, will never make that mistake. – Hans Passant Oct 08 '15 at 13:12
  • I tried FLOW_CONTROL_HARD, FLOW_CONTROL_SOFT, FLOW_CONTROL_DEFAULT, nothing different happened. Also -ixon in stty's options turn off "XON/XOFF" flow control. I don't know if there are different types of flow controls, but that's the only one I found in stty's man page –  Oct 08 '15 at 13:51

0 Answers0