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. Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.
Forum Updated to NodeBB v4.3 + New Features

Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.

Scheduled Pinned Locked Moved Unsolved General and Desktop
42 Posts 4 Posters 8.0k Views 1 Watching
  • 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.
  • jsulmJ jsulm

    @Rika I suggest you implement the receiving part in a proper way: without mixing asynchronous and synchronous ways to read data. Remove the loop from serial::on_readdata(). Put QByteArray ba as member variable in the class. Accumulate data in ba untill you got all data.

    R Offline
    R Offline
    Rika
    wrote on last edited by Rika
    #12

    @jsulm You mean this?

    void serial::on_readdata()
    {
        QByteArray ba(serialPort->readAll());
        qDebug()<<ba.size()<<"sizeeeee:";
        QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                if(newDoc.open(QIODevice::WriteOnly)){
                    newDoc.write(ba);
                }
                newDoc.close();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • R Rika

      @jsulm You mean this?

      void serial::on_readdata()
      {
          QByteArray ba(serialPort->readAll());
          qDebug()<<ba.size()<<"sizeeeee:";
          QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                  if(newDoc.open(QIODevice::WriteOnly)){
                      newDoc.write(ba);
                  }
                  newDoc.close();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #13

      @Rika No, not like this. Please read my post above "Put QByteArray ba as member variable in the class. Accumulate data in ba untill you got all data."

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

      R 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Rika No, not like this. Please read my post above "Put QByteArray ba as member variable in the class. Accumulate data in ba untill you got all data."

        R Offline
        R Offline
        Rika
        wrote on last edited by
        #14

        @jsulm Sorry, I don't really understand what you mean. Can you give an example with code?

        jsulmJ 1 Reply Last reply
        0
        • R Rika

          @jsulm Sorry, I don't really understand what you mean. Can you give an example with code?

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

          @Rika

          void serial::on_readdata()
          {
              ba.apend(serialPort->readAll());
              qDebug()<<ba.size()<<"sizeeeee:";
              if (ba.size() == imageSize) {
                  QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                  if(newDoc.open(QIODevice::WriteOnly)){
                      newDoc.write(ba);
                  }
                  newDoc.close();
              }
          }
          

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

          R 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Rika

            void serial::on_readdata()
            {
                ba.apend(serialPort->readAll());
                qDebug()<<ba.size()<<"sizeeeee:";
                if (ba.size() == imageSize) {
                    QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                    if(newDoc.open(QIODevice::WriteOnly)){
                        newDoc.write(ba);
                    }
                    newDoc.close();
                }
            }
            
            R Offline
            R Offline
            Rika
            wrote on last edited by
            #16

            @jsulm I tried it and it failed, I sent 31021 bytes and always received 241 bytes.

            mrjjM 1 Reply Last reply
            0
            • R Rika

              @jsulm I tried it and it failed, I sent 31021 bytes and always received 241 bytes.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #17

              @Rika
              So it only shows
              qDebug()<<ba.size()<<"sizeeeee:";
              1 time with size 241 ?

              R 1 Reply Last reply
              0
              • mrjjM mrjj

                @Rika
                So it only shows
                qDebug()<<ba.size()<<"sizeeeee:";
                1 time with size 241 ?

                R Offline
                R Offline
                Rika
                wrote on last edited by Rika
                #18

                @mrjj No, the last time was 241. My old way it also received only 241 bytes, so I was thinking of the possibility of an error sent by the program.

                mrjjM 1 Reply Last reply
                0
                • R Rika

                  @mrjj No, the last time was 241. My old way it also received only 241 bytes, so I was thinking of the possibility of an error sent by the program.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #19

                  @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

                  No, the last time was 241.

                  So you do get mutiple
                  qDebug()<<ba.size()<<"sizeeeee:";
                  messages ?

                  R 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

                    No, the last time was 241.

                    So you do get mutiple
                    qDebug()<<ba.size()<<"sizeeeee:";
                    messages ?

                    R Offline
                    R Offline
                    Rika
                    wrote on last edited by
                    #20

                    @mrjj
                    144 sizeeeee:
                    160 sizeeeee:
                    176 sizeeeee:
                    192 sizeeeee:
                    208 sizeeeee:
                    224 sizeeeee:
                    240 sizeeeee:
                    241 sizeeeee:

                    jsulmJ mrjjM 2 Replies Last reply
                    0
                    • R Rika

                      @mrjj
                      144 sizeeeee:
                      160 sizeeeee:
                      176 sizeeeee:
                      192 sizeeeee:
                      208 sizeeeee:
                      224 sizeeeee:
                      240 sizeeeee:
                      241 sizeeeee:

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

                      @Rika As I already said: you have to accumulate all these data in ba and when you got everything then you store it in the file.
                      Again the code:

                      void serial::on_readdata()
                      {
                          ba.apend(serialPort->readAll());
                          qDebug()<<ba.size()<<"sizeeeee:";
                          if (ba.size() == imageSize) {
                              QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                              if(newDoc.open(QIODevice::WriteOnly)){
                                  newDoc.write(ba);
                              }
                              newDoc.close();
                          }
                      }
                      

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

                      R 1 Reply Last reply
                      0
                      • R Rika

                        @mrjj
                        144 sizeeeee:
                        160 sizeeeee:
                        176 sizeeeee:
                        192 sizeeeee:
                        208 sizeeeee:
                        224 sizeeeee:
                        240 sizeeeee:
                        241 sizeeeee:

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #22

                        @Rika
                        But it stops at 241 every time?

                        Maybe its due to data.
                        Could you try in your sent function

                        void serial::on_pushButton_2_clicked()
                        {
                        
                        
                                QByteArray ba;
                                ba.fill('A', 1000);
                                if(serialPort->isOpen()==true){
                                    serialPort->write(ba);
                                    qDebug()<<ba.size()<<"size_send:";
                                }
                        }
                        

                        and see if that changes how you the reading goes.
                        This just sends 1000 A.

                        Also i wonder if write will copy the data and then send / if write sent it all there as else we have the issue of the sent buffer running out of scope.

                        R 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Rika As I already said: you have to accumulate all these data in ba and when you got everything then you store it in the file.
                          Again the code:

                          void serial::on_readdata()
                          {
                              ba.apend(serialPort->readAll());
                              qDebug()<<ba.size()<<"sizeeeee:";
                              if (ba.size() == imageSize) {
                                  QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                                  if(newDoc.open(QIODevice::WriteOnly)){
                                      newDoc.write(ba);
                                  }
                                  newDoc.close();
                              }
                          }
                          
                          R Offline
                          R Offline
                          Rika
                          wrote on last edited by
                          #23

                          @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

                          J.HilkJ 1 Reply Last reply
                          0
                          • R Rika

                            @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

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

                            @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

                            @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

                            at this point, you're not getting away with a simple I've tried that, it does not work.

                            @jsulm is absolutely correct. Show us your actual code


                            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.

                            mrjjM R 2 Replies Last reply
                            1
                            • mrjjM mrjj

                              @Rika
                              But it stops at 241 every time?

                              Maybe its due to data.
                              Could you try in your sent function

                              void serial::on_pushButton_2_clicked()
                              {
                              
                              
                                      QByteArray ba;
                                      ba.fill('A', 1000);
                                      if(serialPort->isOpen()==true){
                                          serialPort->write(ba);
                                          qDebug()<<ba.size()<<"size_send:";
                                      }
                              }
                              

                              and see if that changes how you the reading goes.
                              This just sends 1000 A.

                              Also i wonder if write will copy the data and then send / if write sent it all there as else we have the issue of the sent buffer running out of scope.

                              R Offline
                              R Offline
                              Rika
                              wrote on last edited by
                              #25

                              @mrjj I tried with 1000 A, received only 190

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

                                @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

                                @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

                                at this point, you're not getting away with a simple I've tried that, it does not work.

                                @jsulm is absolutely correct. Show us your actual code

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #26

                                @J-Hilk
                                Do you know if write blocks ?
                                QByteArray ba; // local
                                ba.fill('A', 1000);
                                if(serialPort->isOpen()==true){
                                serialPort->write(ba); // blocks here ? as ba is by reference

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

                                  @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

                                  @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

                                  at this point, you're not getting away with a simple I've tried that, it does not work.

                                  @jsulm is absolutely correct. Show us your actual code

                                  R Offline
                                  R Offline
                                  Rika
                                  wrote on last edited by
                                  #27

                                  @J-Hilk

                                  Send:

                                  #include "ui_serial.h"
                                  #include <QDebug>
                                  #include <QBuffer>
                                  #include <QPixmap>
                                  #include <QFile>
                                  
                                  
                                  serial::serial(QWidget *parent) :
                                      QMainWindow(parent),
                                      ui(new Ui::serial)
                                  {
                                      ui->setupUi(this);
                                  
                                      serialPort = new QSerialPort(this);
                                      serialPort->setPortName("ttyAMA0");
                                      serialPort->setBaudRate(QSerialPort::Baud115200);
                                      serialPort->setDataBits(QSerialPort::Data8);
                                      serialPort->setStopBits(QSerialPort::OneStop);
                                      serialPort->setFlowControl(QSerialPort::NoFlowControl);
                                      serialPort->open(QIODevice::ReadWrite);
                                  
                                      if (serialPort->isOpen() == true){
                                          qDebug() <<"Port Opened....";
                                          connect(serialPort, SIGNAL(readyRead()), this, SLOT(on_readdata()));
                                      }
                                  }
                                  void serial::on_pushButton_2_clicked()
                                  {
                                      QFile* imageFile = new QFile("/home/pi/Desktop/image.jpg");
                                          imageFile->open(QIODevice::ReadOnly);
                                          QByteArray ba = imageFile->readAll();
                                          imageFile->close();
                                          delete imageFile;
                                          if(serialPort->isOpen()==true){
                                              serialPort->write(ba);
                                              qDebug()<<ba.size()<<"size_send:";
                                          }
                                  }
                                  

                                  Rec:

                                  #include "serial.h"
                                  #include "ui_serial.h"
                                  #include <QtSerialPort/QSerialPort>
                                  #include <QDebug>
                                  #include <QBuffer>
                                  #include <QPixmap>
                                  #include <QFile>
                                  #include <QMessageBox>
                                  
                                  serial::serial(QWidget *parent) :
                                     QMainWindow(parent),
                                     ui(new Ui::serial)
                                  {
                                     ui->setupUi(this);
                                  
                                     serialPort = new QSerialPort(this);
                                     serialPort->setPortName("ttyAMA0");
                                     serialPort->setBaudRate(QSerialPort::Baud115200);
                                     serialPort->setDataBits(QSerialPort::Data8);
                                     serialPort->setStopBits(QSerialPort::OneStop);
                                     serialPort->setFlowControl(QSerialPort::NoFlowControl);
                                     serialPort->open(QIODevice::ReadWrite);
                                  
                                     if (serialPort->isOpen() == true){
                                         qDebug() <<"Port Opened....";
                                         connect(serialPort, SIGNAL(readyRead()), this, SLOT(on_readdata()));
                                     }
                                  
                                  }
                                  
                                  serial::~serial()
                                  {
                                     delete ui;
                                     serialPort->close();
                                  }
                                  
                                  
                                  void serial::on_readdata()
                                  {
                                     ba.append( serialPort->readAll());
                                     qDebug()<<ba.size()<<"sizeeeee:";
                                     if (ba.size() == 31021) {
                                         QFile newDoc("/home/pi/Desktop/imagexx.jpg");
                                             if(newDoc.open(QIODevice::WriteOnly)){
                                                 newDoc.write(ba);
                                             }
                                             newDoc.close();
                                     }
                                  //    ui->label->setText(ba);
                                  
                                  //      QPixmap b;
                                  //      if(b.loadFromData(ba,"JPG")){
                                  //          ui->label->setPixmap(b);
                                  //      }
                                  
                                  }
                                  
                                  
                                  1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @J-Hilk
                                    Do you know if write blocks ?
                                    QByteArray ba; // local
                                    ba.fill('A', 1000);
                                    if(serialPort->isOpen()==true){
                                    serialPort->write(ba); // blocks here ? as ba is by reference

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

                                    @mrjj IIRC, it's passed on to the OS during the write call and that copies the data. But I'm not entirely sure 😬


                                    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.

                                    mrjjM 1 Reply Last reply
                                    0
                                    • J.HilkJ J.Hilk

                                      @mrjj IIRC, it's passed on to the OS during the write call and that copies the data. But I'm not entirely sure 😬

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #29

                                      @J-Hilk
                                      Yeah i was wondering since its a board if that still happens as it would
                                      make sense we get cut if not.

                                      @Rika
                                      Can you try this

                                      void serial::on_pushButton_2_clicked()
                                      {
                                              static QByteArray ba;
                                              ba.fill('A', 1000);
                                              if(serialPort->isOpen()==true){
                                                  serialPort->write(ba);
                                                  qDebug()<<ba.size()<<"size_send:";
                                              }
                                      }
                                      

                                      and tell me if we still only get up to 190 bytes with the sizeeeee message.

                                      R 1 Reply Last reply
                                      1
                                      • mrjjM mrjj

                                        @J-Hilk
                                        Yeah i was wondering since its a board if that still happens as it would
                                        make sense we get cut if not.

                                        @Rika
                                        Can you try this

                                        void serial::on_pushButton_2_clicked()
                                        {
                                                static QByteArray ba;
                                                ba.fill('A', 1000);
                                                if(serialPort->isOpen()==true){
                                                    serialPort->write(ba);
                                                    qDebug()<<ba.size()<<"size_send:";
                                                }
                                        }
                                        

                                        and tell me if we still only get up to 190 bytes with the sizeeeee message.

                                        R Offline
                                        R Offline
                                        Rika
                                        wrote on last edited by
                                        #30

                                        @mrjj I tried, still only get 190.
                                        16 sizeeeee:
                                        32 sizeeeee:
                                        64 sizeeeee:
                                        64 sizeeeee:
                                        14 sizeeeee:

                                        mrjjM 1 Reply Last reply
                                        0
                                        • R Rika

                                          @mrjj I tried, still only get 190.
                                          16 sizeeeee:
                                          32 sizeeeee:
                                          64 sizeeeee:
                                          64 sizeeeee:
                                          14 sizeeeee:

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #31

                                          @Rika
                                          Good testing.
                                          So even it says
                                          qDebug()<<ba.size()<<"size_send:";
                                          1000 size_send
                                          you only get
                                          5 lines of
                                          16 sizeeeee:
                                          32 sizeeeee:
                                          64 sizeeeee:
                                          64 sizeeeee:
                                          14 sizeeeee:
                                          ?

                                          R 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