VB query modem for Dial Tone

BigBobBK
BigBobBK used Ask the Experts™
on
I'm trying to use VB to detect a dial tone from my USRobotics 56K modem on serial port 1.  I've created this script and it works when I step thru it in debug but when I try to run the script it never reports a No Dialtone message.

I've been fighting this for days.  Can someone please help me?  Here is what I have:
--------------------------------------------------------------------------
Private Sub Command1_Click()
Dial (Number)
Unload Me
End
End Sub

Private Sub Form_Load()

'Option Explicit
Dim PhoneNumbers() As String
Dim CancelFlag
End Sub

Private Sub CancelButton_Click()
    CancelFlag = True

    CancelButton.Enabled = False
End Sub

Private Sub Dial(Number)
    Dim DialString As String, FromModem As String
    Dim StopString As String
    Dim Delay As Double
    Dim sData As String

    DialString = "ATX4&D2DT" & sData & ";" & vbCr
   
    StopString = "ATH0" & vbCr
    '-- Comm port settings
    MSComm1.Settings = "9600,N,8,1"
   
    '-- Open the comm port
    On Error Resume Next
    MSComm1.PortOpen = True
    If Err Then
       MsgBox "COM1: not available. Change the CommPort property to another port."
       Exit Sub
    End If
   
    '-- Flush the input buffer
    MSComm1.InBufferCount = 0
   
    '-- Dial the number
    MSComm1.Output = DialString
   
    '-- Wait for "OK" to come back from the modem
    Dim cnt As Integer
   
    Do
       DoEvents
       '-- If there is data in the buffer, then read it.



       If MSComm1.InBufferCount Then
              Dim x As Integer
       x = x + 1
       
        If x > "5" Then
          FromModem = FromModem & MSComm1.Input
          '-- Check for "OK"
          If InStr(FromModem, "OK") Then
             '-- Notify the user to pick up the phone
             FromModem = ""
             Beep
             MsgBox "Please pick up the phone and either press Enter, or click OK"
             Exit Do
          ElseIf InStr(FromModem, "NO DIAL TONE") Or InStr(FromModem, "NO DIALTONE") Then
             FromModem = ""
             Beep
             MsgBox "Dialtone not detected.  Please check the telephone connection."
             CancelFlag = True
             Exit Do
          End If
       End If
       End If
       
       '-- Was Cancel pressed?
       If CancelFlag Then
          CancelFlag = False
          Exit Do
       End If
    Loop

    '-- Disconnect the modem
    Comm1.Output = StopString
   
    '-- Close the port
    Delay = Timer
    While Delay + 1 > Timer
        DoEvents
       '-- If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem = FromModem & Comm1.Input
       End If
    Wend
    Comm1.DTREnable = False    'belts and suspenders
    Delay = Timer              'disconnect.  If StopString
    While Delay + 1 > Timer    'worked, this isn't needed.
        DoEvents
    Wend
    Comm1.DTREnable = True
    Comm1.PortOpen = False
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
This is a VB6 app.  But if anyone would have help based on vb,net i would be interested.  I am desperate for any solution.
Top Expert 2014

Commented:
I think you need either telephony software or roll up your sleeves and get familiar with TAPI.

I know the guys at Exceletel and they described the work they did to make software development easier for application guys.
http://www.exceletel.com
Analyst programmer
Commented:
If it works when you step through it, but not when its compiled, it sounds like you need to introduce a longer delay between when you dial and when you check for a response. Looping five times and then checking will only add a delay of a fraction of a second and is probably not long enough. Try adding a timer control to increase the delay for a few seconds (much better than "busy waiting").
in other words, the the Dial() method should finish with the lines:
' -- Dial the number
    MSComm1.Output = DialString
   Timer1.Interval = 3000
   Timer1.Enabled = True

and then in the Timer1_Timer() event, disable the timer and then continue on with the rest of the code:

Timer1.Enabled = False
'-- Wait for "OK" to come back from the modem
    Dim cnt As Integer
   
    Do
       DoEvents
       '-- If there is data in the buffer, then read it.

etc etc

Author

Commented:
Thanks.  I'll keep working at it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial