Win7串口开发的的一些错误以及解决方案
文章目錄
- @[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.)
總結
以上是生活随笔為你收集整理的Win7串口开发的的一些错误以及解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (六)Graphics基本应用
- 下一篇: win2003 Enterprise E