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. Completion notification after completion of write the data in file through UART
Forum Updated to NodeBB v4.3 + New Features

Completion notification after completion of write the data in file through UART

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
10 Posts 3 Posters 837 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
    #1

    Hi,

    How to include the completion notification after completion of write the data in file through UART (serially)?
    I want to show the completion notification in my application. I am storing the data in a file through UART(serially).
    But, I don't know that how can I include that tab or notification my application?
    The application, i am making for windows. The platform is Qt creator.

    Thanks

    aha_1980A 1 Reply Last reply
    0
    • M Mohit Tripathi

      Hi,

      How to include the completion notification after completion of write the data in file through UART (serially)?
      I want to show the completion notification in my application. I am storing the data in a file through UART(serially).
      But, I don't know that how can I include that tab or notification my application?
      The application, i am making for windows. The platform is Qt creator.

      Thanks

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mohit-Tripathi Please show the code you got so far.

      Qt has to stay free or it will die.

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

        Hi,

        I am trying to implement this in terminal application. The code, i have attached is:

        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);
        }
        
        //qDebug()<< QPair<QString, QString>( serial->portName(), tr( "%1: %2" ).arg( serial->portName(), serial->description() ) );
        //serial->setPortName(List);
            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()
        {
            /*int data1  =0;
             char *dataBuffer;
             int size = arduino->bytesAvailable();
             dataBuffer = new char[size+1];
             data1 = arduino->read(dataBuffer,size);
             dataBuffer[data1]='\0';
             //delete dataBuffer;*/
        
            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]);
                qDebug()<<"No reading";
            }
        
            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();
        
        
           // QFile logFile("Data.txt");
           // logFile.open(QIODevice::ReadWrite);
            QTextStream in (&logFile);
            const QString content = in.readAll();
            if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
            {
                qDebug()<<"completed\n";
            }
            logFile.close();
        
        }
        
        aha_1980A 1 Reply Last reply
        0
        • M Mohit Tripathi

          Hi,

          I am trying to implement this in terminal application. The code, i have attached is:

          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);
          }
          
          //qDebug()<< QPair<QString, QString>( serial->portName(), tr( "%1: %2" ).arg( serial->portName(), serial->description() ) );
          //serial->setPortName(List);
              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()
          {
              /*int data1  =0;
               char *dataBuffer;
               int size = arduino->bytesAvailable();
               dataBuffer = new char[size+1];
               data1 = arduino->read(dataBuffer,size);
               dataBuffer[data1]='\0';
               //delete dataBuffer;*/
          
              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]);
                  qDebug()<<"No reading";
              }
          
              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();
          
          
             // QFile logFile("Data.txt");
             // logFile.open(QIODevice::ReadWrite);
              QTextStream in (&logFile);
              const QString content = in.readAll();
              if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
              {
                  qDebug()<<"completed\n";
              }
              logFile.close();
          
          }
          
          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mohit-Tripathi said in Completion notification after completion of write the data in file through UART:

          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();
          

          // QFile logFile("Data.txt");
          // logFile.open(QIODevice::ReadWrite);
          QTextStream in (&logFile);
          const QString content = in.readAll();
          if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
          {
          qDebug()<<"completed\n";
          }
          logFile.close();

          Can you explain what this code fragment is supposed to do?

          Qt has to stay free or it will die.

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

            Hi,

            This code fragment is about, to create the file and store the data in "Data.txt" file which we are getting through UART. I can say that this is like log file.

            Thanks

            aha_1980A 1 Reply Last reply
            0
            • M Mohit Tripathi

              Hi,

              This code fragment is about, to create the file and store the data in "Data.txt" file which we are getting through UART. I can say that this is like log file.

              Thanks

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mohit-Tripathi

              Yeah, but what is this part meant to be:

              // QFile logFile("Data.txt");
              // logFile.open(QIODevice::ReadWrite);
              QTextStream in (&logFile);
              const QString content = in.readAll();
              if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
              {
              qDebug()<<"completed\n";
              }
              logFile.close();

              ?

              Qt has to stay free or it will die.

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

                @aha_1980

                Yeah,

                I have created the string in MCU "+++++++++++++++++++++++++++++++++++++++++++". When, I get this string in my file through UART, I get to know that the data has been pushed or not. This is basically like notification. Then, I am printing "completed", if the data has been pushed.
                You can see that I am taking the data from "Data.txt" file only.

                Thanks

                aha_1980A 1 Reply Last reply
                0
                • M Mohit Tripathi

                  @aha_1980

                  Yeah,

                  I have created the string in MCU "+++++++++++++++++++++++++++++++++++++++++++". When, I get this string in my file through UART, I get to know that the data has been pushed or not. This is basically like notification. Then, I am printing "completed", if the data has been pushed.
                  You can see that I am taking the data from "Data.txt" file only.

                  Thanks

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Mohit-Tripathi

                  So you get "++++++++++++++++++++" when the data is completely send? Because the condition implies the opposite (!contains()):

                  if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))

                  But I can only advice you to not read and write the file alternating; that will destroy performance completely.

                  Back to your question: Why not simply emit a signal once the end condition is satisfied?

                  You already have the data in RAM, no need to write it in a file just to read it back afterwards for checking.

                  Qt has to stay free or it will die.

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

                    @aha_1980

                    Actually, I have data in SD card which is attached with MCU. I am taking those data through UART. I think, there is no way to take the data except UART. So basically, I want to store the SD card data after clicking on to the tab in my desktop application.

                    "Why not simply emit a signal once the end condition is satisfied?"
                    How can I do this? Can you please tell me?

                    Thanks

                    jsulmJ 1 Reply Last reply
                    0
                    • M Mohit Tripathi

                      @aha_1980

                      Actually, I have data in SD card which is attached with MCU. I am taking those data through UART. I think, there is no way to take the data except UART. So basically, I want to store the SD card data after clicking on to the tab in my desktop application.

                      "Why not simply emit a signal once the end condition is satisfied?"
                      How can I do this? Can you please tell me?

                      Thanks

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

                      @Mohit-Tripathi said in Completion notification after completion of write the data in file through UART:

                      How can I do this? Can you please tell me?

                      https://doc.qt.io/qt-5/signalsandslots.html

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

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved