Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Comunicacion serial usando Qt y Visual Studio

    Spanish
    1
    2
    912
    Loading More Posts
    • 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
      Falcon2050 last edited by

      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 Reply Quote 0
      • F
        Falcon2050 last edited by

        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 Reply Quote 0
        • First post
          Last post