示例#1
0
void Win_QextSerialPort::monitorCommEvent()
{
    DWORD eventMask = 0;

    ResetEvent(m_Overlap.hEvent);
    if (!WaitCommEvent(m_WinHandle, & eventMask, & m_Overlap))
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            qCritical("WaitCommEvent error %ld\n", GetLastError());
        }
    }

    if (WaitForSingleObject(m_Overlap.hEvent, INFINITE) == WAIT_OBJECT_0) 
    {
        //overlap event occured
        DWORD undefined;
        if (!GetOverlappedResult(m_WinHandle, & m_Overlap, & undefined, false)) 
        {
            qWarning("Comm event overlapped error %ld", GetLastError());
            return;
        }
        if (eventMask & EV_RXCHAR) 
        {
            if (sender() != this)
                emit readyRead();
        }
        if (eventMask & EV_TXEMPTY) 
        {
            DWORD numBytes;
            GetOverlappedResult(m_WinHandle, & m_OverlapWrite, & numBytes, true);
            m_pBytesToWriteLock->lockForWrite();

            if (sender() != this)
            {
                emit bytesWritten(bytesToWrite());
            }

            m_BytesToWrite = 0;
            m_pBytesToWriteLock->WriteUnlock();
        }
        if (eventMask & EV_DSR)
        {
            if (lineStatus() & LS_DSR)
            {
                emit dsrChanged(true);
            }
            else
            {
                emit dsrChanged(false);
            }
        }
    }
}
示例#2
0
void TestSerialIODevice::setDsr( bool value )
{
    if ( _dsr != value ) {
        _dsr = value;
        emit dsrChanged( value );
    }
}
bool mdtSerialPortPosix::getCtlStates()
{
  int states;

  if(ioctl(pvFd, TIOCMGET, &states) < 0){
    mdtError e(MDT_UNDEFINED_ERROR, "ioctl() call failed with command TIOCMGET", mdtError::Error);
    e.setSystemError(errno, strerror(errno));
    MDT_ERROR_SET_SRC(e, "mdtSerialPortPosix");
    e.commit();
    return false;
  }

  // See witch signals changed
  if((states & TIOCM_CAR) != pvPreviousCarState){
    // Store new state
    pvPreviousCarState = (states & TIOCM_CAR);
    // Determine current state and emit signal
    if(states & TIOCM_CAR){
      pvCarIsOn = true;
    }else{
      pvCarIsOn = false;
    }
    emit carChanged(pvCarIsOn);
  }
  if((states & TIOCM_DSR) != pvPreviousDsrState){
    // Store new state
    pvPreviousDsrState = (states & TIOCM_DSR);
    // Determine current state and emit signal
    if(states & TIOCM_DSR){
      pvDsrIsOn = true;
    }else{
      pvDsrIsOn = false;
    }
    emit dsrChanged(pvDsrIsOn);
  }
  if((states & TIOCM_CTS) != pvPreviousCtsState){
    // Store new state
    pvPreviousCtsState = (states & TIOCM_CTS);
    // Determine current state and emit signal
    if(states & TIOCM_CTS){
      pvCtsIsOn = true;
    }else{
      pvCtsIsOn = false;
    }
    emit ctsChanged(pvCtsIsOn);
  }
  if((states & TIOCM_RNG) != pvPreviousRngState){
    // Store new state
    pvPreviousRngState = (states & TIOCM_RNG);
    // Determine current state and emit signal
    if(states & TIOCM_RNG){
      pvRngIsOn = true;
    }else{
      pvRngIsOn = false;
    }
    emit rngChanged(pvRngIsOn);
  }

  return true;
}
int QextSerialBase::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QIODevice::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: dsrChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 1;
    }
    return _id;
}
mdtAbstractSerialPort::mdtAbstractSerialPort(QObject *parent)
 : mdtAbstractPort(parent)
{
  pvCarIsOn = false;
  pvDsrIsOn = false;
  pvCtsIsOn = false;
  pvRngIsOn = false;
  // Emit signals with initial states
  emit carChanged(pvCarIsOn);
  emit dsrChanged(pvDsrIsOn);
  emit ctsChanged(pvCtsIsOn);
  emit rngChanged(pvRngIsOn);
  // Attributes
  pvUartType = UT_UNKNOW;
}
示例#6
0
void QSerialPort::statusTimeout()
{
#ifdef USE_TERMIOS
    if ( d->fd != -1 && d->isTty ) {
        int old_status = d->status;
        int status = 0;
        ::ioctl( d->fd, TIOCMGET, &status );
        d->status = status;
        if ( ( ( old_status ^ status ) & TIOCM_DSR ) != 0 )
            emit dsrChanged( ( status & TIOCM_DSR ) != 0 );
        if ( ( ( old_status ^ status ) & TIOCM_CAR ) != 0 )
            emit carrierChanged( ( status & TIOCM_CAR ) != 0 );
    }
#endif
}
示例#7
0
int AbstractSerial::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QIODevice::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: signalStatus((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< QDateTime(*)>(_a[2]))); break;
        case 1: exception(); break;
        case 2: ctsChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: dsrChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: ringChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 5;
    }
    return _id;
}