Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using MSComm 1

Status
Not open for further replies.

cscs

Technical User
Jan 18, 2001
3
US
What I am trying to do is to dial a phone number and have the program determine if that number is "busy" or "ringing". I can get the program to dial the number with no problem but to this point I have had no luck in returning anything but the number that is sent to the modem and an "OK" response.

I am using VB6, on winXP, with an external US Robotics 56K modem (I have also checked the modem DIP switches - to make sure it is returing text responses).

Below I have posted the code to try and get this accomplished, but still have not gotten the "Connect" or "Busy" response I am after. Any help on what I am doing wrong or what I should look for would be greatly appreciated.

Thanks.
-----------------------------------------------------------
Example
-----------------------------------------------------------
Private Sub cmdDial_Click()
Const MAX_TRIES = 10000

Dim results, mynum As String
Dim num_tries As Long

'need to figure out how to compare times

mynum = PNum1.Text
Screen.MousePointer = vbHourglass
On Error GoTo Oops

' Try to give MSComm1 time to close.
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False

' Read the entire buffer when Input is used.
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
buffer = ""

' 9600 baud, no parity, 8 data bits, 1 stop bit.
MSComm1.Settings = "9600,N,8,1"

' Open the comm port.
MSComm1.PortOpen = True

' Send the attention string to the modem.
'MSComm1.Output = "ATV1Q0" & Chr$(13)
MSComm1.Output = "ATV1X4" & Chr$(13)

Do
' Read the latest data from the serial port.
DoEvents
results = results & MSComm1.Input
num_tries = num_tries + 1
If num_tries > MAX_TRIES Then
MsgBox "Did not get OK response in " & _
MAX_TRIES & " tries"
Exit Do
End If
Loop Until InStr(results, "OK" & vbCrLf) > 0



' Dial the phone number.
MSComm1.Output = "ATDT " & mynum & ";" & vbCr


Do
DoEvents
buffer = buffer + MSComm1.Input

If InStr(buffer, "Connect") Then
Text3.Text = "Connected"
MSComm1.PortOpen = False
End If

If InStr(buffer, "Busy") Then
Text3.Text = "Busy"
MSComm1.PortOpen = False
End If

Loop

Oops:
MsgBox "Error " & Err.Number & vbCrLf & _
Err.Description, _
vbExclamation Or vbOKOnly, _
"Error"
Screen.MousePointer = vbDefault
Exit Sub

End Sub

 
buffer = buffer + MSComm1.Input
I don't use "+" to add strings together. I've seen this cause problems before. Use "&" instead.

You also might try inserting a

Debug.Print buffer

statement in your buffer read loop, to see what it's actually getting. It might not be matching your strings exactly.

HTH

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top