Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Regarding Projector Programming using QT
Forum Updated to NodeBB v4.3 + New Features

Regarding Projector Programming using QT

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 5 Posters 3.6k Views 2 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.
  • P Prath

    I am writing a code in QT to send the command to the projector to switch it on-off. I tried to send the command but the serial port didn't respond to the command. Following is the basic code written.
    Can anyone help me to decipher what is wrong?

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <QDebug>
    #include<QSerialPort>
    #include<string>
    using namespace std;
    QSerialPort *serial;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    SetupPort();

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    void MainWindow::SetupPort()
    {
    serial = new QSerialPort(this);
    serial->setPortName("COM3");
    serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
    serial->setDataBits(QSerialPort::Data8);
    serial->setFlowControl(QSerialPort::NoFlowControl);
    serial->setStopBits(QSerialPort::OneStop);
    serial->setParity(QSerialPort::NoParity);

    if(!serial->open(QIODevice::ReadWrite))
    {
        qDebug()<<"error: can't open com port";
    }
    
    for(int i=1;i<100;i++)
    

    { //serial->write("57542b4c4544453d31");
    serial->write("WT+LEDE=1");
    QByteArray data = serial->readAll();

    qDebug() << data;
    

    }
    }

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #2

    @Prath
    Assuming your command works, you cannot expect the readAll() immediately after the write() to read the response. It will only read whatever happens to be available when it is called. You really need a signal/slot here. So you keep sending that command, I don't know if that matters.

    1 Reply Last reply
    4
    • P Prath

      I am writing a code in QT to send the command to the projector to switch it on-off. I tried to send the command but the serial port didn't respond to the command. Following is the basic code written.
      Can anyone help me to decipher what is wrong?

      #include "mainwindow.h"
      #include "ui_mainwindow.h"

      #include <QDebug>
      #include<QSerialPort>
      #include<string>
      using namespace std;
      QSerialPort *serial;

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      SetupPort();

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }
      void MainWindow::SetupPort()
      {
      serial = new QSerialPort(this);
      serial->setPortName("COM3");
      serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
      serial->setDataBits(QSerialPort::Data8);
      serial->setFlowControl(QSerialPort::NoFlowControl);
      serial->setStopBits(QSerialPort::OneStop);
      serial->setParity(QSerialPort::NoParity);

      if(!serial->open(QIODevice::ReadWrite))
      {
          qDebug()<<"error: can't open com port";
      }
      
      for(int i=1;i<100;i++)
      

      { //serial->write("57542b4c4544453d31");
      serial->write("WT+LEDE=1");
      QByteArray data = serial->readAll();

      qDebug() << data;
      

      }
      }

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #3

      @Prath said in Regarding Projector Programming using QT:

      what is wrong?

      Not using signal & slots, as @JonB suggested already.
      Have you taken a look at Serial Terminal example?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • P Offline
        P Offline
        Prath
        wrote on last edited by
        #4

        I have used the Qserial port program from Git. The program can connect to the serial port. However, I still could not switch off the projector using the command "WT+LEDE=0".
        Any help in this regards? Our entire project is stuck because of this command being not sent to the projector.

        /****************************************************************************
        **
        ** Copyright (C) 2012 Denis Shienkov denis.shienkov@gmail.com
        ** Copyright (C) 2012 Laszlo Papp lpapp@kde.org
        ** Contact: http://www.qt-project.org/legal
        **
        ** This file is part of the QtSerialPort module of the Qt Toolkit.
        **
        ** $QT_BEGIN_LICENSE:LGPL21$
        ** Commercial License Usage
        ** Licensees holding valid commercial Qt licenses may use this file in
        ** accordance with the commercial license agreement provided with the
        ** Software or, alternatively, in accordance with the terms contained in
        ** a written agreement between you and Digia. For licensing terms and
        ** conditions see http://qt.digia.com/licensing. For further information
        ** use the contact form at http://qt.digia.com/contact-us.
        **
        ** GNU Lesser General Public License Usage
        ** Alternatively, this file may be used under the terms of the GNU Lesser
        ** General Public License version 2.1 or version 3 as published by the Free
        ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
        ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
        ** following information to ensure the GNU Lesser General Public License
        ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
        ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
        **
        ** In addition, as a special exception, Digia gives you certain additional
        ** rights. These rights are described in the Digia Qt LGPL Exception
        ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
        **
        ** $QT_END_LICENSE$
        **
        ****************************************************************************/

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include "console.h"
        #include "settingsdialog.h"

        #include <QMessageBox>
        #include <QtSerialPort/QSerialPort>
        #include <QDebug>
        #include <QLabel>
        #include <QPixmap>
        #include <QFile>
        #include <QTextStream>

        //! [0]
        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        //! [0]
        ui->setupUi(this);
        console = new Console;
        console->setEnabled(false);
        setCentralWidget(console);
        //! [1]
        serial = new QSerialPort(this);
        //! [1]
        settings = new SettingsDialog;

        ui->actionConnect->setEnabled(true);
        ui->actionDisconnect->setEnabled(false);
        ui->actionQuit->setEnabled(true);
        ui->actionConfigure->setEnabled(true);
        
        initActionsConnections();
        
        connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
                SLOT(handleError(QSerialPort::SerialPortError)));
        

        //! [2]
        connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
        //! [2]
        connect(console, SIGNAL(getData(QByteArray)), this, SLOT(writeData(QByteArray)));
        //! [3]
        }
        //! [3]

        MainWindow::~MainWindow()
        {
        delete settings;
        delete ui;
        }

        //! [4]
        void MainWindow::openSerialPort()
        {
        SettingsDialog::Settings p = settings->settings();
        serial->setPortName(p.name);
        if (serial->open(QIODevice::ReadWrite)) {
        if (serial->setBaudRate(p.baudRate)
        && serial->setDataBits(p.dataBits)
        && serial->setParity(p.parity)
        && serial->setStopBits(p.stopBits)
        && serial->setFlowControl(p.flowControl)) {

                console->setEnabled(true);
                console->setLocalEchoEnabled(p.localEchoEnabled);
                ui->actionConnect->setEnabled(false);
                ui->actionDisconnect->setEnabled(true);
                ui->actionConfigure->setEnabled(false);
                ui->statusBar->showMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
                                           .arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
                                           .arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
        
            } else {
                serial->close();
                QMessageBox::critical(this, tr("Error"), serial->errorString());
        
                ui->statusBar->showMessage(tr("Open error"));
            }
        } else {
            QMessageBox::critical(this, tr("Error"), serial->errorString());
        
            ui->statusBar->showMessage(tr("Configure error"));
        }
        

        }
        //! [4]

        //! [5]
        void MainWindow::closeSerialPort()
        {
        serial->close();
        console->setEnabled(false);
        ui->actionConnect->setEnabled(true);
        ui->actionDisconnect->setEnabled(false);
        ui->actionConfigure->setEnabled(true);
        ui->statusBar->showMessage(tr("Disconnected"));
        }
        //! [5]

        void MainWindow::about()
        {
        QMessageBox::about(this, tr("About Simple Terminal"),
        tr("The <b>Simple Terminal</b> example demonstrates how to "
        "use the Qt Serial Port module in modern GUI applications "
        "using Qt, with a menu bar, toolbars, and a status bar."));
        }

        //! [6]
        void MainWindow::writeData(const QByteArray &data)
        {
        serial->write(data);
        }
        //! [6]

        //! [7]
        void MainWindow::readData()
        {
        QByteArray data = serial->readAll();
        console->putData(data);
        }
        //! [7]

        //! [8]
        void MainWindow::handleError(QSerialPort::SerialPortError error)
        {
        if (error == QSerialPort::ResourceError) {
        QMessageBox::critical(this, tr("Critical Error"), serial->errorString());
        closeSerialPort();
        }
        }
        //! [8]

        void MainWindow::initActionsConnections()
        {
        connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(openSerialPort()));
        connect(ui->actionDisconnect, SIGNAL(triggered()), this, SLOT(closeSerialPort()));
        connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
        connect(ui->actionConfigure, SIGNAL(triggered()), settings, SLOT(show()));
        connect(ui->actionClear, SIGNAL(triggered()), console, SLOT(clear()));
        connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
        connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
        }

        JonBJ 1 Reply Last reply
        0
        • P Prath

          I have used the Qserial port program from Git. The program can connect to the serial port. However, I still could not switch off the projector using the command "WT+LEDE=0".
          Any help in this regards? Our entire project is stuck because of this command being not sent to the projector.

          /****************************************************************************
          **
          ** Copyright (C) 2012 Denis Shienkov denis.shienkov@gmail.com
          ** Copyright (C) 2012 Laszlo Papp lpapp@kde.org
          ** Contact: http://www.qt-project.org/legal
          **
          ** This file is part of the QtSerialPort module of the Qt Toolkit.
          **
          ** $QT_BEGIN_LICENSE:LGPL21$
          ** Commercial License Usage
          ** Licensees holding valid commercial Qt licenses may use this file in
          ** accordance with the commercial license agreement provided with the
          ** Software or, alternatively, in accordance with the terms contained in
          ** a written agreement between you and Digia. For licensing terms and
          ** conditions see http://qt.digia.com/licensing. For further information
          ** use the contact form at http://qt.digia.com/contact-us.
          **
          ** GNU Lesser General Public License Usage
          ** Alternatively, this file may be used under the terms of the GNU Lesser
          ** General Public License version 2.1 or version 3 as published by the Free
          ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
          ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
          ** following information to ensure the GNU Lesser General Public License
          ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
          ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
          **
          ** In addition, as a special exception, Digia gives you certain additional
          ** rights. These rights are described in the Digia Qt LGPL Exception
          ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
          **
          ** $QT_END_LICENSE$
          **
          ****************************************************************************/

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include "console.h"
          #include "settingsdialog.h"

          #include <QMessageBox>
          #include <QtSerialPort/QSerialPort>
          #include <QDebug>
          #include <QLabel>
          #include <QPixmap>
          #include <QFile>
          #include <QTextStream>

          //! [0]
          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          //! [0]
          ui->setupUi(this);
          console = new Console;
          console->setEnabled(false);
          setCentralWidget(console);
          //! [1]
          serial = new QSerialPort(this);
          //! [1]
          settings = new SettingsDialog;

          ui->actionConnect->setEnabled(true);
          ui->actionDisconnect->setEnabled(false);
          ui->actionQuit->setEnabled(true);
          ui->actionConfigure->setEnabled(true);
          
          initActionsConnections();
          
          connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
                  SLOT(handleError(QSerialPort::SerialPortError)));
          

          //! [2]
          connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
          //! [2]
          connect(console, SIGNAL(getData(QByteArray)), this, SLOT(writeData(QByteArray)));
          //! [3]
          }
          //! [3]

          MainWindow::~MainWindow()
          {
          delete settings;
          delete ui;
          }

          //! [4]
          void MainWindow::openSerialPort()
          {
          SettingsDialog::Settings p = settings->settings();
          serial->setPortName(p.name);
          if (serial->open(QIODevice::ReadWrite)) {
          if (serial->setBaudRate(p.baudRate)
          && serial->setDataBits(p.dataBits)
          && serial->setParity(p.parity)
          && serial->setStopBits(p.stopBits)
          && serial->setFlowControl(p.flowControl)) {

                  console->setEnabled(true);
                  console->setLocalEchoEnabled(p.localEchoEnabled);
                  ui->actionConnect->setEnabled(false);
                  ui->actionDisconnect->setEnabled(true);
                  ui->actionConfigure->setEnabled(false);
                  ui->statusBar->showMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
                                             .arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
                                             .arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
          
              } else {
                  serial->close();
                  QMessageBox::critical(this, tr("Error"), serial->errorString());
          
                  ui->statusBar->showMessage(tr("Open error"));
              }
          } else {
              QMessageBox::critical(this, tr("Error"), serial->errorString());
          
              ui->statusBar->showMessage(tr("Configure error"));
          }
          

          }
          //! [4]

          //! [5]
          void MainWindow::closeSerialPort()
          {
          serial->close();
          console->setEnabled(false);
          ui->actionConnect->setEnabled(true);
          ui->actionDisconnect->setEnabled(false);
          ui->actionConfigure->setEnabled(true);
          ui->statusBar->showMessage(tr("Disconnected"));
          }
          //! [5]

          void MainWindow::about()
          {
          QMessageBox::about(this, tr("About Simple Terminal"),
          tr("The <b>Simple Terminal</b> example demonstrates how to "
          "use the Qt Serial Port module in modern GUI applications "
          "using Qt, with a menu bar, toolbars, and a status bar."));
          }

          //! [6]
          void MainWindow::writeData(const QByteArray &data)
          {
          serial->write(data);
          }
          //! [6]

          //! [7]
          void MainWindow::readData()
          {
          QByteArray data = serial->readAll();
          console->putData(data);
          }
          //! [7]

          //! [8]
          void MainWindow::handleError(QSerialPort::SerialPortError error)
          {
          if (error == QSerialPort::ResourceError) {
          QMessageBox::critical(this, tr("Critical Error"), serial->errorString());
          closeSerialPort();
          }
          }
          //! [8]

          void MainWindow::initActionsConnections()
          {
          connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(openSerialPort()));
          connect(ui->actionDisconnect, SIGNAL(triggered()), this, SLOT(closeSerialPort()));
          connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
          connect(ui->actionConfigure, SIGNAL(triggered()), settings, SLOT(show()));
          connect(ui->actionClear, SIGNAL(triggered()), console, SLOT(clear()));
          connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
          connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
          }

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #5

          @Prath said in Regarding Projector Programming using QT:

          connect(console, SIGNAL(getData(QByteArray)), this, SLOT(writeData(QByteArray)));
          

          I would at least verify that whatever console getData() is it does return the exact right string to send on to the port. E.g. I don't know if waits till you type a newline or sends characters immediately, and/or whether it sends that newline and that matters.

          At this point, how have you been able to verify your command works in principle outside of anything Qt?

          1 Reply Last reply
          1
          • P Offline
            P Offline
            Prath
            wrote on last edited by
            #6

            We are using a projector application to send command to the projector.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Prath
              wrote on last edited by
              #7

              However, I am not able to write anythinh in the window created after running the Qt programme

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

                Hi,

                Write what ?
                Write where ?
                In what window ?

                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
                • P Offline
                  P Offline
                  Prath
                  wrote on last edited by
                  #9

                  Hey @SGaist , after running the above programme , a GUI pops out. We have to send a command to the projector using the GUI. However, I couldn't send any commnad as nothing could be written on the GUI window.

                  Pablo J. RoginaP 1 Reply Last reply
                  0
                  • P Prath

                    Hey @SGaist , after running the above programme , a GUI pops out. We have to send a command to the projector using the GUI. However, I couldn't send any commnad as nothing could be written on the GUI window.

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #10

                    @Prath said in Regarding Projector Programming using QT:

                    after running the above programme

                    which program?
                    The Serial Terminal example I suggested before?

                    Have you tested managing the projector using any other terminal application? Just to validate it works fine...

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Prath
                      wrote on last edited by
                      #11

                      Yes. @Pablo-J-Rogina . I am connecting the projector to Quectel QCOM application. Now I want to skip that application and create my customised application to control the projector.

                      I wrote a programme based on the guidelines of Quectel to switch off the projector. Following is the code. Even I used the QSerialPort code. But the projector couldn't switch off. However using the command prompt of the Quectel QCOM application, I could control the projector.

                      main.cpp

                      #include "mainwindow.h"

                      #include <QApplication>

                      int main(int argc, char *argv[])
                      {
                      QApplication a(argc, argv);
                      MainWindow w;
                      w.show();
                      return a.exec();
                      }

                      mainwindow.cpp

                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"
                      #include <QDebug>
                      #include<QSerialPort>
                      #include<string>
                      #include<QtGui>
                      #include <QMessageBox>

                      using namespace std;
                      QSerialPort *serial;
                      MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      }

                      MainWindow::~MainWindow()
                      {
                      delete ui;
                      }

                      void MainWindow::on_pushButton_clicked()
                      {
                      QMessageBox::information(this,"Title here","Hello World");
                      serial = new QSerialPort(this);
                      serial->setPortName("COM3");
                      serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
                      serial->setDataBits(QSerialPort::Data8);
                      serial->setFlowControl(QSerialPort::NoFlowControl);
                      serial->setStopBits(QSerialPort::OneStop);
                      serial->setParity(QSerialPort::NoParity);

                      if(!serial->open(QIODevice::ReadWrite))
                      {
                          qDebug()<<"error: can't open com port";
                      }
                      
                      QString command = "WT+LEDE=0\n";
                      QByteArray x = command.toLocal8Bit();
                      serial->write(x);
                      

                      }

                      mainwindow.h

                      #ifndef MAINWINDOW_H
                      #define MAINWINDOW_H

                      #include <QMainWindow>

                      QT_BEGIN_NAMESPACE
                      namespace Ui { class MainWindow; }
                      QT_END_NAMESPACE

                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT

                      public:
                      MainWindow(QWidget *parent = nullptr);
                      ~MainWindow();

                      private slots:
                      void on_pushButton_clicked();

                      private:
                      Ui::MainWindow *ui;
                      };
                      #endif // MAINWINDOW_H

                      #-------------------------------------------------

                      Project created by QtCreator 2019-11-02T10:55:21

                      #-------------------------------------------------

                      QT += core gui serialport

                      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                      TARGET = GUISerialPort
                      TEMPLATE = app

                      SOURCES += main.cpp
                      mainwindow.cpp

                      HEADERS += mainwindow.h

                      FORMS += mainwindow.ui

                      jsulmJ 1 Reply Last reply
                      0
                      • P Prath

                        Yes. @Pablo-J-Rogina . I am connecting the projector to Quectel QCOM application. Now I want to skip that application and create my customised application to control the projector.

                        I wrote a programme based on the guidelines of Quectel to switch off the projector. Following is the code. Even I used the QSerialPort code. But the projector couldn't switch off. However using the command prompt of the Quectel QCOM application, I could control the projector.

                        main.cpp

                        #include "mainwindow.h"

                        #include <QApplication>

                        int main(int argc, char *argv[])
                        {
                        QApplication a(argc, argv);
                        MainWindow w;
                        w.show();
                        return a.exec();
                        }

                        mainwindow.cpp

                        #include "mainwindow.h"
                        #include "ui_mainwindow.h"
                        #include <QDebug>
                        #include<QSerialPort>
                        #include<string>
                        #include<QtGui>
                        #include <QMessageBox>

                        using namespace std;
                        QSerialPort *serial;
                        MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                        {
                        ui->setupUi(this);
                        }

                        MainWindow::~MainWindow()
                        {
                        delete ui;
                        }

                        void MainWindow::on_pushButton_clicked()
                        {
                        QMessageBox::information(this,"Title here","Hello World");
                        serial = new QSerialPort(this);
                        serial->setPortName("COM3");
                        serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
                        serial->setDataBits(QSerialPort::Data8);
                        serial->setFlowControl(QSerialPort::NoFlowControl);
                        serial->setStopBits(QSerialPort::OneStop);
                        serial->setParity(QSerialPort::NoParity);

                        if(!serial->open(QIODevice::ReadWrite))
                        {
                            qDebug()<<"error: can't open com port";
                        }
                        
                        QString command = "WT+LEDE=0\n";
                        QByteArray x = command.toLocal8Bit();
                        serial->write(x);
                        

                        }

                        mainwindow.h

                        #ifndef MAINWINDOW_H
                        #define MAINWINDOW_H

                        #include <QMainWindow>

                        QT_BEGIN_NAMESPACE
                        namespace Ui { class MainWindow; }
                        QT_END_NAMESPACE

                        class MainWindow : public QMainWindow
                        {
                        Q_OBJECT

                        public:
                        MainWindow(QWidget *parent = nullptr);
                        ~MainWindow();

                        private slots:
                        void on_pushButton_clicked();

                        private:
                        Ui::MainWindow *ui;
                        };
                        #endif // MAINWINDOW_H

                        #-------------------------------------------------

                        Project created by QtCreator 2019-11-02T10:55:21

                        #-------------------------------------------------

                        QT += core gui serialport

                        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                        TARGET = GUISerialPort
                        TEMPLATE = app

                        SOURCES += main.cpp
                        mainwindow.cpp

                        HEADERS += mainwindow.h

                        FORMS += mainwindow.ui

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @Prath said in Regarding Projector Programming using QT:

                        if(!serial->open(QIODevice::ReadWrite))

                        Does open() succeed?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        P 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Prath said in Regarding Projector Programming using QT:

                          if(!serial->open(QIODevice::ReadWrite))

                          Does open() succeed?

                          P Offline
                          P Offline
                          Prath
                          wrote on last edited by
                          #13

                          @jsulm Yes. Open succeeded. But still, the projector could not read the commands which I am sending through serial port.

                          jsulmJ 1 Reply Last reply
                          0
                          • P Prath

                            @jsulm Yes. Open succeeded. But still, the projector could not read the commands which I am sending through serial port.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            @Prath You should check what write() returns and connect a slot to https://doc.qt.io/qt-5/qserialport.html#errorOccurred to see whether you get any errors.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            P 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Prath You should check what write() returns and connect a slot to https://doc.qt.io/qt-5/qserialport.html#errorOccurred to see whether you get any errors.

                              P Offline
                              P Offline
                              Prath
                              wrote on last edited by
                              #15

                              @jsulm Could you please help me with the syntax for checking the error. I am completely new in using this.

                              jsulmJ 1 Reply Last reply
                              0
                              • P Prath

                                @jsulm Could you please help me with the syntax for checking the error. I am completely new in using this.

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                @Prath You know how to connect a slot to a signal?
                                https://doc.qt.io/qt-5/signalsandslots.html

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                2
                                • P Offline
                                  P Offline
                                  Prath
                                  wrote on last edited by Prath
                                  #17

                                  Yeah @jsulm . We have to connect this signal [signal]void QSerialPort::errorOccurred(QSerialPort::SerialPortError error) to the slot right?

                                  Is this correct?
                                  void MainWindow::errorReport(QSerialPort::SerialPortError error)
                                  {
                                  if(error!=0)
                                  qDebug()<<"ERROR:"<<endl<<error; // nothing printed
                                  }

                                  connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • P Prath

                                    Yeah @jsulm . We have to connect this signal [signal]void QSerialPort::errorOccurred(QSerialPort::SerialPortError error) to the slot right?

                                    Is this correct?
                                    void MainWindow::errorReport(QSerialPort::SerialPortError error)
                                    {
                                    if(error!=0)
                                    qDebug()<<"ERROR:"<<endl<<error; // nothing printed
                                    }

                                    connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    @Prath said in Regarding Projector Programming using QT:

                                    Is this correct?

                                    Signal is https://doc.qt.io/qt-5/qserialport.html#errorOccurred not error. Just check the documentation.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    3
                                    • P Offline
                                      P Offline
                                      Prath
                                      wrote on last edited by
                                      #19

                                      I think it is correct @jsulm. We are catching the signal using the slot and then displaying the signal.

                                      JonBJ 1 Reply Last reply
                                      0
                                      • P Prath

                                        I think it is correct @jsulm. We are catching the signal using the slot and then displaying the signal.

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #20

                                        @Prath
                                        You wrote

                                        connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));
                                        

                                        Where you have SIGNAL(error(QSerialPort::SerialPortError)) @jsulm is expecting SIGNAL(errorOccurred(QSerialPort::SerialPortError)). If what you have works, we do not understand how.

                                        If you are writing new code and would change over to the new signal/slot syntax you would presumably receive a compile-time error.

                                        1 Reply Last reply
                                        2
                                        • P Offline
                                          P Offline
                                          Prath
                                          wrote on last edited by
                                          #21

                                          Sorry for the delay guys. I tried again with the code and couldn't retrieve anything from the serial port regarding the errror.
                                          I got the attached error:-
                                          IMG_20191124_125954.jpg

                                          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