Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to read synchronously (blocking) from serial port without using threads?
Forum Updated to NodeBB v4.3 + New Features

How to read synchronously (blocking) from serial port without using threads?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 681 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.
  • I Offline
    I Offline
    iomkar
    wrote on last edited by
    #1

    Hello,
    I am developing the project in which I am accessing two serial ports , of which one is communicating with modbus slave device and other is communicating with serial device over UART TTL . In my project, on click of push button , first command should be sent from software to serial device and it should wait for the response .Later the modbus command will be sent and software should wait for the response. I need the response data from both the device to calculate and display some data. I have tried using waitforreadyread() and using readyread signal to connect the function for reading the data but to no use. I am unable to store the data in qbytearray.I have seen that in blocking master example , thread is used. Is there any way to block the master until it receives the entire data? Unresponsiveness of GUI is fine with me till the data is received.

    aha_1980A 1 Reply Last reply
    0
    • I iomkar

      Hello,
      I am developing the project in which I am accessing two serial ports , of which one is communicating with modbus slave device and other is communicating with serial device over UART TTL . In my project, on click of push button , first command should be sent from software to serial device and it should wait for the response .Later the modbus command will be sent and software should wait for the response. I need the response data from both the device to calculate and display some data. I have tried using waitforreadyread() and using readyread signal to connect the function for reading the data but to no use. I am unable to store the data in qbytearray.I have seen that in blocking master example , thread is used. Is there any way to block the master until it receives the entire data? Unresponsiveness of GUI is fine with me till the data is received.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @iomkar from your description, you dont need threads nor blocking. just connect a slot to the readyRead signal and process the answer there. then send out the next command the same way.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • I Offline
        I Offline
        iomkar
        wrote on last edited by
        #3

        @aha_1980 hello, Thank you for your response.I had tried that but issue is that I want to block the code till the entire data is received,because I have other commands to execute only after the data is received. Using just readyRead signal and slot to read the data does not stop the code and later commands are being executed. I have used waitforreadyRead to stop the execution till the data is received. While I was trying different things after posting query here, when I put some delay before sending response in my slave serial device which is nothing but microcontroller, I receive the data correctly but when the delay is removed, I don't get any data on my qtserialport.
        Is there something like after transmitting data from qtserialport, rx buffer of qtserialport is disabled for some duration before it starts accepting data?
        Please let me know if any of above is not clearly described to you

        aha_1980A 1 Reply Last reply
        0
        • I iomkar

          @aha_1980 hello, Thank you for your response.I had tried that but issue is that I want to block the code till the entire data is received,because I have other commands to execute only after the data is received. Using just readyRead signal and slot to read the data does not stop the code and later commands are being executed. I have used waitforreadyRead to stop the execution till the data is received. While I was trying different things after posting query here, when I put some delay before sending response in my slave serial device which is nothing but microcontroller, I receive the data correctly but when the delay is removed, I don't get any data on my qtserialport.
          Is there something like after transmitting data from qtserialport, rx buffer of qtserialport is disabled for some duration before it starts accepting data?
          Please let me know if any of above is not clearly described to you

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @iomkar once again, don't block the main thread! you already noticed that does not work. (and even if it works, it may break anytime)

          simplest solution for your case would be to send the next command from the slot when the first one has finished.

          Qt has to stay free or it will die.

          1 Reply Last reply
          2

          • Login

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