Merge pull request #3110 from Cacodemon345/qt-compile-fix

Serial passthrough fixes on Windows
This commit is contained in:
Miran Grča
2023-02-15 18:12:37 +01:00
committed by GitHub
2 changed files with 12 additions and 6 deletions

View File

@@ -46,6 +46,9 @@ extern "C" {
# include <sys/stat.h>
# include <sys/sysmacros.h>
#endif
#ifdef Q_OS_WINDOWS
#include <windows.h>
#endif
DeviceConfig::DeviceConfig(QWidget *parent)
: QDialog(parent)
@@ -77,9 +80,15 @@ EnumerateSerialDevices()
}
#endif
#ifdef Q_OS_WINDOWS
QSettings comPorts("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM", QSettings::NativeFormat, nullptr);
for (int i = 0; i < comPorts.childKeys().length(); i++) {
serialDevices.push_back(QString("\\\\.\\") + comPorts.value(comPorts.childKeys()[i]).toString());
for (int i = 1; i < 256; i++) {
devstr[0] = 0;
snprintf(devstr.data(), 1024, "\\\\.\\COM%d", i);
auto handle = CreateFileA(devstr.data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0);
auto dwError = GetLastError();
if (handle != INVALID_HANDLE_VALUE || (handle == INVALID_HANDLE_VALUE && ((dwError == ERROR_ACCESS_DENIED) || (dwError == ERROR_GEN_FAILURE) || (dwError == ERROR_SHARING_VIOLATION) || (dwError == ERROR_SEM_TIMEOUT)))) {
if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
serialDevices.push_back(QString(devstr));
}
}
#endif
#ifdef Q_OS_MACOS

View File

@@ -73,9 +73,6 @@ plat_serpt_write_vcon(serial_passthrough_t *dev, uint8_t data)
// fwrite(dev->master_fd, &data, 1);
DWORD bytesWritten = 0;
WriteFile((HANDLE) dev->master_fd, &data, 1, &bytesWritten, NULL);
if (bytesWritten == 0) {
fatal("serial_passthrough: WriteFile pipe write-buffer full!");
}
}
void