我用虚拟串口工具虚拟出20个串口,但是程序只能认到9,超过10,在ClearCommError时,返回错误,请教是怎么回事。

解决方案 »

  1.   

    http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;115831HOWTO: Specify Serial Ports Larger than COM9你只要将com10 改为: \\.\COM10
    就可
      

  2.   

    SUMMARY
    CreateFile() can be used to get a handle to a serial port. The "Win32 Programmer's Reference" entry for "CreateFile()" mentions that the share mode must be 0, the create parameter must be OPEN_EXISTING, and the template must be NULL.CreateFile() is successful when you use "COM1" through "COM9" for the name of the file; however, the message
    INVALID_HANDLE_VALUE
    is returned if you use "COM10" or greater.If the name of the port is \\.\COM10, the correct way to specify the serial port in a call to CreateFile() is as follows:
    CreateFile(
          "\\\\.\\COM10",     // address of name of the communications device
          fdwAccess,          // access (read-write) mode
          0,                  // share mode
          NULL,               // address of security descriptor
          OPEN_EXISTING,      // how to create
          0,                  // file attributes
          NULL                // handle of file with attributes to copy
       );
      

  3.   

    特别感谢  aiirii(ari-淘金坑) 
    问题搞定。