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. QByteArray corrupts my data ???Why???
Qt 6.11 is out! See what's new in the release blog

QByteArray corrupts my data ???Why???

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 7.1k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #7

    @
    if (relays.open(QSerialPort::ReadWrite) {
    // Set port settings here
    QByteArray relay_arr("ch" + QByteArray::number(Ch_on) + "_onx");
    relays.write(relay_arr);
    }
    @

    (Z(:^

    1 Reply Last reply
    0
    • A Offline
      A Offline
      achmed
      wrote on last edited by
      #8

      Thanks Sierdzio.
      I Will give your code a try tomorrow.

      Although I have found a semi sort of solution.

      If I add a 1second delay after opening the ports and also a 1second delay before closing them, then it works.
      This tells me that the <relays.waitForBytesWriten(-1)> does not work.
      As far as I know this function is supposed to pause until all data has been written to the device. Can anybody maybe comment on this statement?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #9
        1. What is version of QtSerialPort?
        2. What is serial port type?
        1 Reply Last reply
        0
        • A Offline
          A Offline
          achmed
          wrote on last edited by
          #10

          Hi kuzulis. Im not sure where to check the version number for QtSerialPort.
          The Serial port is a RS232 device.

          Sierdzio. I implemented your above mentioned code.
          No difference. The only thing I fount to work is if I add a 1sec delay after opening and before closing the port.

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

            2 achmed

            bq.
            Im not sure where to check the version number for QtSerialPort.

            From where you took the QtSerialPort?

            bq. The Serial port is a RS232 device.

            This is USB/Serial converter, on-board device or something else? What chip?

            bq. The code bellow also displays corrupted data.

            What do you see when do writing of relays.write("all_offx") ?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              achmed
              wrote on last edited by
              #12

              Someone else did the installation of Qt on my PC.
              Not sure where they got it from.

              We are using more that one Type/Brand/Chip. They are all giving the same problem.

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

                bq. They are all giving the same problem.

                What is a problem? I repeat a question again: what do you see when do writing of relays.write(“all_offx”) on other side?

                bq. Not sure where they got it from.

                It is in your interests to know it. Without it further reasonings are senseless.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  achmed
                  wrote on last edited by
                  #14

                  [quote author="kuzulis" date="1415359623"]What is a problem? I repeat a question again: what do you see when do writing of relays.write(“all_offx”) on other side?
                  [/quote]

                  As Mentioned in the first post. The output data is corrupted.
                  Example: ^%$%^&*(
                  In Other words unreadable.

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

                    This can not be in principle. Can you check same, but without closing of device?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      achmed
                      wrote on last edited by
                      #16

                      [quote author="achmed" date="1415284517"]If I add a 1second delay after opening the ports and also a 1second delay before closing them, then it works.[/quote]

                      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