Monday, November 26, 2012

Problem With Serial Port COM10 and Higher

Suddenly when I was doing my experiment today, I stumble upon one "small" problem.

All ports from COM1 to COM9 will have no problem when being opened with Turbo C++ or Visual C++ that uses Win32 API (~from my understanding). Any attempt to open COM greater than COM10 will resulted an error.

By asking Google Sensei, a found a suggestion to the problem and try it out. And it was so great that I managed to solve the problem by tweaking here and there and a little effort of try and error method.

The suggestion to use "\\.\COM10" will not work in Turbo C++ as advised however "\\\\.\\COM10" perfectly worked!!

The codes below is being used in my serial communication class;

        // Check if COM10 & above
    AnsiString tempPort;
    int i = portName.Length();

    if(isdigit(portName[i-1])) {
        tempPort.sprintf("\\\\.\\%s", portName);
        portName = tempPort;
    }
ハッピー

No comments: