WinAPI打开串口失败
串口号为COM11,通过WinAPI始终无法打开串口,才发现原因如下:
http://www.advancedvirtualcomport.com/faq.html
How do I open a virtual serial port with a number higher than 9 from my application?
Windows automatically maps COM1-COM9 ports to the right device name. COM ports with higher numbers should be opened as \\.\COMxxx, where xxx is a port number.
Example for C/C++/C#:
hPort = CreateFile("\\\\.\\COM15", ...);
Example for VB:
hPort = CreateFile("\\.\COM15", ...);
Example for Delphi:
hPort := CreateFile('\\.\COM15', ...);
另发现:如果出现1~9 COM port打不开,可能会因为是之前打开后忘记关闭了,系统自动映射会有记录,再次打开时无法成功打开,需要关闭该COM口或者重启电脑(比较裸)。