EasyCom
 

 

EasyCom product information

The EasyCom ActiveX control is a Winsock/Telnet communication component. It is intended for VB and VC++ developers to easily add communication capabilities to their applications. Examples of such communication capabilities might include handling and configuration of remote network equipments and servers, and getting information on such systems.

How to use EasyCom ?

The steps are the following :

Insert the component into your application

In your development environment (any environment that affords using ActiveX full controls), drag'n'drop the component on the form or dialog where it will reside.

Setup the design-time properties

These include the license owner and key information.

Call the methods

EasyCom methods should be called in the following order. First :

1 - Open
2 - Connect

Then as many of these as you need :

3 - Write or WriteNoEcho
3 - Read

Then these :

4 - Disconnect
5 - Close

The Version method may be called at any time to get the component's current version. The interrupt methods works in the X25 or X3 case. Else it does nothing.

Handle the event

The Incoming event may be triggered when the CheckIncoming method is called with a “true” parameter and characters are received from the remote computer.

VB Sample

Here is a sample of some VB code using the control. In this example, the EasyCom control has been dropped on a VB form and is named EasyCom1. A button named “Go” affords triggering the network stuff :

Private Sub Go_Click()

Dim s As String
Dim n As Integer
Dim b As Byte

' let's not 2 Go_Click() calls talk to the same EasyCom
Go.Enabled = False

' opening as telnet will afford minimal telnet protocol handling
n = EasyCom1.Open("Telnet")

' connect to remote host - IP address or host name
If n = 0 Then n = EasyCom1.Connect("machine1")

' parameter 1 : the vertical bar is mandatory to delimit the string expected
' parameter 2 = 0 : no partial return is expected
' parameter 3 = 8 : time out is 8 seconds
' parameter 4 = false : do not reinitialize read buffer
' parameter 5 = string : characters read
If n = 0 Then n = EasyCom1.Read("login: |", 0, 8, False, s)

' notice that "& vbCr" is necessary for the string to be effectively sent
If n = 0 Then n = EasyCom1.Write("user1" & vbCr)

' do read and write stuff, WriteNoEcho to display passwords
If n = 0 Then n = EasyCom1.Read("Password: |", 0, 8, False, s)
If n = 0 Then n = EasyCom1.WriteNoEcho("password1" & vbCr)
If n = 0 Then n = EasyCom1.Read("$ |", 0, 8, False, s)

' telnet connect to a second machine
If n = 0 Then n = EasyCom1.Write("telnet machine2" & vbCr)
If n = 0 Then n = EasyCom1.Read("login: |", 0, 8, False, s)
If n = 0 Then n = EasyCom1.Write("user2" & vbCr)
If n = 0 Then n = EasyCom1.Read("Password: |", 0, 8, False, s)
If n = 0 Then n = EasyCom1.WriteNoEcho("password2" & vbCr)
If n = 0 Then n = EasyCom1.Read("$ |", 0, 8, False, s)
If n = 0 Then n = EasyCom1.Write("some command -o " & Cust1.Text & vbCr)

' ---> here 2 different strings may be received from the remote computer
' ---> EasyCom recognizes this and returns 0 if the 1st string is received
' ---> and 1 is the 2nd is received. if 1 is returned, the program chooses
' ---> not to process the further following reads and writes
If n = 0 Then n = EasyCom1.Read("[n] |unknown|", 0, 300, False, s)

' remote computer is waiting for user entry to give additional details - say yes
If n = 0 Then n = EasyCom1.Write("y" & vbCr)

' parameter 4 = true : reinitialize read buffer, discarding data in buffer
If n = 0 Then n = EasyCom1.Read("$ |", 0, 30, True, s)

' Disconnect and close
EasyCom1.Disconnect
EasyCom1.Close

' allow again go button
Go.Enabled = True

' one answer not received in due time - exit
If n = -2 Then
MsgBox "Timeout waiting for answer", vbExclamation
Exit Sub
End If

' com error - exit (error message already given by EasyCom)
If n < 0 Then
Exit Sub
End If

' remember "If n = 0 Then n = EasyCom1.Read("[n] |unknown|", 0, 300, False, s)"
' n = 1 means we're in the "unknown" case so no other information is available
If n = 1 Then
MsgBox "Customer " & Cust1.Text & " is unknown.", vbExclamation
Exit Sub
End If

' search for string "_nav" in last part of the string received
n = InStr(s, "_nav")

' not found - exit
If n = 0 Then
MsgBox "No information has been found.", vbExclamation
Exit Sub
End If

' found, get 8th character after "_" in "_nav"
b = Mid$(s, n + 8, 1)
s = "The information is : " & b

' say it
MsgBox s, vbInformation

End Sub