Important: Please read the Qt Code of Conduct -

Simulate date on serial port

  • Hi,

    I am developing desktop application that needs to communicate with hardware device via serial interface. Currently I do not have the hardware device but I have read data sheet and started to develop a test application while waiting for a device. Anyway I have created small test application that opens serial port and connects readyRead signal with slot function that will do the parsing of received data.
    As per specification the device will periodically send data as 24 byte blocks like this:
    //during ablations, source is a string of 24 bytes:

    // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    //066 128 128 166 128 144 130 128 128 180 131 168 129 248 129 128 128 128 128 128 128 173 233 000

    066 is start of the data block byte and 000 is end od the block byte.

    Because I have started to develop an app before I received the hardware device I would like to simulate the data flow. For that reason I have installed com0com to create two virtually connected serial ports (com5 and com6) and I have installed "Com port data emulator" software to simulate date. In this emulator software in data source section I choose text string and and copy all the above example bytes. But in my test application I receive this data block as 122 bytes block. Maybe I need to setup this emulator software in another way.

    My slot that handles received data is:

    qDebug() << "New data available: " << m_pSerialPort->bytesAvailable();
    QByteArray datas = m_pSerialPort->readAll();
    qDebug() << datas;

    Any suggestions?


  • Lifetime Qt Champion


    Maybe I need to setup this emulator software in another way.

    Most likely. I assume you send the characters as string, not as bytes. Can this software send raw bytes?


Log in to reply