我用API打开串口时,COM1-COM9都可以的,可是COM10就不行了,急急急急急急急急

解决方案 »

  1.   

    你是不是用Spcomm打開的?? 是有個小bug, 要修改源碼才解決!!
      

  2.   

    参考一下 EnumDisplaySettings 函数的帮助,你就理解怎么做啦
    在 2K、XP 下,设备名是以 \\.\ 开头的
    lpszDeviceName 
    Pointer to a null-terminated string that specifies the display device whose graphics mode the function will obtain information about. 
    This parameter can be NULL. A NULL value specifies the current display device on the computer that the calling thread is running on. If lpszDeviceName is not NULL, the string must be of the form \\.\DisplayX, where X can have the values 1, 2, or 3. COM10 或者以上即是 \\.\COM10-----------------------------------
    现在混水园了!
      

  3.   

    COM10? COM11行吗?——是系统有问题?
      

  4.   

    DWORD ComWin32::Open(void)
    {
    char  portName[MAX_PATH];
    // 在 C/C++ 字符串中,\\ 才代表 字符 \
    wsprintf(portName, "\\\\.\\COM%d", comID + 1); // comID = 0~31
    comHandle = CreateFile(portName,                      // Name
    GENERIC_READ | GENERIC_WRITE,  // Access mode
    0,                             // Share mode
    NULL,                          // Security attributes
    OPEN_EXISTING,                 // How to create
    FILE_ATTRIBUTE_NORMAL |        // File attributes
    FILE_FLAG_OVERLAPPED,
    NULL                           // Template
    );

    if (comHandle == INVALID_HANDLE_VALUE)
    comLastError = GetLastError();
    else
    comLastError = NO_ERROR;

    return comLastError;
    } // ComWin32::Open()