PDA

View Full Version : Getting problem in writing command to serial port



prasad1001
6th March 2014, 08:38
Hello all,
First of all sorry for my English,,,

I am biggner in Qt, I have a need to read and write from a QT program to a serial port(fingerprint module r305). I was written code for write and read functions..
My problem is when i write something to the serial port i need an ack signal to the serial port but nothing is happning.

And my debug output giving error as "No such process" as shown in below.

Here is my code...



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();
port=new QSerialPort(info);

qDebug()<<port->open(QIODevice::ReadWrite) <<" ok";
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();
} else {
qDebug() << "Unable to open port, error code" << port->error();
qDebug()<< port->errorString();
}
connect(port,SIGNAL(readyRead()),this,SLOT(readDat a()));
}
}


void MainWindow::on_pushButton_clicked()
{
writeData("0xEF01FFFFFFFF010003100005");
}

void MainWindow::writeData(char *msg)
{
port->write(msg);
qDebug()<<port->errorString();
qDebug() << "Error code:" << port->error();
textEdit->append("writing data:");
textEdit->append(msg);

QTimer *timee=new QTimer(this);
timee->start(1000);
port->flush();
}

void MainWindow::readData()
{
port->flush();
QString response=port->readAll();
textEdit->append(response);
}

void MainWindow::on_pushButton_2_clicked()
{
exit(0);
}



And my debug output giving error as "No such process" as shown in below.

Number of serial ports: 1
Name: "ttyS0"
true ok
Baud rate: 9600
Data bits: 8
Stop bits: 1
Parity: 0
Flow control: 0
Read buffer size: 0
"No such process"
Error code: 3

Please help me...and thanks in advance..