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;
}