GetCommTimeouts 函数失败,错误代码为 50
当我开发PCIe通信接口时,我使用了CreateFile & Readfile函数来操作设备。但是当我尝试为句柄设置超时时,我遇到了以下问题,这是我的代码,
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 函数工作正常,但是当我想获取其超时设置时,它返回错误代码 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我通过改变driver中的设置参数解决了这个问题,实现了与SetCommTimeouts()相同的功能
Finally, I solved this problem by changing the setting parameters in driver to achieve the same function as SetCommTimeouts()