Solved

MsComm Question

Posted on 1998-06-08
3
518 Views
Last Modified: 2008-03-17
I'm trying to use Mscomm control in visual basic and the
problem that i am having is that the modem is not
"letting go" after i place a call.  the code is simple
i use
mscomm1.commport = 2
mscomm1.settings = "9600,n,8,1"
mscomm1.portopen = true
mscomm1.output = "ATDT 5551212" & vbcr
mscomm1.portopen = false

...
This works fine for the first call however when i try to
make another call "even after shutting down the program"
it just runs through the code and does not dial.  
So i go into my terminal program "Telemate" and when i start
that program i can see strings of garbage coming from my modem
until the program initializes it.

So i'm missing a command let me know if anyone knows which one
it is.
0
Comment
Question by:jtjcomp
[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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1462754
jtjcomp,
You need to send a stop string to the modem when you finishes.
Comm1.OutOut = "ATH0" & Chr(13)
Wait tell the modem dtops, then close the port.
Any questions, let me know
Regards
Dalin


0
 
LVL 1

Author Comment

by:jtjcomp
ID: 1462755
I have tried that and it did not work, however i did not wait to close the port. but since i issued the hang up command shouldn't it have hung up regardless of the port status.
thanks in advance..
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1462756
jtjcomp,
This is some woring code.
You can see if it works for you. You need to pass the number to the routine.
Regards
Dalin

Private Sub Dial(Number$)
    Dim DialString$, FromModem$
    Dim StopString As String
    Dim Delay As Double

    '--- AT is the Hayes compatible ATTENTION command an is required to send commands to the modem.
    '--- DT means "Dial Tone" - The Dial command, using touch tones as opposed to pulse (DP = Dial Pulse)
    '--- PhoneNumbers$(Index) is the phone number of the person you're dialing
    '--- A semicolon tells the modem to return to command mode after dialing (important)
    '--- A Carriage return, Chr$(13), is required when sending commands to the modem.
    DialString$ = "ATX4&D2DT" + Number$ + ";" + Chr$(13)
    StopString = "ATH0" + Chr$(13)
    '-- Comm port settings
    Comm1.Settings = "300,N,8,1"
   
    '-- Open the comm port
    On Error Resume Next
    Comm1.PortOpen = True
    If Err Then
       MsgBox "COM1: not available. Change the CommPort property to another port."
       Exit Sub
    End If
   
    '-- Flush the input buffer
    Comm1.InBufferCount = 0
   
    '-- Dial the number
    Comm1.Output = DialString$
   
    '-- Wait for "OK" to come back from the modem
    Do
       DoEvents
       '-- If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem$ = FromModem$ + Comm1.Input
          '-- Check for "OK"
          If InStr(FromModem$, "OK") Then
             '-- Notify the user to pick up the phone
             FromModem = ""
             Beep
             MsgBox "Please pick up the phone and either press Enter, or click OK"
             Exit Do
          ElseIf InStr(FromModem$, "NO DIAL TONE") Or InStr(FromModem$, "NO DIALTONE") Then
             FromModem = ""
             Beep
             MsgBox "Dialtone not detected.  Please check the telephone connection."
             CancelFlag = True
             Exit Do
          End If
       End If
       
       '-- Was Cancel pressed?
       If CancelFlag Then
          CancelFlag = False
          Exit Do
       End If
    Loop

    '-- Disconnect the modem
    Comm1.Output = StopString
   
    '-- Close the port
    Delay = Timer
    While Delay + 1 > Timer
        DoEvents
       '-- If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem$ = FromModem$ + Comm1.Input
       End If
    Wend
    Comm1.DTREnable = False    'belts and suspenders
    Delay = Timer              'disconnect.  If StopString
    While Delay + 1 > Timer    'worked, this isn't needed.
        DoEvents
    Wend
    Comm1.DTREnable = True
    Comm1.PortOpen = False
End Sub
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

631 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