Communication Arduino-C++ do not read Arduino

后端 未结 3 1062
清酒与你
清酒与你 2021-01-06 04:15

I have the following code:

QSerialPort arduPort(\"COM5\");
arduPort.setBaudRate(QSerialPort::Baud9600);
arduPort.setDataBits(QSerialPort::Data8);
arduPort.se         


        
3条回答
  •  春和景丽
    2021-01-06 04:25

    BaudRate: THIS WASN'T SET BY QT!!!!!!! It turns out you can only set the baud rate after you open the port.. Otherwise it is left at the previous value which is 0 when you first plug in the cable.

    Yes, it is true. But it has been fixed and will be available in Qt 5.3

    fDtrControl: Set to 1 by Putty, left at 0 by Qt.

    No. Qt do not touch the DTR signal at opening. This signal will be cleared only when was set to DTR_CONTROL_HANDSHAKE. Because QtSerialPort do not support the DTR/DSR flow control. So, in any case you can control the DTR by means of QSerialPort::setDataTerminalReady(bool).

    PS: I mean current Qt 5.3 release

    fOutX and fInX: Both also set to 1 by Putty and left at 0 by Qt.

    This flag's are used only when you use QSerialPort::Software flow control (Xon/Xoff). But you are use the QSerialPort::NoFlowControl (as I can see from your code snippet), so, all right. So, please check that you use Putty with the "None" flow control too.

    While setting all the parameters I thought it would be a good idea to set the error policy to 'skip'.

    Please use only QSerialPort::Ignore policy (by default). Because other policies is deprecated (all policies) and will be removed in future.

    UPD:

    dcb.fRtsControl = RTS_CONTROL_ENABLE;

    Ahh, seems that your Arduino expect that RTS signal should be enabled by default. In this case you should to use QSerialPort::setRequestToSend(bool). But it is possible only in QSerialPort::NoFlowControl mode.

    I.e. RTS always will be in RTS_CONTROL_DISABLE or RTS_CONTROL_HANDSHAKE after opening of port (depends on your FlowControl settings, QSerialPort::setFlowControl() ).

提交回复
热议问题