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. Secure receiving serial data (QSerialPort)
QtWS25 Last Chance

Secure receiving serial data (QSerialPort)

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 608 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.
  • A Offline
    A Offline
    atilalms
    wrote on last edited by
    #1

    Hello, everyone!

    In my application, I need to receive 8 bytes everytime a button (hardware) is pressed. I have already checked the bytes with a terminal software and the transmission is ok.

    I want to receive these bytes with QT, but sometimes the package comes wrong. I need help to build a secure routine to read the data without errors.

    What is the problem with my program?

    Until now I did this:

    @
    void ipd::serialReceived()
    {
    leitura = serial->readAll();
    dado_serial.append(leitura); // Group the data until 8 bytes

        tamanho_serial += leitura.size();             // Size of data
        if (tamanho_serial >=8)                               // If size is bigger than 8,
        {
            qDebug()<< "--"<< cont++ <<"--";
            qDebug()<< dado_serial.toHex();
    
            dado.REG_END    = dado_serial.mid(0,1).toHex();             // Get each byte
            dado.REG_FUNC   = dado_serial.mid(1,1).toHex();
            dado.REGISTRO0  = dado_serial.mid(2,1).toHex();
            dado.REGISTRO1  = dado_serial.mid(3,1).toHex();
            dado.REGISTRO2  = dado_serial.mid(4,1).toHex();
            dado.REGISTRO3  = dado_serial.mid(5,1).toHex();
            dado.REG_CRCH   = dado_serial.mid(6,1).toHex();
            dado.REG_CRCL   = dado_serial.mid(7,1).toHex();
    
             // Clear variables
            dado_serial = 0;                                                                            
            tamanho_serial = 0;
            flag_conta_silencio = 1;
            serial->clear();
    
            
        }
    

    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

      You can take the Terminal example (from the QtSerialPort) and check received data. Of course, in case your data transferred in "string" form.

      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