Solved

Using MSComm

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

912 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

23 Experts available now in Live!

Get 1:1 Help Now