QString MainWindow::serialErrorString() const { QSerialPort* serial = qobject_cast<QSerialPort*>(_ioDevice); switch(serial->error()) { case QSerialPort::NoError: return "no error"; case QSerialPort::DeviceNotFoundError: return "device not found"; case QSerialPort::PermissionError: return "permission error"; case QSerialPort::OpenError: return "device is already opened"; case QSerialPort::FramingError: return "framing error"; case QSerialPort::ParityError: return "parity error"; case QSerialPort::BreakConditionError: return "break condition error"; case QSerialPort::ReadError: return "read error"; case QSerialPort::WriteError: return "write error"; case QSerialPort::UnsupportedOperationError: return "unsupported operation error"; case QSerialPort::UnknownError: default: return "unknown error"; } }
bool SerialCommunication::SerialDisconnect() { // serial disconnect if (serial.isOpen()) { serial.close(); return true; } return false; }
bool AtSessionManager::addSerialPort ( const QString& deviceName, const QString& options ) { // Bail out if the device is already bound. if ( d->serialPorts.contains( deviceName ) ) return true; // Attempt to open the device. QSerialPort *port = QSerialPort::create( deviceName, 115200, true ); if ( !port ) return false; connect( port, SIGNAL(destroyed()), this, SLOT(serialPortDestroyed()) ); // Zero reads on RFCOMM sockets should cause a close to occur. port->setKeepOpen( false ); // Add the device to our list. d->serialPorts.insert( deviceName, port ); registerTaskIfNecessary(); // Wrap the device in a new session handler. We hang it off the // serial port object so it will get cleaned up automatically // when removeSerialPort is called. AtFrontEnd *session = new AtFrontEnd( options, port ); session->setDevice( port ); emit newSession( session ); return true; }
QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication coreApplication(argc, argv); int argumentCount = QCoreApplication::arguments().size(); QStringList argumentList = QCoreApplication::arguments(); QTextStream standardOutput(stdout); if (argumentCount == 1) { standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]").arg(argumentList.first()) << endl; return 1; } QSerialPort serialPort; QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; serialPort.setBaudRate(serialPortBaudRate); if (!serialPort.open(QIODevice::ReadOnly)) { standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } SerialPortReader serialPortReader(&serialPort); return coreApplication.exec(); }
bool Ficgta01MultiplexerPlugin::detect( QSerialIODevice *device ) { // The FIC needs a special line discipline set on the device. QSerialPort *port = qobject_cast<QSerialPort *>( device ); if (port) { int discipline = N_TIHTC; ::ioctl(port->fd(), TIOCSETD, &discipline); } device->discard(); int rc; struct termios t; rc = tcgetattr(port->fd(), &t); t.c_cflag |= CRTSCTS; rc = tcsetattr(port->fd(), TCSANOW, &t); // Issue an innocuous command to wake up the device. // It will respond with either "OK" or "AT-Command Interpreter ready". // We will do this up to 10 times as the modem is losing the first at // commands (due waking up) int attempts = 10; while (--attempts >= 0 && !QSerialIODeviceMultiplexer::chat( device, "ATZ")); // Issue the AT+CMUX command to determine if this device // uses GSM 07.10-style multiplexing. #ifndef FICGTA01_NO_MUX return QGsm0710Multiplexer::cmuxChat( device, FICGTA01_FRAME_SIZE, true ); #else return true; #endif }
void SerialCommunication::rgbChange(int r, int g, int b) { data = ""; data.append("0" + QString::number(r) + "," + QString::number(g) + "," + QString::number(b) + "\n"); qDebug("Sending: " + data); if (serial.isOpen()) serial.write(data); }
void ConnectionThread::run() { if(stepByStep) sendNextCommand = false; else sendNextCommand = true; QSerialPort serial; serial.setPortName(portName); if (!serial.open(QIODevice::ReadWrite)) { emit error(tr("Can't open %1, error code %2").arg(portName).arg(serial.error())); return; } while (!quit) { if(stepByStep) { while(!sendNextCommand); mutex.lock(); sendNextCommand = false; mutex.unlock(); } // Envoi microcommande serial.write(test->recupProchaineMicrocommande().c_str()); if(!serial.waitForBytesWritten(waitTimeout)) { emit timeout(tr("Wait write microcommande timeout %1").arg(QTime::currentTime().toString())); } //Accusé de reception if(serial.waitForReadyRead(waitTimeout)) { QByteArray received = serial.readAll(); if(received.toStdString().compare(COMMANDE_RECEIVED) != 0) { emit error("Not wanted response"); } } else { emit timeout(tr("Wait read response timeout %1").arg(QTime::currentTime().toString())); } //Pret a recevoir prochaine commande if(serial.waitForReadyRead(waitTimeout)) { QByteArray received = serial.readAll(); if(received.toStdString().compare(READY_FOR_NEXT_COMMAND) != 0) { emit error("Not wanted response"); } } else { emit timeout(tr("Wait read response timeout %1").arg(QTime::currentTime().toString())); } } }
void onRxData() { if (m_port.bytesAvailable() < 9) return; if (m_port.error() != QSerialPort::NoError) return; if (! check(m_port.peek(9))) return setIoStatus(ChecksumError); uint8_t dummy; m_str >> m_address >> dummy >> m_status >> dummy >> m_value; setIoStatus(Ok); }
PortSettings PositioningMethodSerialPortOptions::getPortSettings(const QString &APortName) { PortSettings portSettings; OptionsNode node; if (Options::hasNode(OPV_POSITIONING_METHOD_SERIALPORT, APortName)) node = Options::node(OPV_POSITIONING_METHOD_SERIALPORT, APortName); else { QSerialPort *serialPort = new QSerialPort(APortName); if (serialPort->open(QIODevice::ReadOnly)) { portSettings.FBaudRate = serialPort->baudRate(); portSettings.FDataBits = serialPort->dataBits(); portSettings.FStopBits = serialPort->stopBits(); portSettings.FParity = serialPort->parity(); portSettings.FFlowControl = serialPort->flowControl(); serialPort->close(); } else // Failed to open the port node = Options::node(OPV_POSITIONING_METHOD_SERIALPORT, APortName); serialPort->deleteLater(); } if (!node.isNull()) { portSettings.FBaudRate = node.value("baud-rate").toLongLong(); portSettings.FDataBits = (QSerialPort::DataBits)node.value("data-bits").toInt(); portSettings.FStopBits = (QSerialPort::StopBits)node.value("stop-bits").toInt(); portSettings.FParity = (QSerialPort::Parity)node.value("parity").toInt(); portSettings.FFlowControl = (QSerialPort::FlowControl)node.value("flow-control").toInt(); } return portSettings; }
void SerialSetup::GetSerialport() { foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { qDebug() << "Name : " << info.portName(); QSerialPort serial; serial.setPort(info); if (serial.open(QIODevice::ReadWrite)) { serial.close(); ui->SerialPort->addItem(info.portName()); } }
void MainWindow::on_connectAction_triggered(bool connect) { if(connect) { ConnectDialog dlg(this); if(dlg.exec() == QDialog::Accepted) { if(dlg.connectionType() == Serial) { QSerialPort* serialPort = new QSerialPort(this); _ioDevice = serialPort; serialPort->setPort( dlg.serialPortInfo()); if(serialPort->open(QIODevice::ReadWrite)) { // TODO hardcoded settings if(!serialPort->setBaudRate(QSerialPort::Baud115200) || !serialPort->setDataBits(QSerialPort::Data8) || !serialPort->setParity(QSerialPort::NoParity) || !serialPort->setFlowControl(QSerialPort::NoFlowControl) || !serialPort->setStopBits(QSerialPort::TwoStop)) { serialPort->close(); QMessageBox::critical(this, "Logger", "Can't configure serial port, reason: " + serialErrorString()); return; } } else { QMessageBox::critical(this, "Logger", "Serial port connection failed, reason: " + serialErrorString(), QMessageBox::Ok); return; } } else if(dlg.connectionType() == File) { QFile* file = new QFile(dlg.fileName(), this); _ioDevice = file; } _logParser = new LogParser(_ioDevice, this); QObject::connect(_logParser, SIGNAL(logMessageReceived(QString)), SLOT(onLogMessageReceived(QString))); QObject::connect(_logParser, SIGNAL(packetParsed(Packet)), SLOT(onPacketParsed(Packet))); _logParser->setParent(0); _logParser->moveToThread(_parserThread); _parserThread->start(); _logParser->openDevice(); } } else { _ioDevice->close(); } updateStatus(); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList argumentList = QCoreApplication::arguments(); QSerialPort serialPort; QString serialPortName = "/dev/ttyUSB0"; // default int boudRate = QSerialPort::Baud115200; if (argumentList.size() == 2 ) { serialPortName = argumentList.at(0); boudRate = argumentList.at(1).toInt(); } serialPort.setPortName(serialPortName); serialPort.open(QIODevice::ReadWrite); serialPort.setBaudRate(boudRate); serialPort.setDataBits(QSerialPort::Data8); serialPort.setParity(QSerialPort::NoParity); serialPort.setStopBits(QSerialPort::OneStop); serialPort.setFlowControl(QSerialPort::NoFlowControl); SerialPortReader serialPortReader(&serialPort, 8080); serialPortReader.showSerialInfo(); return a.exec(); }
/** * This functions takes a serial port and tries if it can find a Kettler bike connected * to it. */ bool Kettler::discover(QString portName) { bool found = false; QSerialPort sp; sp.setPortName(portName); if (sp.open(QSerialPort::ReadWrite)) { m_kettlerConnection.configurePort(&sp); // Discard any existing data QByteArray data = sp.readAll(); // Read id from bike sp.write("cd\r\n"); sp.waitForBytesWritten(500); QByteArray reply = sp.readAll(); reply.append('\0'); QString replyString(reply); if (replyString.startsWith("ACK") || replyString.startsWith("RUN")) { found = true; } } sp.close(); return found; }
void ScanUART::sendAbortCmd(QSerialPort &port) { QByteArray abortCmd; abortCmd += 'a'; port.setBaudRate(QSerialPort::Baud115200); port.write(abortCmd); port.waitForBytesWritten(100); int maxCnt = 20; int cnt=0; while(port.waitForReadyRead(100)) { port.readAll(); cnt++;if(cnt>=maxCnt) break; } }
JLWidget::JLWidget(QWidget *parent) : QWidget(parent), ui(new Ui::JLWidget) { ui->setupUi(this); exusb = new ExUSB(); exusb->start(); exusbthread = new ExUSBThread(exusb); jl = new JLOpenCV(); //img = new QImage(640,480,QImage::Format_RGB32); //connect(exusbthread,SIGNAL(exusbthread->GetFrameOK()),this,SLOT(flush_image)); connect(exusbthread,SIGNAL(GetFrameOK(int)),this,SLOT(flush_image()),Qt::QueuedConnection); //connect(exusbthread,SIGNAL(exusbthread->GetFrameOK(int)),exusbthread,SLOT(test_recv())); //,Qt::QueuedConnection); //connect(this,SIGNAL(flush_image()),exusbthread,SLOT(GetFrameOK()),Qt::DirectConnection); //mVideoWidget.setParent(this); /* mVideoWidget = new QVideoWidget(); mMediaPlayer = new QMediaPlayer; QMediaContent mp = QUrl::fromLocalFile("E:\\zlj_bd.mp4"); mMediaPlayer->setMedia(mp); mMediaPlayer->setVideoOutput(mVideoWidget); //mVideoWidget->setBaseSize(1024,576); mVideoWidget->setGeometry(0,0,1024,576); mVideoWidget->show(); mMediaPlayer->play(); */ // image img = new QImage(640,480,QImage::Format_RGB32); scence = new QGraphicsScene; QPainter mPainter(ui->histwidget); mPainter.setPen(Qt::blue); mPainter.drawText(rect(),Qt::AlignCenter,"Hello WOrld"); // serialport QSerialPort *mPort = new QSerialPort(); mPort->setPortName("COM4"); mPort->setBaudRate(mPort->Baud115200); if (mPort->open(QIODevice::ReadWrite)) { mPort->write("hello"); } }
bool ScanUART::testBootMode(QSerialPort &port) { bool foundFlag = false; SearchController contr; Request req; req.setNetAddress(0); port.setBaudRate(QSerialPort::Baud115200); CommandInterface* cmd = new GetCoreVersion(); if(cmd->execute(req,port)){ contr.setBaudrate(115200); if(QString(req.getRdData()).contains("boot")) contr.setBootMode(true); else contr.setBootMode(false); contr.setAsciiMode(false); contr.setNetAddress(0); contr.setUartName(pName); if(contr.getBootMode()) { emit plcHasBeenFound(contr); foundFlag = true; } } delete cmd; if(foundFlag) return true; return false; }
bool ScanUART::scan(QSerialPort &port) { bool foundFlag = false; SearchController contr; float stepWidth = 100.0/(baudTable.count()*2); float currentPercent=0; for(int i=0;i<baudTable.count();i++) { Request req; req.setNetAddress(progAddr); port.setBaudRate(baudTable.at(i)); CommandInterface* cmdBin = new GetCoreVersion(); CommandInterface* cmdAscii = new AsciiDecorator(cmdBin); QVector<CommandInterface*> cmdList {cmdBin, cmdAscii}; foundFlag = false; foreach(CommandInterface* cmd, cmdList) { if(cmd->execute(req,port)){ contr.setBaudrate(baudTable.at(i)); if(QString(req.getRdData()).contains("Relkon")) contr.setBootMode(false); else contr.setBootMode(true); if(dynamic_cast<AsciiDecorator*>(cmd)) contr.setAsciiMode(true); else contr.setAsciiMode(false); GetCoreVersion* coreCmd = dynamic_cast<GetCoreVersion*>(cmdBin); if(coreCmd) contr.setNetAddress(coreCmd->getNetAddress()); else contr.setNetAddress(0); contr.setUartName(pName); // get canal name if(contr.getBootMode()==false) { CommandInterface* cmdGetName = new GetCanName(); if(contr.getAsciiMode()) cmdGetName = new AsciiDecorator(cmdGetName); if(cmdGetName->execute(req,port)) { contr.setCanName(QString(req.getRdData()).remove("Canal:")); } delete cmdGetName; } emit percentUpdate(100); emit plcHasBeenFound(contr); foundFlag = true; break; } currentPercent+=stepWidth; emit percentUpdate(currentPercent); } delete cmdAscii; // cmdBin удаляется декоратором mutex.lock(); if(stopCmd) {mutex.unlock();break;} mutex.unlock(); if(foundFlag) break; } if(foundFlag) return true; return false; }
bool SerialCommunication::SerialConnect(QString PortName) { // serial connect if (!serial.isOpen()) { serial.setPortName(PortName); serial.setBaudRate(QSerialPort::Baud9600); serial.setDataBits(QSerialPort::Data8); serial.setParity(QSerialPort::NoParity); serial.setStopBits(QSerialPort::OneStop); serial.setFlowControl(QSerialPort::NoFlowControl); serial.open(QIODevice::ReadWrite); serial.waitForBytesWritten(9000); if (serial.isWritable()) { return true; } } return false; }
/*! Constructs a QSerialPortInfo object from serial \a port. */ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port) { foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) { if (port.portName() == serialPortInfo.portName()) { *this = serialPortInfo; break; } } }
QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication coreApplication(argc, argv); int argumentCount = QCoreApplication::arguments().size(); QStringList argumentList = QCoreApplication::arguments(); QTextStream standardOutput(stdout); if (argumentCount == 1) { standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]").arg(argumentList.first()) << endl; return 1; } QSerialPort serialPort; QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; serialPort.setBaudRate(serialPortBaudRate); serialPort.open(QIODevice::WriteOnly); QFile dataFile; if (!dataFile.open(stdin, QIODevice::ReadOnly)) { standardOutput << QObject::tr("Failed to open stdin for reading") << endl; return 1; } QByteArray writeData(dataFile.readAll()); dataFile.close(); if (writeData.isEmpty()) { standardOutput << QObject::tr("Either no data was currently available on the standard input for reading, or an error occurred for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } SerialPortWriter serialPortWriter(&serialPort); serialPortWriter.write(writeData); return coreApplication.exec(); }
bool CommInterface::openPort(const QString& portname, const QString& baudrate) { QSerialPort* port = new QSerialPort(portname); _port = port; connect(port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handleSerialError(QSerialPort::SerialPortError))); _protocol = new Comm::RobotProtocol(port, 0, true); _protocol->beQuiet(true); _protocol->setDebugMode(true, false, false); if (_protocol->open()) { port->setBaudRate(baudrate.toInt()); port->setFlowControl(QSerialPort::NoFlowControl); port->setParity(QSerialPort::NoParity); port->setDataBits(QSerialPort::Data8); port->setStopBits(QSerialPort::OneStop); } else { delete _protocol; _protocol = 0; return false; } _comm = new Comm::RobotCommInterface(_protocol, new Comm::AX12CommManager, 0, this, this); changeStatus(true); return true; }
void MainWindow::initPort() { foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){ QSerialPort serialtmp; serialtmp.setPort(info); /* 判断端口是否能打开 */ if(serialtmp.open(QIODevice::ReadWrite)) { int isHaveItemInList = 0; /* 判断是不是已经在列表中了 */ for(int i=0; i<ui->portNameCombo->count(); i++) { /* 如果,已经在列表中了,那么不添加这一项了就 */ if(ui->portNameCombo->itemData(i) == serialtmp.portName()) { isHaveItemInList++; } } if(isHaveItemInList == 0) { ui->portNameCombo->addItem(serialtmp.portName()); } serialtmp.close(); } }
/** * This functions takes a serial port and tries if it can find a Monark bike connected * to it. */ bool MonarkConnection::discover(QString portName) { bool found = false; QSerialPort sp; sp.setPortName(portName); if (sp.open(QSerialPort::ReadWrite)) { configurePort(&sp); // Discard any existing data QByteArray data = sp.readAll(); // Read id from bike sp.write("id\r"); sp.waitForBytesWritten(-1); QByteArray id; do { bool readyToRead = sp.waitForReadyRead(1000); if (readyToRead) { id.append(sp.readAll()); } else { id.append('\r'); } } while ((id.indexOf('\r') == -1)); id.replace("\r", "\0"); // Should check for all bike ids known to use this protocol if (QString(id).toLower().contains("lt") || QString(id).toLower().contains("lc") || QString(id).toLower().contains("novo")) { found = true; } } sp.close(); return found; }
QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication coreApplication(argc, argv); int argumentCount = QCoreApplication::arguments().size(); QStringList argumentList = QCoreApplication::arguments(); QTextStream standardOutput(stdout); if (argumentCount == 1) { standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]").arg(argumentList.first()) << endl; return 1; } QSerialPort serialPort; QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; serialPort.setBaudRate(serialPortBaudRate); if (!serialPort.open(QIODevice::ReadOnly)) { standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.error()) << endl; return 1; } QByteArray readData = serialPort.readAll(); while (serialPort.waitForReadyRead(5000)) readData.append(serialPort.readAll()); if (serialPort.error() == QSerialPort::ReadError) { standardOutput << QObject::tr("Failed to read from port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } else if (serialPort.error() == QSerialPort::TimeoutError && readData.isEmpty()) { standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(serialPortName) << endl; return 0; } standardOutput << QObject::tr("Data successfully received from port %1").arg(serialPortName) << endl; standardOutput << readData << endl; return 0; }
QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication coreApplication(argc, argv); int argumentCount = QCoreApplication::arguments().size(); QStringList argumentList = QCoreApplication::arguments(); QTextStream standardOutput(stdout); if (argumentCount == 1) { standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]").arg(argumentList.first()) << endl; return 1; } QSerialPort serialPort; QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; serialPort.setBaudRate(serialPortBaudRate); if (!serialPort.open(QIODevice::WriteOnly)) { standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } QFile dataFile; if (!dataFile.open(stdin, QIODevice::ReadOnly)) { standardOutput << QObject::tr("Failed to open stdin for reading") << endl; return 1; } QByteArray writeData(dataFile.readAll()); dataFile.close(); if (writeData.isEmpty()) { standardOutput << QObject::tr("Either no data was currently available on the standard input for reading, or an error occurred for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } qint64 bytesWritten = serialPort.write(writeData); if (bytesWritten == -1) { standardOutput << QObject::tr("Failed to write the data to port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } else if (bytesWritten != writeData.size()) { standardOutput << QObject::tr("Failed to write all the data to port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } else if (!serialPort.waitForBytesWritten(5000)) { standardOutput << QObject::tr("Operation timed out or an error occurred for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } standardOutput << QObject::tr("Data successfully sent to port %1").arg(serialPortName) << endl; return 0; }
bool Generator::setConnection(const QString &portName, const int &new_baudrate, const QString &new_generatorType) { if (new_generatorType.trimmed().toUpper() == "DS335") { if (this->ds335 == nullptr) this->ds335 = new DS335(); this->generatorType = "DS335"; return this->ds335->setConnection(portName, new_baudrate); } if (new_generatorType.trimmed().toUpper() == "DS345") { if (this->ds345 == nullptr) this->ds345 = new DS345(); this->generatorType = "DS345"; return this->ds345->setConnection(portName, new_baudrate); } if (new_generatorType.trimmed().isEmpty() || new_generatorType.trimmed().toUpper() == "AUTO") { QSerialPort *serial = new QSerialPort(); serial->setPortName(portName); serial->setBaudRate(new_baudrate); return autoSetGeneratorType(serial); } return false; }
/*! Create and open a serial device from a \a name of the form \c{device:rate}. Returns NULL if the device could not be opened. The \a defaultRate parameter indicates the default rate to use if \c{:rate} was not included in the device name. If \a flowControl is true, then CTS/RTS flow control should be enabled on the device. The \a name parameter can have the special form \c{sim:hostname}, where \c hostname is the name of a host running a phone simulator daemon (usually \c localhost). The phone simulator mode is intended for debugging purposes only. */ QSerialPort *QSerialPort::create( const QString& name, int defaultRate, bool flowControl ) { int rate = defaultRate; QString dev = name; if ( dev.length() > 0 && dev[0] == '/' ) { int index = dev.indexOf(QChar(':')); if ( index != -1 ) { rate = dev.mid( index + 1 ).toInt(); dev = dev.left( index ); } } qDebug() << "opening serial device " << dev << " at " << rate; QSerialPort *device = new QSerialPort( dev, rate ); device->setFlowControl( flowControl ); if ( !device->open( ReadWrite ) ) { qWarning() << "Failed opening " << dev; delete device; return 0; } else { qDebug() << "Opened " << dev; return device; } }
void MainWindow::updateStatus() { if(_ioDevice && _ioDevice->isOpen()) { QString device; QSerialPort* serial = qobject_cast<QSerialPort*>(_ioDevice); if(serial != NULL) device = serial->portName(); QFile* file = qobject_cast<QFile*>(_ioDevice); if(file != NULL) device = file->fileName(); _connectionStatusLabel->setText(QString("Connected to: %1").arg(device)); } else { _connectionStatusLabel->setText(QString("Not connected")); } _packetsReceivedCountLabel->setText(QString("Packets received: %1").arg(_packetsReceivedCount)); _crcErrorsCountLabel->setText(QString("Packets with CRC errors: %2").arg(_crcErrorCount)); }
bool pf_mcontroller::setup (QSerialPort& port) { //Set unlimited Rx buffer size port.setReadBufferSize(0); return port.setBaudRate(QSerialPort::Baud9600) || port.setDataBits(QSerialPort::Data8) || port.setParity(QSerialPort::NoParity) || port.setStopBits(QSerialPort::OneStop) || port.setFlowControl(QSerialPort::NoFlowControl); }
void MainWindow::run() { QSerialPort availableport; while(true){ availableport.setPortName("COM6"); availableport.open(QIODevice::ReadOnly); availableport.setBaudRate(QSerialPort::Baud9600); availableport.setDataBits(QSerialPort::Data8); availableport.setParity(QSerialPort::NoParity); availableport.setStopBits(QSerialPort::OneStop); availableport.setFlowControl(QSerialPort::NoFlowControl); if(availableport.isOpen()){ //DEBUG MODE ON bioGuised->show(); delay(5000); } else{ bioGuised->hide(); } } }