2013-01-10 119 views
0

我的問題是,我試圖檢查與不同的port_name像7或14或25.它不打開或處理串行數據的句柄只是與if條件匹配,它正在關閉句柄。代碼有問題嗎?錯誤開放端口

void command_handler::start() 
{ 
    char port_name[] = "COM7:";  /* Name of the serial port */ 

    serial_port = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); 
    /* Make sure port was opened */ 

    if (serial_port == INVALID_HANDLE_VALUE) 
    { 
     fprintf(stderr, "Error opening port\n"); 
     printf("I'm here"); 
     CloseHandle(serial_port); 
     exit(0); 
    } 
    set_up_serial_port(serial_port, baud_rate); 
    process_serial_data = false; 
} 

回答

0

你有沒有試過下面命名:

char port_name[] = "\\\\.\\COM7"; 

的第二個問題,也許是CHARWCHAR差異。我想你應該發送一個WCHAR字符串到API。