Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Spanish
  4. Comunicacion serial usando Qt y Visual Studio
Forum Updated to NodeBB v4.3 + New Features

Comunicacion serial usando Qt y Visual Studio

Scheduled Pinned Locked Moved Spanish
2 Posts 1 Posters 1.1k 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.
  • F Offline
    F Offline
    Falcon2050
    wrote on last edited by
    #1

    Hola a todos:
    Me gustaria amablemente preguntarles acerca de como poder realizar la comunicacion serial con Qt, he intentado de muchas formas pero ninguna me ha funcionado.
    Si alguien de ustedes tiene experiencia en esto, le estare realmente muy agradecido.
    Que tengan un lindo dia.

    P.S: Uso Qt dentro de Visual Studio, y estoy tratando de desarrollar una aplicacion de consola.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Falcon2050
      wrote on last edited by
      #2

      Aqui les dejo el codigo que tengo hasta ahora :

      //mytimer.hpp

      #ifndef MYTIMER_HPP
      #define MYTIMER_HPP

      #include <QtSerialPort/QtSerialPort>
      #include <QTimer>
      #include <QThread>
      #include <QObject>

      class MyTimer : public QObject
      { Q_OBJECT

      public: MyTimer(int,int); QSerialPort serial; QTimer timer; int how_many_times; int sampling;

      signals: void done();

      public slots: void MyTimerSlot();
      };

      #endif // MYTIMER_H

      //mytimer.cpp

      //#include <QtSerialPort/QtSerialPort>
      #include “mytimer.hpp”
      #include <QDebug>

      MyTimer::MyTimer(int a, int b)
      { how_many_times = a; sampling = b;
      connect(&timer, SIGNAL), this, SLOT)); timer.setInterval(sampling); timer.start();

      }

      void MyTimer::MyTimerSlot()
      {
      if (how_many_times == 1) { timer.stop(); } /==========================================================================/ serial.setPortName(“COM1”); 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.write(“hello”); serial.close(); /==========================================================================/ qDebug() << “hello” ; how_many_times -= 1; if (how_many_times == 0) { done(); }

      }

      //main.cpp

      #include <QCoreApplication>
      #include “mytimer.hpp”

      int main(int argc, char *argv[])
      { QCoreApplication a(argc, argv);
      MyTimer timer(20,500); QObject::connect(&timer, SIGNAL), &a, SLOT)); return a.exec(); }

      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