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. GPS Sensor data to view on ui

GPS Sensor data to view on ui

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 358 Views
  • 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.
  • S Offline
    S Offline
    Shivam Sharma
    wrote on last edited by
    #1

    Hi guys,

    So I've written the code for getting data from serial port and it's successful. Further when i connect the GPS Sensor and try to extract the string. The append function doesn't display any data on the ui (QTextbox). Can anyone help?
    Here is the code of the read and write data in the file function:

    void MainWindow::serialReceived()
    {
    QByteArray serialData;
    serialData = serial->readAll();
    QString receivedData = QString::fromStdString(serialData.toStdString());

    char t0[512];
    static char t1[512];
    static int wp=0;
    unsigned int i=0;
    
    QString filename="/home/user/Desktop/Programs/Readserial2/gotdata.txt";
    QFile file( filename );
    
    if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
    {
        QTextStream stream( &file );
        strcpy(t0,serialData);
        for (i=0;i<strlen(t0);i++)
        {
            ui->receiver->append(receivedData);
            t1[wp++]=t0[i];
            wp%=512;
            t1[wp]=0;
    
            if(t0[i] == '\n')
            {
                wp=0;
                if(checksum_gps(t1))
                {
                    if(memcmp("$GPRMC",t1,6)==0 || memcmp("$GPRMC",t1,6)==0)
                    {
    
                        strcat(t1,timestamp());
                        stream<<t1;
                        ui->contdata->append(t1);
                    }
                }
            }
        }
        stream << t1 << endl;
        fflush(stdout);
        file.close();
    }
    

    }

    jsulmJ 1 Reply Last reply
    0
    • S Shivam Sharma

      Hi guys,

      So I've written the code for getting data from serial port and it's successful. Further when i connect the GPS Sensor and try to extract the string. The append function doesn't display any data on the ui (QTextbox). Can anyone help?
      Here is the code of the read and write data in the file function:

      void MainWindow::serialReceived()
      {
      QByteArray serialData;
      serialData = serial->readAll();
      QString receivedData = QString::fromStdString(serialData.toStdString());

      char t0[512];
      static char t1[512];
      static int wp=0;
      unsigned int i=0;
      
      QString filename="/home/user/Desktop/Programs/Readserial2/gotdata.txt";
      QFile file( filename );
      
      if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
      {
          QTextStream stream( &file );
          strcpy(t0,serialData);
          for (i=0;i<strlen(t0);i++)
          {
              ui->receiver->append(receivedData);
              t1[wp++]=t0[i];
              wp%=512;
              t1[wp]=0;
      
              if(t0[i] == '\n')
              {
                  wp=0;
                  if(checksum_gps(t1))
                  {
                      if(memcmp("$GPRMC",t1,6)==0 || memcmp("$GPRMC",t1,6)==0)
                      {
      
                          strcat(t1,timestamp());
                          stream<<t1;
                          ui->contdata->append(t1);
                      }
                  }
              }
          }
          stream << t1 << endl;
          fflush(stdout);
          file.close();
      }
      

      }

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

      @Shivam-Sharma What did you check so far?
      Is serialReceived() called?
      Is file.open() successful?
      Why do you call ui->receiver->append(receivedData); inside the for loop?
      What does strlen(t0) return?

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Shivam Sharma
        wrote on last edited by
        #3

        @jsulm
        Yes, serialReceived() is called?
        Yes, file.open() is successful?
        sorry deleted this, it was a commented :ui->receiver->append(receivedData);
        strlen(t0) gives the length, so that the loop runs only for that length.

        jsulmJ 1 Reply Last reply
        0
        • S Shivam Sharma

          @jsulm
          Yes, serialReceived() is called?
          Yes, file.open() is successful?
          sorry deleted this, it was a commented :ui->receiver->append(receivedData);
          strlen(t0) gives the length, so that the loop runs only for that length.

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

          @Shivam-Sharma said in GPS Sensor data to view on ui:

          strlen(t0) gives the length

          I know what it does, but does it return a number > 0 in your case?
          Did you try

          qDebug() << receivedData?
          

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

          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