Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Link between 2 serial ports
Qt 6.11 is out! See what's new in the release blog

Link between 2 serial ports

Scheduled Pinned Locked Moved C++ Gurus
2 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    goupil35
    wrote on last edited by
    #1

    Hello,
    I want to do a link between 2 serial ports (all coming in COM3 have to be resent to COM4 and the same in the other way).

    I use the terminal version and in "main.cpp" I create another MainWindow variable w1. In "MainWindow.cpp" I was able in method MainWindow::ReadData() to modify so I can test what is the COM (the code is included below).

    My problem is that when I do "serial->write(data);" it sends the data on the same COM that the bytes received. I want to send data received in the other one: if I get data on COM3 I want to send them on COM4 and vice-versa.

    Have someone an idea ?

    Thanks


    void MainWindow::readData()
    {
    QByteArray data = serial->readAll();
    console->putData(data);
    if (serial->portName()=="COM3")
    serial->write(data);
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      To make it simple, just use one MainWindow with two serial ports (use meaningful names for the variables) and one slot for each serial port (you can optimize that later)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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