rika
rikaFeb. 10, 2019, 10:45 p.m.

Help sending files via COM port

I have 2 separate computers connected by COM port, I want to write an application in QT to send 1 txt file from machine 1 to machine 2. Do you have any specific examples about it? I really need them. Thank you.

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

7
Evgenii Legotckoi
  • Feb. 11, 2019, 4:27 a.m.

Hello,

I think, the same example in this article . This article was wrote by another user. But, in my opinion, it is nearest example with serial port for your question on this site.

    rika
    • Feb. 25, 2019, 3:02 a.m.
    • (edited)

    Thank you for your help. I did it. But I have some problems, this is my code:
    I only sent 1 txt file, but when I received it, I received 3 txt files, the first file was divided into 3 files.

    void MayInternet::serialReceived()
    {
    //Tao file nhan
    QDateTime local= QDateTime::currentDateTime();
    bool checkfile=true;
    if (checkfile)
    {
        QString filename="TinNhan"+local.date().toString("dd.MM.yyyy")+local.time().toString("hh.mm.ss")+".txt";
        if (Name!=filename)
        {
            Name=filename;
            checkfile=false;
        }
    }
    QFile file(Name);
    if (!file.open(QFile::Append | QFile::Text))
    {
        QMessageBox::warning(this, "Canh bao", "Khong tao duoc file / File khong ton tai. " + file.errorString());
        return ;
    }
    //Kiem tra du lieu tu cong va ghi vao file
    if(serialPort->bytesAvailable())
    {
        QByteArray datas = serialPort->readAll();
        if(datas.size()>0)
        {
            if(file.isOpen())
            {
                 QTextStream in(&file);
                 in<<datas;                 
            }
            file.close();
        }
        else {
            QMessageBox::warning(this, "Cảnh báo", "Không có dữ liệu. " + file.errorString());
            return;
        }
        if(serialPort->atEnd())
        {
            checkfile=true;
        }
    }
    
      Evgenii Legotckoi
      • Feb. 25, 2019, 4:17 a.m.

      Hello,

      I think. It is technology limitation. You can't send big file in one message. Just concatenate this several messages to one file.

        rika
        • March 1, 2019, 3 a.m.

        I have another question: I use 9-pin COM port, I want PC1 just send only, PC2 only receive. Therefore I connect Tx of COM1 (PC1) to Rx of COM2 (PC2). In my file.txt there is MD5 to check PC2, if the received PC2 file is match with the original file. if the file is not match, how to PC1 be aware and send it again (without the connect Tx of PC2 to Rx of PC1

          Evgenii Legotckoi
          • March 1, 2019, 5:47 a.m.

          Sorry, I don't know this moment.

            rika
            • March 4, 2019, 5:38 a.m.
            • (edited)

            I have another question:I want to read data from the COM port and write to the txt file, after I finish writing, I will open the file and display the screen. The problem I have is, I have not received all the data, they have been displayed on the screen, and the data is not fully received. This is my code:

            doc () is the function that displays the screen

                QByteArray datas = serialPort->readAll();
                if(datas.size()>0)
                {
                    if(file.isOpen())
                    {
                         QTextStream in(&file);
                         in<<datas;
                    }
                    file.close();
            
                }
                else {
                    QMessageBox::warning(this, "Cảnh báo", "Không có dữ liệu. " + file.errorString());
                    return;
                }
            if(serialPort->atEnd())
            {
                doc();
            }
            
              Evgenii Legotckoi
              • March 5, 2019, 3:33 a.m.

              Do you have all information in txt file if you open this file in standard windows notepad?

              Under Windows OS method readAll() works badly.

              Try this variant

              QFile inputFile(fileName);
              if (inputFile.open(QIODevice::ReadOnly))
              {
                 QTextStream in(&inputFile);
                 while (!in.atEnd())
                 {
                    QString line = in.readLine();
                    ...
                 }
                 inputFile.close();
              }
              

                Comments

                Only authorized users can post comments.
                Please, Log in or Sign up
                AD

                C ++ - Test 004. Pointers, Arrays and Loops

                • Result:50points,
                • Rating points-4
                m

                C ++ - Test 004. Pointers, Arrays and Loops

                • Result:80points,
                • Rating points4
                m

                C ++ - Test 004. Pointers, Arrays and Loops

                • Result:20points,
                • Rating points-10
                Last comments
                i
                innorwallNov. 15, 2024, 5:30 p.m.
                Qt/C++ - Lesson 065. The correspondence of HTTP errors to server response errors in QNetworkAccessManager s Midsummer Classic in Kansas City priligy online pharmacy
                i
                innorwallNov. 15, 2024, 4:44 p.m.
                Qt/C++ - Lesson 039. How to paint stroke in QSqlTableModel by value in the column? Many OPKs would advise users to start using the test strips around day 9 of your cycle, considering day 1 to be the first day of full menstrual flow buy priligy australia
                i
                innorwallNov. 15, 2024, 1:27 p.m.
                Release of C++/Qt and QML application deployment utility CQtDeployer v1.4.0 (Binary Box) optionally substituted alkoxy, optionally substituted alkenyloxy, optionally substituted alkynyloxy, optionally substituted aryloxy, OCH, OC H, OC H, OC H, OC H, OC H, OC H, O C CH, OCH CH OH, O…
                i
                innorwallNov. 15, 2024, 8:26 a.m.
                Qt/C++ - Lesson 031. QCustomPlot – The build of charts with time buy generic priligy We can just chat, and we will not lose too much time anyway
                i
                innorwallNov. 15, 2024, 6:03 a.m.
                Qt/C++ - Lesson 060. Configuring the appearance of the application in runtime I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
                Now discuss on the forum
                t
                tonypeachey1Nov. 15, 2024, 5:04 p.m.
                google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
                i
                innorwallNov. 15, 2024, 4:50 p.m.
                добавить qlineseries в функции priligy for sale Gently flush using an ear syringe
                i
                innorwallNov. 11, 2024, 9:55 p.m.
                Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
                9
                9AnonimOct. 25, 2024, 7:10 p.m.
                Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

                Follow us in social networks