Hello all,
I was writing code for RFID reader interfacing for my pc. RFID reader is responding fine with my minicom program ...but from the application code it is saying unable to open port.
Here is my code...
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
textEdit=ui->textEdit;
qDebug() << "Number of serial ports:" << QSerialPortInfo::availablePorts().count();
foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
{
qDebug()<<"Name: "<<info.portName();
qDebug()<<"Description: "<<info.description();
qDebug()<<"Manufactures: "<<info.manufacturer();
QSerialPort *port = new QSerialPort(info);
qDebug() << "Baud rate:" << port->baudRate();
qDebug() << "Data bits:" << port->dataBits();
qDebug() << "Stop bits:" << port->stopBits();
qDebug() << "Parity:" << port->parity();
qDebug() << "Flow control:" << port->flowControl();
qDebug() << "Read buffer size:" << port->readBufferSize();
port->close();
} else {
qDebug() << "Unable to open port, error code" << port->error();
}
}
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
textEdit=ui->textEdit;
qDebug() << "Number of serial ports:" << QSerialPortInfo::availablePorts().count();
foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
{
qDebug()<<"Name: "<<info.portName();
qDebug()<<"Description: "<<info.description();
qDebug()<<"Manufactures: "<<info.manufacturer();
QSerialPort *port = new QSerialPort(info);
if (port->open(QIODevice::ReadWrite)) {
qDebug() << "Baud rate:" << port->baudRate();
qDebug() << "Data bits:" << port->dataBits();
qDebug() << "Stop bits:" << port->stopBits();
qDebug() << "Parity:" << port->parity();
qDebug() << "Flow control:" << port->flowControl();
qDebug() << "Read buffer size:" << port->readBufferSize();
port->close();
} else {
qDebug() << "Unable to open port, error code" << port->error();
}
}
}
To copy to clipboard, switch view to plain text mode
The output i am getting is
---------------------------------
Number of serial ports: 1
Name: "ttyS0"
Description: ""
Manufactures: ""
Unable to open port, error code 2
--------------------------------------------
Thanks in advance.
Bookmarks