Skip to main content
Visitor II
September 22, 2019
Solved

proper way to read /dev/ttyrpmsg0

  • September 22, 2019
  • 1 reply
  • 742 views

Hi,

I am executing echo_tty_echo example and trying to get the messages coming from m4 inside qt program as follows:

   QString line;

   QStringList list1;

   char buff[100];

   while (1) {

       QProcess::execute("echo hello > /dev/ttyRPMSG0");

       QFile armIpcReadMsg("/dev/ttyRPMSG0");

       if(armIpcReadMsg.exists())

       {

           if(armIpcReadMsg.open(QIODevice::ReadOnly | QIODevice::Unbuffered)

           {

               armIpcReadMsg.read(buff,100);

               line = QString::fromLatin1(buff);

               list1 = line.split(",");

               ui->label->setText(list1.at(0));

               ui->label_2->setText(list1.at(1));

               ui->label_3->setText(list1.at(2));

               armIpcReadMsg.close();

           }

       }

       memset(&buff[0], 0, sizeof(buff));

       delay(500);

   }

As you see, the command "echo hello > /dev/ttyRPMSG0" is inside my while loop. When I run this code, the command is executed just once and nothing can be read from the port.

As I modified the code so that our command is run as a seperate thread, it continues to run infinitely in the loop but out port can read nothing again.

As a third scenario, I execute my command not inside my qt program but from linux bash, Our port can read something but usually what it reads in the variable 'buff' is spoiled and erroneous.

Any ideas to read /dev/ttyrpmsg0 properly ? Should I add a delay while sending the command or while reading the port ? How long delay ?

tnx

    This topic has been closed for replies.
    Best answer by IYetk

    I solved the problem with "QtSerialPort".

    1 reply

    IYetkAuthorAnswer
    Visitor II
    September 23, 2019

    I solved the problem with "QtSerialPort".