Пример #1
0
/*!
    \reimp

    Opens the serial port using OpenMode \a mode, and then returns true if
    successful; otherwise returns false with and sets an error code which can be
    obtained by calling the error() method.

    \warning The \a mode has to be QIODevice::ReadOnly, QIODevice::WriteOnly,
    or QIODevice::ReadWrite. Other modes are unsupported.

    \sa QIODevice::OpenMode, setPort()
*/
bool QSerialPort::open(OpenMode mode)
{
    Q_D(QSerialPort);

    if (isOpen()) {
        setError(QSerialPort::OpenError);
        return false;
    }

    // Define while not supported modes.
    static const OpenMode unsupportedModes = Append | Truncate | Text | Unbuffered;
    if ((mode & unsupportedModes) || mode == NotOpen) {
        setError(QSerialPort::UnsupportedOperationError);
        return false;
    }

    clearError();
    if (d->open(mode)) {
        QIODevice::open(mode);

        d->dataTerminalReady = isDataTerminalReady();
        d->requestToSend = isRequestToSend();

        return true;
    }
    return false;
}
Пример #2
0
/*!
    \property QSerialPort::dataTerminalReady
    \brief the state (high or low) of the line signal DTR

    Returns true on success, false otherwise.
    If the flag is true then the DTR signal is set to high; otherwise low.

    \note The serial port has to be open before trying to set or get this
    property; otherwise false is returned and the error code is set to
    NotOpenError.

    \sa pinoutSignals()
*/
bool QSerialPort::setDataTerminalReady(bool set)
{
    Q_D(QSerialPort);

    if (!isOpen()) {
        d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
        qWarning("%s: device not open", Q_FUNC_INFO);
        return false;
    }

    const bool dataTerminalReady = isDataTerminalReady();
    const bool retval = d->setDataTerminalReady(set);
    if (retval && (dataTerminalReady != set))
        emit dataTerminalReadyChanged(set);

    return retval;
}