I have an application where I am writing data to the serial port via an USB to RS422 convertor. This convertor cable to connected to my PC through an USB hub. The problem I am facing is that each time I change the PC in which I am running the application, the name of the COM port changes. So I will have to change this in my code and recompile the code to run the application. At present following is the code I am using to initialize the serial port:
if ((comport = CreateFile("\\\\.\\COM7", GENERIC_WRITE, 0,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)) == INVALID_HANDLE_VALUE)
{
return false;
}
Here I am exclusively mentioning the name of the COM port. I would like to know if there is an API to know the status of the COM ports and on the fly recognize the COM port to which my convertor is connected ?