Solved

Using MSComm

Posted on 1998-02-05
4
1,320 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
  • 3
4 Comments
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now