最近用MOXA多串口卡,装好后系统有COM10,我用API CreateFile 函数就是说失败。但是我看到网上很多调试工具是可以打开COM10的。不知哪位碰到过这样的问题,请指点!谢谢!
我的代码:
m_hComm = CreateFile("COM10", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,          FILE_ATTRIBUTE_NORMAL,
NULL);

解决方案 »

  1.   

    \\\\..\\COM10(好象是这样),,不能使用"com10"...
      

  2.   

    MSDN是这么说的:HOWTO: Specify Serial Ports Larger than COM9CreateFile() 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
       );
    NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well. 
     
      

  3.   

    谢谢 lwglucky(才鸟) 
    搞定了
    应该是写成 \\\\.\\COM10