G
G
geek16bits2018-05-14 11:52:45
Qt
geek16bits, 2018-05-14 11:52:45

Is it possible to obtain a HANDLE with QSerialPort similar to the HANDLE obtained with CreateFile(winapi, )?

Is it possible to get a HANDLE using QSerialPort similar to the HANDLE obtained using CreateFile (winapi, windows.h)?
There is a code written in C ++ and WinApi, in which the port is opened to access the device with:

LPTSTR port_name = TEXT("COM5");

HANDLE hCom = CreateFile((LPCWSTR)port_name,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    0,
                    NULL);

I change the code above to:
HANDLE hCom;
QSerialPort *serial;
serial = new QSerialPort();
serial->setPortName("COM5");
serial->setBaudRate(QSerialPort::Baud38400);
serial->open(QIODevice::ReadWrite);

hCom = serial->handle();

After this change in the code, communication with the device stops working. The code compiles without errors, GetLastError returns 0 when the port is opened. When writing to the port using WirteFile, GetLastError starts returning error 997 ERROR_IO_PENDING.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question