Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Problem sending data via the serial port to the XBee radio module via the RS232 cable
Forum Updated to NodeBB v4.3 + New Features

Problem sending data via the serial port to the XBee radio module via the RS232 cable

Scheduled Pinned Locked Moved Game Development
2 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SALA-BANAKISSA
    wrote on last edited by
    #1

    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);
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Isn't this thread a duplicate of "this":http://qt-project.org/forums/viewthread/39539/ ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved