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. Problems using QSerialPort and an RS232-emulator.
Qt 6.11 is out! See what's new in the release blog

Problems using QSerialPort and an RS232-emulator.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.6k 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.
  • W Offline
    W Offline
    wost
    wrote on last edited by
    #1

    Unfortunately, I have no code to offer at this moment, seeing as the code is at another computer I don't have access to at the moment.

    So, I have two programs: both are reading from and writing to the same virtual COM-port. I have some problems sending data from the one program, and have the other program listen to this and parse it correctly. The one program sends one bit of data to the other program, that program reads this and sends a corresponding data back and the first program outputs this; and it's during the last step the program doesn't work as expected.

    For testing purposes I made it so that when the one program sends ACK to the other program, it will respond with 0x00, 0x00, 0x00. For some reason the data I get back is weird data with NEGATIVE or very huge hex values. I then tried to send NAK, and have it send back 0xFF, 0xFF, 0xFF; but for some reason I get back the exact same data. Like - EXACTLY the same, nothing different at all and still the weird values.

    I have absolutely no idea what I have done wrong. Are there anything I could try doing tomorrow when I get access to my computer?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      I'd say, run the Blocking Master Example and the Blocking Slave Example and see if they work as expected. Then compare the code to your own applications.

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

        @wost said in Problems using QSerialPort and an RS232-emulator.:

        So, I have two programs: both are reading from and writing to the same virtual COM-port

        Sorry, what?

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wost
          wrote on last edited by
          #4

          Haha, I'm using VSPE to create a virtual COM-port, and I then have two programs that connects to that port. Both can send and receive data from each other. If that makes any sense. :p

          mrjjM 1 Reply Last reply
          0
          • W wost

            Haha, I'm using VSPE to create a virtual COM-port, and I then have two programs that connects to that port. Both can send and receive data from each other. If that makes any sense. :p

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @wost said

            Hi
            You should test with other comm software that it works as expected. Then you know its a bug in your code and not the
            virtual device.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wost
              wrote on last edited by wost
              #6

              I got it to work!

              I simplified my code somewhat, and now I don't get any errors or crashes! I tried implementing my own (somewhat confusing) functionality for reading data, and that's not always a good idea. :P

              I did this:

              connect(&_port, &QSerialPort::readyRead, this, &Worker::_readData);
              

              and then this:

              bool Worker::_readData() {
              	_receivedData.append(_port.readAll());
              
              	if(_receivedData.count() >= 136) {
              // It should be this long
              		qDebug() << _receivedData;
              		qDebug() << "done reading...";
              		_receivedData.clear();
              		return true;
              	} else {
              		qDebug() << "reading...";
              	}
              }
              
              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