文章目录
-
- @[toc]
- 背景
- 遇到的问题
-
- 1 看得到串口,但是一直打开失败,GetLastError=433
- 2 看得到串口(COM16),但是一直打开失败,GetLastError=2
文章目录
-
- @[toc]
- 背景
- 遇到的问题
-
- 1 看得到串口,但是一直打开失败,GetLastError=433
- 2 看得到串口(COM16),但是一直打开失败,GetLastError=2
背景
需要在win7上通过串口控制光源,因为没有对应的串口接口,所以使用了
PL2303的串口转USB线。
使用的API是CreateFileA
遇到的问题
1 看得到串口,但是一直打开失败,GetLastError=433
433这个错误码在微软的error code表没有找到,后来在stackoverflow找到
一点资料,说是找不到设备,我用下好的驱动程序更新一下,解决
2 看得到串口(COM16),但是一直打开失败,GetLastError=2
2的意思是文件不存在。
这个问题的原因是COM超过9以后需要特殊处理,所以我换了个前面的USB,就正常了。
问题相关资料link:
https://stackoverflow.com/questions/48029055/configuring-serial-port-with-windows-api-createfile-failed-with-error-2-error
If you want to use a COM port above 9 you have to use the Win32 device path syntax:
LPCTSTR pcCommPortWin32DevicePath = TEXT("\\.\COM16");
HANDLE hCom = CreateFile(pcCommPortWin32DevicePath, ...);
(MSDN describes the string as it should look in memory, not in your code. Your clue to this is the single slash in the example string. This means you must double all backslashes to get a correct C literal string.)