|
-
Aug 7th, 2000, 04:11 PM
#1
Thread Starter
Lively Member
is there a way to know which port the modem is located at during run time?
-
Aug 9th, 2000, 04:47 AM
#2
Lively Member
This could be one way.
Hope it could be for some help
Best Regards
/Lennart Johansson
----------------------------------
First produce the sub Modemcommand
----------------------------------
Function ModemCommand (AtCommand$) as integer
Dim timeout&
Dim Buffer$
Dim CRLF as string
CRLF = chr$(13) & chr$(10)
Comm1.output=ATCommand$ & chr$(13)
'assume a timeout error
ModemCommand=2
Timeout=Timer+1
Do until Timer > Timeout&
Doevents
Buffer$=Buffer$ & Comm1.input
If instr(Buffer$,"OK" & CRLF) then
ModemCommand =0
Exit Do
end if
If instr(Buffer$,"ERROR" & CRLF) then
ModemCommand =1
Exit Do
end if
Loop
end Function
-----------------------------------
Then create the function FindModem.
Thisone returns only the first modem
-----------------------------------
Function FindModem (BitRate&)
'This routine leaves the comport open if found
Dim I%
Dim Portnum%
Dim ErrCode%
If Comm1.Portopen then Comm1.Portopen=False
Bitrate&=1200
Comm1.RTSEnable=True
'lowest speed
Comm1.Settings=Format$(BitRate&) & ",n,8,1"
On Error resume next
For I% = 1 to 9
'checks ports 1 through 9
Comm1.Commport=I%
'Try to open the port
Comm1.Portopen=True
If Comm1.Portopen then
'Port opened ok. Test for modem by sendin "AT"
Errcode%=ModemCommand("ATV1Q0")
If ErrCode%=0 then
PortNum%=I%
exit for
else
'Ok was not recieved
'Comm1.Portopen=False
'Portnum%=0
end if
end if
next I%
'Modem found?
If PortNum% > 0 then
'Start at the highest speed
BitRate&=19200
Do
Comm1.Settings=Format$(Bitrate&) & ",n,8,1"
'Port has opened ok. Now test for speed by sending "AT"
ErrCode%=ModemCommand("AT")
If ErrCode%=0 then exit do
BitRate&=Bitrate& \ 2
Loop until Bitrate& = 1200
FindModem=Portnum%
end if
end function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|