Searching for code to find Comport with a modem attached, all that I found (plenty hits) were more than either I wanted to fool with, or more than I understood. So here's a simple version I came up with. Probably lots of bad stuff is gonna happen (BSOD's, GPF's, ...) but it works on my machine at least (so far).
'
'
Code:
'Find Modem.bas - 'XP SP3 - PBWin 8.03 #Compile Exe #Include "WIN32API.INC" Sub Find_Modem_Comport Local ctr&, byts&, ComPort$, ncomm&, prts$, n$ ncomm = FreeFile ErrClear For ctr = 0 To 9 COMPORT$ = "COM" & Using$("# ", ctr) Comm Open COMPORT$ As #nComm Sleep 100 'JIC it needs the time to open If Err Then 'no modem attached here Close ncomm 'JIC ErrClear 'set to 0 for next try Else 'Got a modem maybe Comm Set #nComm, Baud = 115200 ' 9600 baud Comm Set #nComm, Byte = 8 ' 8 bits Comm Set #nComm, Parity = %False ' No parity Comm Set #nComm, Stop = 0 ' 1 stop bit Comm Set #nComm, TxBuffer = 4096 ' 4k transmit buffer Comm Set #nComm, RxBuffer = 4096 ' 4k receive buffer 'n$ = "ATDT 1234567" & $CrLf '<< Hear dial tone and number dialed but returns nothing 'n$ = "+++" '<< returns nothing n$ = "AT" & $CrLf 'returns OK Comm Send #nComm, n$ Sleep 10 'wait for reply 'nothing returns regardless of how Long 'except For "AT" which return "OK" byts = Comm(#nComm, RxQue) Comm Recv #nComm, byts, n$ Comm Send #nComm, "ATH0" & $CrLf 'hang up JIC it dials If byts > 0 Then 'Valid modem available ? "Received " & n$,, COMPORT$ & " is GOOD " End If End If ' Close ncomm Next ctr Close End Sub Function PBMain Call Find_Modem_Comport End Function '
Comment