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. Create a function using QSerialPort
Forum Updated to NodeBB v4.3 + New Features

Create a function using QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 650 Views 2 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.
  • E Offline
    E Offline
    Elocau
    wrote on last edited by
    #1

    Hello everyone,

    I need your help with creating a function using the QSerialPort class.

    The overall functioning of the function is there but I have trouble turning all that into code.

    The purpose of this function will be:

    -to send an address (type "\ FE \ 01 \ XX \ XX \ XX") via serial link every second until the reception buffer is full

    -If the buffer is full and reading it, we get the same address as the one sent then we empty the buffer

    -when the buffer is empty the loop still executes but this time the address will be ("\ FE \ 02 \ XX \ XX \ XX") and the loop starts again

    When reading the documentation Qt I came across "bool QSerialPort :: canReadLine ()" which returns true or false if the buffer is filled, so I can use this to trigger my function.

    The problem is that I have a lot of trouble implementing the code from the ideas I have on paper, I do not know if my choices are the right ones. If anyone can help me draw the structure that my function will take

    Thank you

    K Matthew11M Gojir4G 3 Replies Last reply
    0
    • E Elocau

      Hello everyone,

      I need your help with creating a function using the QSerialPort class.

      The overall functioning of the function is there but I have trouble turning all that into code.

      The purpose of this function will be:

      -to send an address (type "\ FE \ 01 \ XX \ XX \ XX") via serial link every second until the reception buffer is full

      -If the buffer is full and reading it, we get the same address as the one sent then we empty the buffer

      -when the buffer is empty the loop still executes but this time the address will be ("\ FE \ 02 \ XX \ XX \ XX") and the loop starts again

      When reading the documentation Qt I came across "bool QSerialPort :: canReadLine ()" which returns true or false if the buffer is filled, so I can use this to trigger my function.

      The problem is that I have a lot of trouble implementing the code from the ideas I have on paper, I do not know if my choices are the right ones. If anyone can help me draw the structure that my function will take

      Thank you

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Elocau

      Hi and welcome to devnet forum

      There are a couple of examples available for QSerialPort. Those examples may be compiled for initial tests and build typically a good start for own applications.

      Vote the answer(s) that helped you to solve your issue(s)

      E 1 Reply Last reply
      2
      • K koahnig

        @Elocau

        Hi and welcome to devnet forum

        There are a couple of examples available for QSerialPort. Those examples may be compiled for initial tests and build typically a good start for own applications.

        E Offline
        E Offline
        Elocau
        wrote on last edited by
        #3

        @koahnig
        Are you talking about the examples available in Qt Creator or examples available elsewhere? I will see the examples on Qt Creator, I forgot. Thank you

        K 1 Reply Last reply
        0
        • E Elocau

          @koahnig
          Are you talking about the examples available in Qt Creator or examples available elsewhere? I will see the examples on Qt Creator, I forgot. Thank you

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Elocau

          Either in creator or directly the examples you may install with Qt libs. They should be the same.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • E Elocau

            Hello everyone,

            I need your help with creating a function using the QSerialPort class.

            The overall functioning of the function is there but I have trouble turning all that into code.

            The purpose of this function will be:

            -to send an address (type "\ FE \ 01 \ XX \ XX \ XX") via serial link every second until the reception buffer is full

            -If the buffer is full and reading it, we get the same address as the one sent then we empty the buffer

            -when the buffer is empty the loop still executes but this time the address will be ("\ FE \ 02 \ XX \ XX \ XX") and the loop starts again

            When reading the documentation Qt I came across "bool QSerialPort :: canReadLine ()" which returns true or false if the buffer is filled, so I can use this to trigger my function.

            The problem is that I have a lot of trouble implementing the code from the ideas I have on paper, I do not know if my choices are the right ones. If anyone can help me draw the structure that my function will take

            Thank you

            Matthew11M Offline
            Matthew11M Offline
            Matthew11
            wrote on last edited by
            #5

            @Elocau
            If I understand correctly you are trying to talk with device/devices using some kind of ping-pong messaging? The PC (master) sends frame FE 01... waits for the reception from the device (Slave) and the cycle is repeated but with the new frame FE 02...? Am I correct?

            1 Reply Last reply
            0
            • E Elocau

              Hello everyone,

              I need your help with creating a function using the QSerialPort class.

              The overall functioning of the function is there but I have trouble turning all that into code.

              The purpose of this function will be:

              -to send an address (type "\ FE \ 01 \ XX \ XX \ XX") via serial link every second until the reception buffer is full

              -If the buffer is full and reading it, we get the same address as the one sent then we empty the buffer

              -when the buffer is empty the loop still executes but this time the address will be ("\ FE \ 02 \ XX \ XX \ XX") and the loop starts again

              When reading the documentation Qt I came across "bool QSerialPort :: canReadLine ()" which returns true or false if the buffer is filled, so I can use this to trigger my function.

              The problem is that I have a lot of trouble implementing the code from the ideas I have on paper, I do not know if my choices are the right ones. If anyone can help me draw the structure that my function will take

              Thank you

              Gojir4G Offline
              Gojir4G Offline
              Gojir4
              wrote on last edited by Gojir4
              #6

              @Elocau said in Create a function using QSerialPort:

              "\ FE \ 01 \ XX \ XX \ XX"

              Your example suggests that you are sending binary data so in this case using bool QSerialPort :: canReadLine () will probably not work as expected as it will seek for end line ASCII character.

              You need to define if you want to use binary of ASCII protocol and then handle data accordingly

              1 Reply Last reply
              3

              • Login

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