[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1408
  • Last Modified:

Using MSComm

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
chekhov
Asked:
chekhov
  • 3
1 Solution
 
kamallCommented:
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
 
chekhovAuthor Commented:
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
 
kamallCommented:
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
 
kamallCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now