|
This example uses Visual Basic 5.0 to utilize KEPServerEX's Modem functions. In
addition to using Visual Basic to view the basic tags of the modem add-on, this example
will store a list of phone numbers and dial each number in turn. The Visual
Basic Source Code for this example can be downloaded and compiled on any machine running Visual Basic
5.0 or better. Any KEPServerEX serial communications project can be used.
Note: This is an intermediate level KEPServerEX Solution and assumes basic knowledge
of any version of Visual Basic.
How To Setup KEPServer For Use with this Example
In this example, we use a channel alias map name of ModemChannel. In
our Visual Basic application, the LinkTopic properties of
all the DDE links will be set to
"ServerMain|ModemChannel". If this is not your alias map name for the Channel,
you must change these DDE links.
Manual Operation
Manual Operation is an easy way to use Visual Basic to view the Modem tags in your
KEPServerEX project. All we need is nine text boxes (One for each Modem tag), one timer and
a few buttons. Each text box has it's LinkTopic property set to the appropriate tag. When the
program run, it initializes each text box and sets the LinkMode property to vbLinkAutomatic.
The Automatic link means that a constant connection is maintained between KEPServerEX and
this example. When the form is run, the following code is executed:
Private Sub Form_Load()
'Index for the array of text boxes
Dim X As Integer
'In case KEPSever is not ready, this will prevent the VB Project from throwing
an error
On Error Resume Next
'Set the 7 text boxes to Automatic
For X = 0 To 6
txtDDE(X).LinkMode = vbLinkAutomatic
Next X
' Set the 2 additional text boxes to Automatic
txtDial.LinkMode = vbLinkAutomatic txt
Hangup.LinkMode = vbLinkAutomatic
End Sub
Since the VB Project maintains a constant check to see if KEPServerEX is running, and
that the proper DDE connection is there, the timer is needed. This timer will check each
DDE connection every two seconds. If the LinkMode of the text box is set to None, then a
DDE link is not active. The timer will reset the link to Automatic, then move on to check
the next DDE connection.
Private Sub Timer_Timer()
Dim X As Integer
On Error Resume Next
'Check each text box to see if link has failed
For X = 0 To 6
'If so, set text to display status and reset the link
If txtDDE(X).LinkMode = vbLinkNone Then
txtDDE(X).Text = "Tag Not Defined"
txtDDE(X).LinkMode = vbLinkAutomatic
End If
Next X
'Check link status of Dial Tag
If txtDial.LinkMode = vbLinkNone Then
txtDial.Text = "-1"
txtDial.LinkMode = vbLinkAutomatic
End If
'Check link status of HangUp Tag
If txtHangup.LinkMode = vbLinkNone Then
txtHangup.Text = "-1"
txtHangup.LinkMode = vbLinkAutomatic
End If
End Sub
Automatic Operation
Automatic Operation is used to automate KEPServerEX. Using this example, KEPServerEX is
automatically dial each number in a User-Defined list for a specific amount a time. Once
the connection time has elapsed, KEPServerEX will dial a new number. The VB Project does
this by allowing the user to enter in a list of phone numbers and a time to stay connected.
There is also a delay time between connections, this give the modem a chance to reset, the
KEPServerEX time to reset, and so on. Once this data has been entered, the user clicks "Begin
Dialing" and can just sit back and wait for the data to come in. Plus, with Auto-Reconnect
checked, KEPServerEX will retry the last number dialed in the event it was disconnected. As
with the Manual Operation, a timer is needed to keep the DDE connections going. However,
this example also uses the timer to montior connection time, delay time, line disconnect
and Auto-Reconnect status.
Private Sub SecondTimer_Timer()
On Error Resume Next
' Check Link Status and Reset if needed
If txtLinkTest.LinkMode = vbLinkNone Then
txtLinkTest.Text = "-1"
txtLinkTest.LinkMode = vbLinkAutomatic
AddItem ("Warning: DDE Link Not Active, Trying to Reestablish.")
End If
'If link is still not active, assume there is no DDE link and stop
If txtLinkTest.LinkMode = vbLinkNone Then
'Link not active
AddItem ("Aborted: No Active DDE Connection")
SecondTimer.Enabled = False SetEnable (True)
Exit Sub
End If
'Line Status = Line Dropped when in Wait State. So, only reconnect when
' connected & time is remaining.
If ((txtLinkTest.Text = LineDroppedStatus) Or (txtLinkTest.Text = LineDroppedRemoteStatus))
And (SecondTimer.Tag > 0) And (Connected) Then
If btnReconnect.Tag = 1 Then
'Reconnect Enabled
AddItem ("Line Dropped By User... Reconnecting")
SecondTimer.Tag = 0 'Set Count to 0 to enable Wait State
ReDial
Exit Sub
Else
AddItem ("Line Dropped By User")
btnBegin_Click ' Click STOP to reset all fields
End If
End If
SecondTimer.Tag = Str(Val(SecondTimer.Tag) - 1)
If Connected And (SecondTimer.Tag >= 0) Then
txtTime.Text = "Connection Time Remaining: " & SecondTimer.Tag & " Seconds"
ElseIf (Not Connected) And (SecondTimer.Tag >= 0) Then
txtTime.Text = "Waiting: " & SecondTimer.Tag & " Seconds"
Else
txtTime.Text = "" 'To stop things like "Time Remaining: -1"
End If
If Val(SecondTimer.Tag) <= 0 Then
SecondTimer.Enabled = False
If Connected Then
Wait
Else
DialNext
End If
End If
End Sub
|