Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QextSerialPort - ReadWrite mode trouble
QtWS25 Last Chance

QextSerialPort - ReadWrite mode trouble

Scheduled Pinned Locked Moved 3rd Party Software
8 Posts 3 Posters 6.8k 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.
  • Q Offline
    Q Offline
    Qtnovice
    wrote on last edited by
    #1

    Hi,
    I need some help to be able to properly communicate with a device by qextserialport.
    It operates at 9600bps with no flow control.

    In ReadOnly mode I can manage bytes coming from the device since the device sends some bytes to allow me to "sync" and so I can properly read the following bytes...

    Problems arise when the device is not operating as master (when I need so send a command to read the answer that follows ReadWrite mode is required).
    I need to send one or two bytes and then the device should answer by sending one or two bytes.
    It should be simple but I often see data lost.
    By using @while (port->bytesAvailable()<1)
    usleep(5000);@ before port->readRawData call nothing change.
    I also added port->flush() or port->readAll() before port->write(...) but I didn't solve the trouble.

    The code that manages the serial port is on a thread different from the main one. I didn't subclass the QThread class but moved my class that manages the serial device to a different thread. I think it should work...

    Should I use buffered or unbuffered mode? And what about timeout (port settings)?
    What do you suggest?
    Thank you!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      I am using the same serial port for reading/writing in an application. The application uses QextSerialPort and opens it with QIODevice::ReadWrite .

      There is also another class QSerialDevice available. "Here":http://developer.qt.nokia.com/forums/viewthread/11634/#67246 you find some details on it.

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

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qtnovice
        wrote on last edited by
        #3

        Before evaluating to prefer QSerialDevice, I'd like to be sure I'm properly using QextSerialPort.
        I obviously use ReadWrite mode to be able to read&write.

        How would you write two bytes and then read the answer (2 bytes too)?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          The reading and writing is done in different threads. When bytes are reeived a readyRead() signal is issued.

          When I started to use QextSerialPort I have found a derivative showing that approach. I have used this for guiding my implementation.

          At that time I have found source obviously having the same origin, but following different strategies. I did not find the SourceForge version (now in Google) at that time. Unfortunately, I cannot change easily.

          When the pain is large enough and I need a serial device implementation I probably will have a very close look to QSerialDevice.

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

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qtnovice
            wrote on last edited by
            #5

            But are you referring to QextSerialPort::EventDriven mode?
            I think it's not mandatory, is it?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              That is the way I am using it. I have never tested the other mode.

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

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Qtnovice
                wrote on last edited by
                #7

                QextSerialPort::EventDriven mode didn't solve the troubles.
                So I tried to manage the RS232 by QSerialDevice and nothing changed.
                Then I found that by writing one byte at time (by QSerialDevice - I had no time to try by QExtSerialPort) in unbuffered mode (in place of writing a QByteArray in buffered or unbuffered mode) everything worked as expected (without usleep calls between consecutive byte writings too).
                So something is still unclear.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shorawitz
                  wrote on last edited by
                  #8

                  I don't know if you have the ability to add a message delimiter, I had to do that with my own protocol. Then all I did was loop:

                  @
                  readBytes = serialport->read(serialport->bytesAvailable());
                  @

                  and append readBytes to a QString until I reach my message delimiter. At the moment, I'm testing my code with a virtual serial port connecting 2 x VirtualBox's using the following for these serial port settings:

                  @
                  serialPort = new QextSerialPort(serialDevice, QextSerialPort::EventDriven);
                  serialPort->setBaudRate(BAUD115200);
                  serialPort->setFlowControl(FLOW_OFF);
                  serialPort->setParity(PAR_NONE);
                  serialPort->setDataBits(DATA_8);
                  serialPort->setStopBits(STOP_2);
                  @

                  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