Solved

Using MSComm

Posted on 1998-02-05
4
1,353 Views
Last Modified: 2011-09-20
I want to be able to detect if the modem has a dial tone or not. I've looked at the MSComm control, and it doesn't seem it can do this. Does anybody know how elses it can be done?
0
Comment
Question by:chekhov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1455812
chekhov, the MSComm cannot detect whether the modem has a dialtone or not. It can only send and receive data through the COM port. In order to detect if the modem has a dialtone, you must send a command to the modem and then read the modem's response. In other words, you send the string "ATDT555600" & CHR(13) to the COM port, which will be received by the modem, and then you will contuinuously read the input buffer of the COM port to get the answer of the modem which is "NO DIALTONE" if the modem will not detect the dialtone.
Best regards.
0
 

Author Comment

by:chekhov
ID: 1455813
Following your advice, I wrote the following function, but it doesn't work. It never gets out of the DO loop, because the string "NO DIALTONE" never was returned. In fact, no string was returned, as I monitored it through the "Debug.print FromModem$" statement

Public Function bModemHasDialTone() As Boolean
' returns True if modem has a dial tone, False otherwise
    Dim FromModem$, dummy
   
    Comm1.Settings = "300,N,8,1"
    On Error Resume Next
   
    Comm1.PortOpen = True
    If Err Then
       MsgBox "COM1: not available. Change the CommPort property to another port."
       bModemHasDialTone = False
       Exit Function
    End If
   
    ' Flush the input buffer.
    Comm1.InBufferCount = 0
   
    ' Dial the number.
    Dim sNumber As String
    sNumber = "ATDT555600"
    Comm1.Output = "ATDT555600" & Chr(13)
   
    Do
       dummy = DoEvents()
       ' If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          Debug.Print FromModem$
          FromModem$ = FromModem$ + Comm1.Input
          If InStr(FromModem$, "NO DIALTONE") Then
             bModemHasDialTone = False
             Exit Do
          End If
          If InStr(FromModem$, "OK") Then
             bModemHasDialTone = True
             Exit Do
          End If
       End If
    Loop
   
    ' Disconnect the modem.
    Comm1.Output = "ATH" + Chr$(13)
   
    ' Close the port.
    Comm1.PortOpen = False

End Function

0
 
LVL 7

Accepted Solution

by:
kamall earned 200 total points
ID: 1455814
Well, try this code which I have tested and is working just fine.
(Put 2 text boxes, one command button, one timer, and the MSComm control on the form. Set the Timer1 interval to 5000. Run the project and in the Text1 enter the command to be sent to the modem and click the Command1 button).

(Note: set the MSComm1 control to a relatively moderate baud rate; 9600 for example)

Private Sub Command1_Click()
Comm1.PortOpen = True
Text2.Text = "WAIT..."

    ' Flush the input buffer.
    Comm1.InBufferCount = 0
    Comm1.OutBufferCount = 0
    'Send command
    Comm1.Output = Text1.Text + Chr(13)
   
    ' Wait upto 5 seconds for answer to come back from the modem.
    x = Timer
    Do
       dummy = DoEvents()
       ' If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem$ = FromModem$ + Comm1.Input
       End If
    Loop Until Timer = x + 5
Text2.Text = FromModem$

Comm1.PortOpen = False
End Sub


0
 
LVL 7

Expert Comment

by:kamall
ID: 1455815
Also, note that not all the property value combinations of the MSComm control will work. Check the properties to be as below:
DTREnabled = True
EOFEnabled = False
Handshaking = NoHandshaking
NullDiscard = False
RThreshold = 0
RTSEnabled = False
SThreshold = 0
And keep all other default property-settings as is except the CommPort and the Settings (I tested it with 14400,n,8,1)
If you have any problems, drop me a comment with your e-mail address and I will send you the project.
Best regards
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question