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

1 に答える 1

0

以下の命名を試しましたか:

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

CHAR2 番目の問題は、おそらく と の違いですWCHARWCHARAPIに文字列を送信する必要があると思います。

于 2013-01-10T06:47:19.253 に答える