How to set QSerialPort::PinoutFlags and XonLimit/XoffLimit values?



  • @QSerialPort port(port_info.name);
    if (port.open(QIODevice::ReadWrite)) {
    port.setParity(port_info.parity); //QSerialPort::NoParity
    port.setFlowControl(port_info.flow); //QSerialPort::SoftwareControl
    port.setBaudRate(port_info.baud_rate, //QSerialPort::Baud19200
    QSerialPort::AllDirections);
    port.setDataBits(port_info.data_bits); //QSerialPort::Data8
    port.setStopBits(port_info.stop_bits); //QSerialPort::OneStop
    port.setReadBufferSize(port_info.read_buffer); //8
    port.setDataTerminalReady(port_info.data_terminal_ready); //true
    port.setRequestToSend(port_info.request_to_send); //false
    if (port.isReadable() && port.isWritable()) {
    qDebug() << port.pinoutSignals();
    if (port.error() != QSerialPort::NoError) {
    qDebug() << port.errorString();
    }
    else {
    forever {
    if (!allowed_to_work) {
    break;
    }
    else {
    readLoop(port);
    writeOnceIfNeeded(port);
    }
    }
    }
    }
    }
    port.close();@

    This skel code of mine is working for many different sets of QSerialPort's properties; I can freely read from and write to some devices I'm using it with. Now I'm trying to use it with new hardware and it needs to be configured in a way I don't know how to bite.

    The above code returns no errors but also no PinoutFlags. I want my port.pingoutFlags() to return (0x80|0x40) (QSerialPort::ClearToSendSignal, DTS) but:

    I would expect the above example to return (0x40) (DTS only, no RTS) while it's returning no flags,

    I don't know how to set CTS variable because I can't find method similar to those to set DTS and RTS values,

    I found some weird output when playing with setRequestToSend() and setDataTerminalReady() methods:

    • If I set RTS to true then I'm getting (0x40) (RTS only, no DTS) no matter if I'm setting DTS to true or to false,
    • if I set RTS only, I end up with (0x4|0x40) (RTS and DTR on);
    • etc. but the isDataTerminalReady() and isRequestToSend() methods return predictable values, different than these viewable by pinoutSignals();

    Using Device Monitoring Studio I can see that the values of PinoutSignals count as "FlowReplace", not values returned by above mentioned methods - that's why I'm looking for the way to change them directly... but pinoutSignals() returns no reference, only a copy so I can't just use operator|= and hope for the best.

    Also, I can't figure the way to set XonLimit and XoffLimit values...



    1. Please provide info about your OS and device type.
    2. Please check that all setXX() methods returns true!

    [quote]
    I would expect the above example to return (0×40) (DTS only, no RTS) while it’s returning no flags,
    [/quote]

    Why do you expect it?

    [quote]
    I don’t know how to set CTS variable because I can’t find method similar to those to set DTS and RTS values,
    [/quote]

    Is is impossible, since CTS is an input line.

    [quote]
    bq. If I set RTS to true then I’m getting (0×40) (RTS only, no DTS) no matter if I’m setting DTS to true or to false,
    [/quote]

    How you did " setting DTS to true or to false" ?

    [quote]
    etc. but the isDataTerminalReady() and isRequestToSend() methods return predictable values, different than these viewable by pinoutSignals();
    [/quote]

    the isDataTerminalReady() and isRequestToSend() implicitly calls of pinoutSignals() to query a desired bit.

    [quote]
    that’s why I’m looking for the way to change them directly…
    [/quote]

    You can change only RTS and DTR signals, since it is outgoing signals..

    [quote]
    Also, I can’t figure the way to set XonLimit and XoffLimit values…
    [/quote]

    This is a platform-specific thing (I suppose you talk about Windows). So you can use QSerialPort::handle() -> query the DCB -> change what you want -> update DCB.



    1. Windows, yes. Device is home-made so I don't think it has a "type"...
    2. They are. There were "if jungle" there but I've deleted the checks before posting to make it more clear to you. Btw. isn't " if (port.error() != QSerialPort::NoError)" enough?
    3. I think I get all these flags wrong. I just deleted the part of code which was trying to set them and now everything is working... sorry for garbage topic.

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.