Problem sending data via the serial port to the XBee radio module via the RS232 cable
-
I have a problem opening the COM1 and communication to the xbee, I came writing even a single character even read what I get, is that a person of good will could help me if please? this is urgent, thank you.
Here is the code of my program:
connect(Bouton1, SIGNAL(clicked()), this, SLOT(on_pushButton_3_clicked()));
void Interface::on_pushButton_3_clicked()
{
// const QTime *temp ;//Si on clique sur "Start" if(validStart == true) { // Permet de savoir que le bouton est en mode "Stop" validStart = false; connect(m_timer, SIGNAL(timeout()), this, SLOT(update())); // On déclenche le départ du Timer m_timer->start(1000); serialTimer->setSingleShot(true); QObject ::connect(this, SIGNAL(writeRequest(QByteArray)), this, SLOT(writeSerial(QByteArray))); QObject ::connect(serial, SIGNAL(readyRead()), this, SLOT(handleResponse())); QObject ::connect(serialTimer, SIGNAL(timeout()), this, SLOT(processTimeout())); } // Si on clique sur "Stop" else { // Permet de savoir que le bouton est en mode "Start" validStart = true; // On arrête le compteur m_timer->stop(); }
}
voiid Interface::writeSerial(QByteArray C)
{serial->open(QIODevice::ReadWrite); serial->setBaudRate(9600); if (serial->portName()!= "COM1")
{
serial->close(); serial->setPortName("COM1"); if (!serial->open(QIODevice::ReadWrite)) { processError(tr("Can't open %1, error code %2").arg(serial->portName()).arg(serial->error())); return; } if (!serial->setBaudRate(QSerialPort::Baud19200))
{
processError(tr("Can't set rate 19200 baud to port %1, error code %2")
.arg(serial->portName()).arg(serial->error()));return; } if (!serial->setDataBits(QSerialPort::Data8))
{
processError(tr("Can't set 8 data bits to port %1, error code %2")
.arg(serial->portName()).arg(serial->error()));return; } if (!serial->setParity(QSerialPort::NoParity))
{
processError(tr("Can't set no patity to port %1, error code %2") .arg(serial->portName()).arg(serial->error())); return; } if (!serial->setStopBits(QSerialPort::OneStop))
{
processError(tr("Can't set 1 stop bit to port %1, error code %2")
.arg(serial->portName()).arg(serial->error()));return; } if (!serial->setFlowControl(QSerialPort::NoFlowControl))
{
processError(tr("Can't set no flow control to port %1, error code %2")
.arg(serial->portName()).arg(serial->error()));return; } } qDebug() << "Message written"; this->msgRequest = "O"; serial->write(msgRequest); serialTimer->start(400);
}
-
Isn't this thread a duplicate of "this":http://qt-project.org/forums/viewthread/39539/ ?