Solved

Using MSComm

Posted on 1998-02-05
4
1,333 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

786 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