Logo Search packages:      
Sourcecode: qtemu version File versions  Download package

bool Posix_QextSerialPort::open ( OpenMode  mode  )  [virtual]

Opens the serial port associated to this class. This function has no effect if the port associated with the class is already open. The port is also configured to the current settings, as stored in the Settings structure.

Implements QextSerialBase.

Definition at line 829 of file posix_qextserialport.cpp.

References PortSettings::BaudRate, PortSettings::DataBits, PortSettings::FlowControl, PortSettings::Parity, QextSerialBase::queryMode(), setBaudRate(), setDataBits(), setFlowControl(), setParity(), setStopBits(), PortSettings::StopBits, and PortSettings::Timeout_Millisec.

    QMutexLocker lock(mutex);
    if (mode == QIODevice::NotOpen)
        return isOpen();
    if (!isOpen()) {
        qDebug() << "trying to open file" << port.toAscii();
        //note: linux 2.6.21 seems to ignore O_NDELAY flag
        if ((fd = ::open(port.toAscii() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) {
            qDebug("file opened succesfully");

            setOpenMode(mode);              // Flag the port as opened
            tcgetattr(fd, &old_termios);    // Save the old termios
            Posix_CommConfig = old_termios; // Make a working copy
            cfmakeraw(&Posix_CommConfig);   // Enable raw access

            /*set up other port settings*/
            Posix_CommConfig.c_cc[VMIN]= 0;
#ifdef _POSIX_VDISABLE  // Is a disable character available on this system?
            // Some systems allow for per-device disable-characters, so get the
            //  proper value for the configured device
            const long vdisable = fpathconf(fd, _PC_VDISABLE);
            Posix_CommConfig.c_cc[VINTR] = vdisable;
            Posix_CommConfig.c_cc[VQUIT] = vdisable;
            Posix_CommConfig.c_cc[VSTART] = vdisable;
            Posix_CommConfig.c_cc[VSTOP] = vdisable;
            Posix_CommConfig.c_cc[VSUSP] = vdisable;
            tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);

            if (queryMode() == QextSerialBase::EventDriven) {
                readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
                connect(readNotifier, SIGNAL(activated(int)), this, SIGNAL(readyRead()));
        } else {
            qDebug() << "could not open file:" << strerror(errno);
    return isOpen();

Generated by  Doxygen 1.6.0   Back to index