Link between 2 serial ports



  • 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);
    }


  • Lifetime Qt Champion

    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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.