PRATH
PRATH

Reputation: 1

Regarding Projector Programming using QT

I am connecting the projector to Quectel QCOM application. Now I want to skip that application and create my customized application to control the projector.

I wrote a program 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.

Please help me in this guys! I am stuck in this since a month.

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

QMake project file:

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

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

Upvotes: 0

Views: 178

Answers (0)

Related Questions