void MainWindow::slot_readUart(){ // Поставил на всякий случай if (!m_pSerial->isOpen()) { return; } qint64 numBytes; numBytes = m_pSerial->bytesAvailable(); if ( numBytes < 0) { m_pSerial->close(); //qDebug("Read port error %ld", m_pSerial->lastError()); qDebug("Read port error "); return; } if ( numBytes == 0) { //qDebug("Read 0"); // Windows patch m_pSerial->read(numBytes); return; }....}
#if defined(Q_OS_WIN32) m_pSerial->setDeviceName(m_pCBSerialPort->currentText());#else m_pSerial->setDeviceName(QString("/dev/") + m_pCBSerialPort->currentText());#endif if (!m_pSerial->open(AbstractSerial::ReadWrite)) { qDebug("Error open port"); return; }/* qDebug() << "= New parameters ="; qDebug() << "Device name : " << m_pSerial->deviceName(); qDebug() << "Baud rate : " << m_pSerial->baudRate(); qDebug() << "Data bits : " << m_pSerial->dataBits(); qDebug() << "Parity : " << m_pSerial->parity(); qDebug() << "Stop bits : " << m_pSerial->stopBits(); qDebug() << "Flow : " << m_pSerial->flowControl(); qDebug() << "Char timeout, msec : " << m_pSerial->charIntervalTimeout();//*/ switch (m_pCBSerialSpeed->currentIndex()) { case 0: m_pSerial->setBaudRate(AbstractSerial::BaudRate1200); break; case 1: m_pSerial->setBaudRate(AbstractSerial::BaudRate2400); break; case 2: m_pSerial->setBaudRate(AbstractSerial::BaudRate4800); break; case 3: m_pSerial->setBaudRate(AbstractSerial::BaudRate9600); break; case 4: m_pSerial->setBaudRate(AbstractSerial::BaudRate19200); break; case 5: m_pSerial->setBaudRate(AbstractSerial::BaudRate38400); break; case 6: m_pSerial->setBaudRate(AbstractSerial::BaudRate57600); break; case 7: m_pSerial->setBaudRate(AbstractSerial::BaudRate115200); break; } m_pSerial->setDataBits(AbstractSerial::DataBits8); m_pSerial->setParity(AbstractSerial::ParityNone); m_pSerial->setStopBits(AbstractSerial::StopBits1); m_pSerial->setFlowControl(AbstractSerial::FlowControlOff); m_pSerial->flush(); }
... ::DEV_BROADCAST_DEVICEINTERFACE notificationFilter; int size = sizeof(::DEV_BROADCAST_DEVICEINTERFACE); ::ZeroMemory(¬ificationFilter, size); notificationFilter.dbcc_size = size; notificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; size = sizeof(guidDevInterfaceList); for (int i = 0; i < size; i++) { notificationFilter.dbcc_classguid = guidDevInterfaceList[i]; ::HDEVNOTIFY hDeviceNotify = ::RegisterDeviceNotification(this->internalHwnd, ¬ificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE); if (!hDeviceNotify) { // Handle the error... qWarning("Notificator: Failed call RegisterDeviceNotification: %d\n", (int)GetLastError()); }...
//callbac обработчик сообщений от окна...::LRESULT CALLBACK internal_proc(::HWND hwnd, ::UINT message, ::WPARAM wp, ::LPARAM lp){ switch (message) { case WM_DEVICECHANGE: { //тут "тупо" перебор имеющихся в системе портов с помощью SetupDiGetClassDevs и SetupDiEnumDeviceInfo } break; default: return ::DefWindowProc(hwnd, message, wp, lp); } return 0;}...