Link to home
Start Free TrialLog in
Avatar of BigBobBK
BigBobBK

asked on

VB query modem for Dial Tone

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
Avatar of BigBobBK
BigBobBK

ASKER

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.
Avatar of aikimark
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
ASKER CERTIFIED SOLUTION
Avatar of Karen
Karen
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.  I'll keep working at it.