'GetCommTimeouts function failed with error code 50

when I develop a PCIe communication interface, I used CreateFile & Readfile function to operate the device. But when I tried to set timeout to the handle, I met the following problem and this is my code,

    HANDLE* device;
    char device_path_process[MAX_PATH+1] = "";
    ...
    
    *device = CreateFile(device_path_process, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
    if (*device == INVALID_HANDLE_VALUE) {
        std::cout<< std::to_string(GetLastError()) << std::endl;
        status = 2;
        goto Exit;
    }
    COMMTIMEOUTS cto;
    if(!GetCommTimeouts(*device, &cto)) {
        std::cout<< std::to_string(GetLastError()) << std::endl;
        status = 3;
        goto Exit;
    }

CreateFile function worked normally, but when I want to get its timeout setting, it return error code 50.

Does anyone has ideas? Thanks!



Solution 1:[1]

Finally, I solved this problem by changing the setting parameters in driver to achieve the same function as SetCommTimeouts()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lyon