0
votes

What I'm trying to do is write string to the serial port from the windows 7 host machine to the /dev/ttys0 in the guest Ubuntu machine.

I tested this using putty on both the host and guest machine. The data is written to the /dev/ttys0 from \.\pipe\COM1.

Now I want to use a simple QT5 program using this virtual serial port to write a string to the guest putty.

The problem I have is that the program isn't able to open this port , below is the Qt program.

#include <QtCore/QCoreApplication>
#include <QSerialPort>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSerialPort serial;
    qDebug() << " Serial communication starts .. ";
    serial.setPortName("\\.\pipe\COM1");
    if(serial.open(QIODevice::ReadWrite))
     {
        serial.setBaudRate(QSerialPort::Baud9600);
        serial.setDataBits(QSerialPort::Data8);
        serial.setParity(QSerialPort::NoParity);
        serial.setStopBits(QSerialPort::OneStop);
        serial.setFlowControl(QSerialPort::NoFlowControl);

        serial.write("blah blah");

      }
    else
        qDebug() << " Serial port isn't open : " << serial.errorString();
    while(serial.canReadLine())
    {
        qDebug() << " serial.readLine()" ;

    }

    serial.close();
    return a.exec();
}

the output of the debug :

Serial communication starts .. 
Serial port isn't open :  "No such file or directory"
1
I think you need more black slashes to escape the other correctly, try \\\\.\\pipe\\COM1 or R"(\\.\pipe\COM1)"Niall
@Niall that didn't work, it gives me the serial error of "incorrect function"Sam Gomari

1 Answers

0
votes

What is the software you use to run your virtual machine with Ubuntu?? If, it's VM Ware Workstation you can edit the preference of the VM and add a serial port.