lundi 27 juillet 2020

Putty and RaspberryPi : How to speed up a QProcess instruction

I wrote a small GUI as basic example that replicates the problem I have. I am using Windows 10 with Qt5. Given the remote access tool Putty. I am able to log in inside a RaspberryPi that is mounted on a robot. In order to check the robot's latitude/longitude I can give on a Git Bash terminal the following command :

$ plink.exe robot1@166.130.166.166-pw xxxxxx -P 1234"sudo cat /dev/serial0"

and the output of the command is as follows:

0.88,6.9,M,-33.7,M,0000,000059 $GPGSA,A,3,24,04,06,22,28,17,03,12,19,02,,,1.36,0.88,1.0401 $GPRMC,154725.000,A,4224.2007,N,07044.9218,W,5.54,76.03,270720,,,D4F $GPVTG,76.03,T,,M,5.54,N,10.26,K,D3B $GPGGA,154726.000,4224.2010,N,07044.9198,W,2,10,0.88,6.9,M,-33.7,M,0000,000057 $GPGSA,A,3,24,04,06,22,28,17,03,12,19,02,,,1.36,0.88,1.0401 $GPRMC,154726.000,A,4224.2010,N,07044.9198,W,5.56,76.41,270720,,,D45 $GPVTG,76.41,T,,M,5.56,N,10.30,K,D38

Now in order to avoid to manually type that command I automated the process and created a small .ui carrying 1 QPushButton, 1 QLineEdit and 1 QTextEdit, and use QProcess to execute any command line instruction.

The problem I have is that as I push the button I see the output but only after an extremely long time (i.e. > 3 minutes or more sometimes) which is not great because it is taking too much to show the output on the QTextEdit. How can I solve that?

proc

Below the code of the GUI:

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

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


void MainWindow::check_GPSStatus()
{
    // Execution of the QProcess
    this->executeGPSCommand = new QProcess(this);
    this->executeGPSCommand ->setProcessChannelMode(QProcess::MergedChannels);
    connect(this->executeGPSCommand , QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
            [this, script = this->executeGPSCommand ](int exitCode, QProcess::ExitStatus exitStatus){
        qDebug() << "[EXEC] FINISHED: " << exitCode << exitStatus;
        if(exitCode == 0)
        {
            QString stdOutput = QString::fromUtf8(this->executeGPSCommand ->readAllStandardOutput());
            qDebug() << stdOutput;
            ui->textEdit_EC_GPS->setText(stdOutput);
            ui->lineEdit_EC_GPS->setText("SUCCESS: ACQUIRING GPS COORDINATES");
        }
        else
        {
            QString stdErr = QString::fromUtf8(this->executeGPSCommand ->readAllStandardError());
            qDebug() << stdErr;
            QString stdOutput = QString::fromUtf8(this->executeGPSCommand ->readAllStandardOutput());
            qDebug() << stdOutput;
            ui->textEdit_EC_GPS->setText(stdErr + "\n" + stdOutput);
            ui->lineEdit_EC_GPS->setText("CONNECTION ERROR");
        }
        ui->pushBtn_EC_GPS->setEnabled(true);
    });
}


void MainWindow::execute_GPS_CommandIn_Pi(QString command)
{
    // will start new process without blocking
    QString args = "robot1@166.130.166.166-pw xxxxxx -P 1234";
    QStringList args_list = args.split(' ', QString::SkipEmptyParts);
    this->executeGPSCommand ->start("plink.exe", args_list << command);
}


void MainWindow::on_pushBtn_EC_GPS_clicked()
{
    qDebug() << "Launching GPS Troubleshooting";
    execute_GPS_CommandIn_Pi("sudo cat /dev/serial0");
    ui->pushBtn_EC_GPS->setEnabled(false);
}

I am not very much familiar with Putty, but I was able to write the automation procedure using QProcess, which is a good and quick way to test the correctness of my thoughts. After trying several combinations of commands I arrived to the one I posted in the code that successfully inquire the Raspberry Pi about the position asked. I did a good amount of research but didn't see Putty used on a lot of application similar to the one I am writing. Please if anyone has ever had a similar problem, point to the right direction for solving it.

Aucun commentaire:

Enregistrer un commentaire