Win7串口开发的的一些错误以及解决方案
文章目錄
- @[toc]
- 背景
- 遇到的問(wèn)題
- 1 看得到串口,但是一直打開(kāi)失敗,GetLastError=433
- 2 看得到串口(COM16),但是一直打開(kāi)失敗,GetLastError=2
- @[toc]
- 1 看得到串口,但是一直打開(kāi)失敗,GetLastError=433
- 2 看得到串口(COM16),但是一直打開(kāi)失敗,GetLastError=2
背景
需要在win7上通過(guò)串口控制光源,因?yàn)闆](méi)有對(duì)應(yīng)的串口接口,所以使用了
PL2303的串口轉(zhuǎn)USB線(xiàn)。
使用的API是CreateFileA
遇到的問(wèn)題
1 看得到串口,但是一直打開(kāi)失敗,GetLastError=433
433這個(gè)錯(cuò)誤碼在微軟的error code表沒(méi)有找到,后來(lái)在stackoverflow找到
一點(diǎn)資料,說(shuō)是找不到設(shè)備,我用下好的驅(qū)動(dòng)程序更新一下,解決
2 看得到串口(COM16),但是一直打開(kāi)失敗,GetLastError=2
2的意思是文件不存在。
這個(gè)問(wèn)題的原因是COM超過(guò)9以后需要特殊處理,所以我換了個(gè)前面的USB,就正常了。
問(wèn)題相關(guān)資料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.)
總結(jié)
以上是生活随笔為你收集整理的Win7串口开发的的一些错误以及解决方案的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: (六)Graphics基本应用
- 下一篇: win2003 Enterprise E