I'm guessing Windows.
Any C/C++ Compiler should be able to access COM Ports, but after about COM4 the naming converntion channges to "\\.\COMx"
Here's some well used code of mine that access any COM port on Windows:
The CString is from MFC, but you can substitute the string behaviour for whatever is appropriate in your compiler.
openPort(int comPort, int baudRate)
{
CString str;
CString log;
COMMTIMEOUTS timeouts;
str.Format(L"\\\\.\\COM%d",comPort);
TRACE(L"Attempting to open %s\r",str);
//Call CreateFile to open the comms port
hPort = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hPort == INVALID_HANDLE_VALUE)
{
log.Format(L"Failed to open the comms port, Error:%d\n", GetLastError());
return hPort;
}
//Get the current state prior to changing it
DCB dcb;
dcb.DCBlength = sizeof(DCB);
if (!GetCommState(hPort, &dcb))
{
TRACE(L"Failed to get DCB. Oops. Oh well.\r");
return hPort;
}
//Setup the baud rate
dcb.BaudRate = baudRate;
dcb.Parity = NOPARITY;
dcb.ByteSize = 8;
dcb.StopBits = ONESTOPBIT;
dcb.fDsrSensitivity = FALSE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
//Now that we have all the settings in place, make the changes
SetCommState(hPort,&dcb);
GetCommTimeouts(hPort, &timeouts);
timeouts.ReadIntervalTimeout=50; // 50 ms timeout
timeouts.ReadTotalTimeoutConstant = 50;
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.WriteTotalTimeoutConstant = 50;
timeouts.WriteTotalTimeoutMultiplier = 10;
SetCommTimeouts(hPort, &timeouts);
return hPort;
}
Thank you so much sir and yes OS is windows and I read on user manuals that as DOS is older, it can access only 4 COM port addresses.
If I understand you correctly, you want to connect to your device via UART (in your case a Virtual Comport) and you want to make a GUI on Windows to handle it. There are nice toolkits like GTK, QT, WxWindows that you could use, but it takes a bit practice to implement them.
If you really want to use C++, I would suggest installing Visual Studio Community edition, there you have under C++ an option to create a CLR empty project and add a Windows form to it.
VS libraries are a bit… you will see, but it’s the easiest way to create a GUI for VCP, if you don’t have a lot of experience. The GUI design is simple drag and drop option and you get your actions and function prototypes automatically.
Michal
Thanks for the reply sir but I am not allowed to use tool kits and I have to implement from the scratch.
Howdy, you're not saying which OS or compiler. A DOS C++ has a short COM list. If C++ under Visual Studio, not a problem. I've got several BASIC under Visual Studio apps that control stuff through a serial port (usually via USB<->SIO). Frequently the USB converters are COM9 or higher. G.H. <<<)))
Thanks for the reply sir and I am using windows OS and DOS compiler