Win7串口开发的的一些错误以及解决方案

背景

需要在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.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值