>Dear Experts
>
>I developed an application that sends SMS messages from a USB GSM modem. I'm using a third party dll. I need to pass in the COM PORT, that the modem appears to be connected to.
>
>So far, I've been looking up the COM PORT manually using the Windows Device Manager, and write it into a properties file. I'm wondering if there's a way to detect which COM PORT, the modem is connected to programmatically?
>
>It'll save the trouble of looking it up every time.
>The port number changes if I unplug/replug it sometimes.
>
>Please help
A quick-and-dirty hack.. Doesn't really answer your question as it only lists the available serial ports (does not indicate if serial port is associated with a modem or not), it also fails to list serial ports already opened by the current or other process.
LOCAL I,nH
SET TALK OFF
FOR I=1 TO 25
nH = FOPEN("COM"+TRANSFORM(m.I),12)
IF nH<>-1 THEN
? "COM"+TRANSFORM(m.I)
=FCLOSE(m.nH)
ENDIF
ENDFOR
SET TALK ON
In checking to see if you've got a modem on the serial port, you could try sending "AT"+CHR(13) and see if you get a response (e.g. "OK" in response) -- though if you've got type of device (say a printer) on that port, you'll be sending "garbage" to it (in the case of printer, it'll print something).