Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Not the copying the data in a file with same file size?

Not the copying the data in a file with same file size?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
16 Posts 3 Posters 1.1k 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.
  • M Offline
    M Offline
    Mohit Tripathi
    wrote on last edited by Mohit Tripathi
    #1

    Hi,

    I am trying to store the data through UART from my processor. You can say that I am making the log file but the data is storing with more size more than expected. The data should be size of 500KB but it is storing more than 2MB size.
    The data is fine in file. There is no extra data in that file and there is also not corrupt data. I am storing the data with baudrate of 19200 in the file.

    QFile logFile("Data.txt");
        if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
            qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
    QTextStream log(&logFile);
        logFile.setObjectName("Log File");
        log << serialBuffer;
        log.flush();
        logFile.close();
    

    here, serialBuffer is buffer to store the data.
    Can I know how this is possible and why this is happening?

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • M Mohit Tripathi

      Hi,

      I am trying to store the data through UART from my processor. You can say that I am making the log file but the data is storing with more size more than expected. The data should be size of 500KB but it is storing more than 2MB size.
      The data is fine in file. There is no extra data in that file and there is also not corrupt data. I am storing the data with baudrate of 19200 in the file.

      QFile logFile("Data.txt");
          if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
              qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
      QTextStream log(&logFile);
          logFile.setObjectName("Log File");
          log << serialBuffer;
          log.flush();
          logFile.close();
      

      here, serialBuffer is buffer to store the data.
      Can I know how this is possible and why this is happening?

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

      @mohit-tripathi said in Not the copying the data in a file with same file size?:

      QIODevice::Append

      You are appending to the file.
      Remove QIODevice::Append ...

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mohit Tripathi
        wrote on last edited by
        #3

        @jsulm

        I am making the log file. The data come one by one through UART. If, we will not append the data will overwrite. It means that the new data will not add at end of the previous data.

        jsulmJ 1 Reply Last reply
        0
        • M Mohit Tripathi

          @jsulm

          I am making the log file. The data come one by one through UART. If, we will not append the data will overwrite. It means that the new data will not add at end of the previous data.

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

          @mohit-tripathi Then I don't understand the problem. If you append to the file then it will grow and will not have fix size. So, why should it be exactly 500KB?

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

          1 Reply Last reply
          0
          • M Mohit Tripathi

            Hi,

            I am trying to store the data through UART from my processor. You can say that I am making the log file but the data is storing with more size more than expected. The data should be size of 500KB but it is storing more than 2MB size.
            The data is fine in file. There is no extra data in that file and there is also not corrupt data. I am storing the data with baudrate of 19200 in the file.

            QFile logFile("Data.txt");
                if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
                    qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
            QTextStream log(&logFile);
                logFile.setObjectName("Log File");
                log << serialBuffer;
                log.flush();
                logFile.close();
            

            here, serialBuffer is buffer to store the data.
            Can I know how this is possible and why this is happening?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @mohit-tripathi you're appending the raw serialData, are you sure, you don't have some kind of protocol on top if it? Telegramsize, checksum etc.

            Have you compared the raw Data that you get? Just because your text browser doesn't display them, doesn't mean there are unwanted bytes in your file.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            jsulmJ 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @mohit-tripathi you're appending the raw serialData, are you sure, you don't have some kind of protocol on top if it? Telegramsize, checksum etc.

              Have you compared the raw Data that you get? Just because your text browser doesn't display them, doesn't mean there are unwanted bytes in your file.

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

              @j-hilk Now I understand what the problem is :-)

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

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Mohit Tripathi
                wrote on last edited by
                #7

                @jsulm

                I am reading the SD card file through UART from SD card. The SD file is 500KB but the data which I am storing in file on my PC using Qt application. The data is same but the size is showing above 2 MB which is impossible.
                That's why I am not getting here. if I am reading the same file and storing in other file. the file size should be same.

                jsulmJ 1 Reply Last reply
                0
                • M Mohit Tripathi

                  @jsulm

                  I am reading the SD card file through UART from SD card. The SD file is 500KB but the data which I am storing in file on my PC using Qt application. The data is same but the size is showing above 2 MB which is impossible.
                  That's why I am not getting here. if I am reading the same file and storing in other file. the file size should be same.

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

                  @mohit-tripathi After the comment from @J-Hilk I understood your problem. Take a look at his post.

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

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mohit Tripathi
                    wrote on last edited by
                    #9

                    @jsulm @J-Hilk
                    Hi,

                    As, I can see that the data is copying there or four times in my file.

                    void SettingsDialog::on_pushButton_clicked()
                    {
                    //    const QStringList list = m_ui->serialPortInfoListBox->itemData(mohit).toStringList();
                    //    qDebug()<<list;
                    //    QList<QString> List;
                    //    List = list.mid(0,1);
                    //    qDebug()<<"COM:"<<List;
                    
                        foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){
                        qDebug() << "Name  :" << info.portName();
                        QString List1 = info.portName();
                        qDebug() <<List1;
                        serial->setPortName(List1);
                    }
                    
                        serial->open(QSerialPort::ReadWrite);
                        serial->setBaudRate(QSerialPort::Baud19200);
                        serial->setDataBits(QSerialPort::Data8);
                        serial->setParity(QSerialPort::NoParity);
                        serial->setStopBits(QSerialPort::OneStop);
                        serial->setFlowControl(QSerialPort::NoFlowControl);
                        connect(serial,&QSerialPort::readyRead,this,&SettingsDialog::serialReceived);
                    
                        static const char mydata[] ={'M','N'};
                        QByteArray sendPacket = QByteArray::fromRawData(mydata, sizeof(mydata));
                       // QByteArray sendPacket("MN");
                    //    serial->write(sendPacket);
                        sendPacket.resize(2);
                        if(serial->isWritable())
                        {
                    
                            serial->write(sendPacket.toStdString().c_str(), sendPacket.size());
                            serial->flush();
                            serial->waitForBytesWritten(100);
                        }
                        else
                        {
                            qDebug()<<"write to serial";
                        }
                    
                    }
                    
                    void SettingsDialog::serialReceived()
                    {
                        QFile logFile("Data.txt");
                        if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
                            qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
                         QTextStream log(&logFile);
                    
                        QStringList buffer_split = serialBuffer.split("++--++--++--++--++--++--++--++--++");
                        if(buffer_split.length() < 3){
                            serialData = serial->readAll();
                            serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                            serialData.clear();
                        }else{
                            serialBuffer = "";
                            qDebug() << buffer_split << "\n";
                            //   Dialog::updatelcd1(buffer_split[0]);
                            QMessageBox::about(this, "Data Copy Status", "SD Card Data Copied.\n\nPlease remove the device");
                            qDebug()<<"No reading";
                        }
                    
                      //  logFile.setObjectName("Log File");
                        log << serialBuffer;
                        log.flush();
                        log.reset();
                    
                    }
                    

                    Can you please check?

                    jsulmJ J.HilkJ 2 Replies Last reply
                    0
                    • M Mohit Tripathi

                      @jsulm @J-Hilk
                      Hi,

                      As, I can see that the data is copying there or four times in my file.

                      void SettingsDialog::on_pushButton_clicked()
                      {
                      //    const QStringList list = m_ui->serialPortInfoListBox->itemData(mohit).toStringList();
                      //    qDebug()<<list;
                      //    QList<QString> List;
                      //    List = list.mid(0,1);
                      //    qDebug()<<"COM:"<<List;
                      
                          foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){
                          qDebug() << "Name  :" << info.portName();
                          QString List1 = info.portName();
                          qDebug() <<List1;
                          serial->setPortName(List1);
                      }
                      
                          serial->open(QSerialPort::ReadWrite);
                          serial->setBaudRate(QSerialPort::Baud19200);
                          serial->setDataBits(QSerialPort::Data8);
                          serial->setParity(QSerialPort::NoParity);
                          serial->setStopBits(QSerialPort::OneStop);
                          serial->setFlowControl(QSerialPort::NoFlowControl);
                          connect(serial,&QSerialPort::readyRead,this,&SettingsDialog::serialReceived);
                      
                          static const char mydata[] ={'M','N'};
                          QByteArray sendPacket = QByteArray::fromRawData(mydata, sizeof(mydata));
                         // QByteArray sendPacket("MN");
                      //    serial->write(sendPacket);
                          sendPacket.resize(2);
                          if(serial->isWritable())
                          {
                      
                              serial->write(sendPacket.toStdString().c_str(), sendPacket.size());
                              serial->flush();
                              serial->waitForBytesWritten(100);
                          }
                          else
                          {
                              qDebug()<<"write to serial";
                          }
                      
                      }
                      
                      void SettingsDialog::serialReceived()
                      {
                          QFile logFile("Data.txt");
                          if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
                              qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
                           QTextStream log(&logFile);
                      
                          QStringList buffer_split = serialBuffer.split("++--++--++--++--++--++--++--++--++");
                          if(buffer_split.length() < 3){
                              serialData = serial->readAll();
                              serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                              serialData.clear();
                          }else{
                              serialBuffer = "";
                              qDebug() << buffer_split << "\n";
                              //   Dialog::updatelcd1(buffer_split[0]);
                              QMessageBox::about(this, "Data Copy Status", "SD Card Data Copied.\n\nPlease remove the device");
                              qDebug()<<"No reading";
                          }
                      
                        //  logFile.setObjectName("Log File");
                          log << serialBuffer;
                          log.flush();
                          log.reset();
                      
                      }
                      

                      Can you please check?

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

                      @mohit-tripathi said in Not the copying the data in a file with same file size?:

                      serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());

                      Why do you append to serialBuffer? After appending you write to the log, that means as long as buffer_split.length() < 3 you write same data into the log...

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

                      1 Reply Last reply
                      0
                      • M Mohit Tripathi

                        @jsulm @J-Hilk
                        Hi,

                        As, I can see that the data is copying there or four times in my file.

                        void SettingsDialog::on_pushButton_clicked()
                        {
                        //    const QStringList list = m_ui->serialPortInfoListBox->itemData(mohit).toStringList();
                        //    qDebug()<<list;
                        //    QList<QString> List;
                        //    List = list.mid(0,1);
                        //    qDebug()<<"COM:"<<List;
                        
                            foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){
                            qDebug() << "Name  :" << info.portName();
                            QString List1 = info.portName();
                            qDebug() <<List1;
                            serial->setPortName(List1);
                        }
                        
                            serial->open(QSerialPort::ReadWrite);
                            serial->setBaudRate(QSerialPort::Baud19200);
                            serial->setDataBits(QSerialPort::Data8);
                            serial->setParity(QSerialPort::NoParity);
                            serial->setStopBits(QSerialPort::OneStop);
                            serial->setFlowControl(QSerialPort::NoFlowControl);
                            connect(serial,&QSerialPort::readyRead,this,&SettingsDialog::serialReceived);
                        
                            static const char mydata[] ={'M','N'};
                            QByteArray sendPacket = QByteArray::fromRawData(mydata, sizeof(mydata));
                           // QByteArray sendPacket("MN");
                        //    serial->write(sendPacket);
                            sendPacket.resize(2);
                            if(serial->isWritable())
                            {
                        
                                serial->write(sendPacket.toStdString().c_str(), sendPacket.size());
                                serial->flush();
                                serial->waitForBytesWritten(100);
                            }
                            else
                            {
                                qDebug()<<"write to serial";
                            }
                        
                        }
                        
                        void SettingsDialog::serialReceived()
                        {
                            QFile logFile("Data.txt");
                            if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
                                qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData());
                             QTextStream log(&logFile);
                        
                            QStringList buffer_split = serialBuffer.split("++--++--++--++--++--++--++--++--++");
                            if(buffer_split.length() < 3){
                                serialData = serial->readAll();
                                serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                                serialData.clear();
                            }else{
                                serialBuffer = "";
                                qDebug() << buffer_split << "\n";
                                //   Dialog::updatelcd1(buffer_split[0]);
                                QMessageBox::about(this, "Data Copy Status", "SD Card Data Copied.\n\nPlease remove the device");
                                qDebug()<<"No reading";
                            }
                        
                          //  logFile.setObjectName("Log File");
                            log << serialBuffer;
                            log.flush();
                            log.reset();
                        
                        }
                        

                        Can you please check?

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #11

                        @mohit-tripathi

                        what's your thought behind this:

                        QStringList buffer_split = serialBuffer.split("++--++--++--++--++--++--++--++--++");
                            if(buffer_split.length() < 3){
                                serialData = serial->readAll();
                                serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                                serialData.clear();
                            }else{
                                serialBuffer = "";
                                qDebug() << buffer_split << "\n";
                                //   Dialog::updatelcd1(buffer_split[0]);
                                QMessageBox::about(this, "Data Copy Status", "SD Card Data Copied.\n\nPlease remove the device");
                                qDebug()<<"No reading";
                            }
                        

                        the else path will never be executed!
                        therefore, your serialBuffer will never be cleared, but you append to it all the time


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        2
                        • M Offline
                          M Offline
                          Mohit Tripathi
                          wrote on last edited by
                          #12

                          Thanks,

                          @jsulm @J-Hilk
                          I got the issue.
                          I have more question. How can I store the data in my file as much as in less time. I need the data transmission through UART faster. The baudrate is only 115200. I am able to receive the data 4mb in 5 minutes. I think that this is very less.
                          Is there any way to make data transmission faster using UART?

                          jsulmJ 1 Reply Last reply
                          0
                          • M Mohit Tripathi

                            Thanks,

                            @jsulm @J-Hilk
                            I got the issue.
                            I have more question. How can I store the data in my file as much as in less time. I need the data transmission through UART faster. The baudrate is only 115200. I am able to receive the data 4mb in 5 minutes. I think that this is very less.
                            Is there any way to make data transmission faster using UART?

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

                            @mohit-tripathi Serial port communication is slow as it really antique. If you can use higher frequency on bot sides (>115200) then you can increase the speed.
                            See "Speed" in https://en.wikipedia.org/wiki/Serial_port.

                            Also you can compress data before sending it and then decompress on receiver side.

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

                            1 Reply Last reply
                            2
                            • M Offline
                              M Offline
                              Mohit Tripathi
                              wrote on last edited by
                              #14

                              @jsulm

                              How can I define in Qt over 115200 baudrate?

                              J.HilkJ 1 Reply Last reply
                              0
                              • M Mohit Tripathi

                                @jsulm

                                How can I define in Qt over 115200 baudrate?

                                J.HilkJ Offline
                                J.HilkJ Offline
                                J.Hilk
                                Moderators
                                wrote on last edited by
                                #15

                                @mohit-tripathi

                                setBaudRate(qint32 baudRate, QSerialPort::Directions directions = AllDirections)

                                any positive qint32 value will do > max = 2 147 483 647


                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                1 Reply Last reply
                                2
                                • M Offline
                                  M Offline
                                  Mohit Tripathi
                                  wrote on last edited by Mohit Tripathi
                                  #16
                                  This post is deleted!
                                  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