0

My problem is that I have try and check with different port_name like 7 or 14 or 25. It's not opening or process the serial data the handle simply matching with the if condition and it is closing the handle. Is there any problem with the code?

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;
}
Charles Menguy
  • 40,830
  • 17
  • 95
  • 117

1 Answers1

0

Did you tried below naming:

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

The second issue maybe is difference of CHAR and WCHAR. I think you should send a WCHAR string to the API.

masoud
  • 55,379
  • 16
  • 141
  • 208