Hi, I am trying to detect the comm port, that the hardware is connected to, in my program before initialising it. What function can I use to do that? Can someone pls help me out? Thanks!
There isn't a serial function that will allow you to automatically detect the hardware. Your program needs to test (probe) the serial ports in the system.
A simple way would be to open a COM port and send a command. The depending on the response (if any) you can determine that the hardware is connected. This assumes that the hardware will have a fix RS-232 configuration. Depending on how your instrument uses the port you can think of different ways to identify your hardware.
I think this is basically what the OS and device driver do on ISA and PCI buses to detect the PC devices (and implement PnP).