I know I posted a more simplified listing somewhere, but could not find it in the search on my own name

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 "
byts = Comm(#nComm, RxQue) Comm Recv #nComm, byts, n$ Comm Send #nComm, "ATH0" & $CrLf 'hang up JIC it dials
'http://www.powerbasic.com/support/pbforums/showthread.php?t=6468&highlight=modem+detection 'by Peter Lameijn '================================================================================================== ' Modem detection example. PST_xxx equates are in Winbase.h '================================================================================================== #Include "win32api.inc" %PST_MODEM = &h00000006& Function PBMain () As Long Local lRet&,lComm&,lCommProp As CommProp Local Comport$, ctr&, p_ptr& '<<< This commented section works fine. ' lComm& = CreateFile("COM1",%GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,%OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) ' If lRet = %INVALID_HANDLE_VALUE Then Exit Function ' lRet = GetCommProperties(lComm&,lCommProp) ' If lCommProp.dwProvSubType = %PST_MODEM Then ? "Modem on Com 2" ' CloseHandle lComm& ' ' lComm& = CreateFile("COM2",%GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,%OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) ' If lRet = %INVALID_HANDLE_VALUE Then Exit Function ' lRet = GetCommProperties(lComm&,lCommProp) ' If lCommProp.dwProvSubType = %PST_MODEM Then ? "Modem on Com 2" ' CloseHandle lComm& ' ' lComm& = CreateFile("COM3",%GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,%OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) ' If lRet = %INVALID_HANDLE_VALUE Then Exit Function ' lRet = GetCommProperties(lComm&,lCommProp) ' If lCommProp.dwProvSubType = %PST_MODEM Then ? "Modem on Com 3" ' CloseHandle lComm& ' ' lComm& = CreateFile("COM4",%GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,%OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) ' If lRet = %INVALID_HANDLE_VALUE Then Exit Function ' lRet = GetCommProperties(lComm&,lCommProp) ' If lCommProp.dwProvSubType = %PST_MODEM Then ? "Modem on Com 4" ' CloseHandle lComm& '<<< However this does not work, it gives a "Parameter Mismatch error For ctr = 0 To 9 'Doesn't work ' Comport$ = Left$("COM" & Using$("#", ctr), 4) & $Nul ' lComm& = CreateFile(Comport$, %GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,%OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) 'Nor does this p_Ptr = StrPtr(Comport$) 'didn't work either lComm& = CreateFile(p_Ptr, %GENERIC_READ Or %GENERIC_WRITE,0,ByVal %Null,% OPEN_EXISTING,%FILE_FLAG_OVERLAPPED,ByVal %Null) If lRet = %INVALID_HANDLE_VALUE Then Exit Function lRet = GetCommProperties(lComm&,lCommProp) If lCommProp.dwProvSubType = %PST_MODEM Then ? "Modem on " & Comport$ CloseHandle lComm& Next ctr ? "Done",,FuncName$ End Function '
'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 '
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: