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
.NET ProgrammingVisual Basic Classic

Avatar of undefined
Last Comment
BigBobBK

8/22/2022 - Mon
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.
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
Karen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
BigBobBK

ASKER
Thanks.  I'll keep working at it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck