RMCLink COM Component

RMCLink.IsConnected Method

Checks to see if the link is currently connected to a controller.

Syntax

Visual Basic (Declaration)

Function IsConnected ( _

   ping As PingType _

) As Boolean

 

Visual Basic (Usage)

Dim instance As RMCLink

Dim ping As PingType

Dim returnValue As Boolean

 

returnValue = instance.IsConnected(ping)

Parameters

ping

This parameter determines if the link should try sending a test communication with the controller before deciding whether the connection is still established. Specify ptPing to do the test communication, and ptDoNotPing to determine if the connection is established based on the last communication attempt. This parameter is ignored if the connection is known to be closed.

Return Value

Return True if the connection is established (after a ping is sent out if ping is set to ptPing). Otherwise, returns False.

Remarks

This method is synchronous, which means that it will not return until the method is completed. If ping is ptDoNotPing, then it will return immediately. If ping is ptPing, then it may take several seconds to complete. If this method is called on the main thread, then the application will likely be unresponsive until this method completes. For applications where this is not acceptable, this and other synchronous methods should be called from a worker thread, and may use the CancelRequest method to cancel an in progress request.

Exceptions

Error Code

Description

rmcEInvalidArg = 7

The ping parameter must be ptPing (1) or ptDoNotPing (0).

Example

The following code example illustrates the use of the IsConnected method.

Visual Basic 6 / VBA

Option Explicit
 
Public Sub Sample()
    ' Declare and create the RMCLinkServer COM object.
    Dim srv As New RMCLinkServer
 
    ' Use our RMCLinkServer to create the correct type of RMCLink object.
    Dim rmc As RMCLink
    Set rmc = srv.CreateEthernetLink(dtRMC70, "192.168.0.22")
 
    ' Establish the connection.
    rmc.Connect
 
    ' Do some long task...
 
    ' Check to see if the link is still connected.
    Dim isConn As Boolean
    isConn = rmc.IsConnected(ptPing)
     If (isConn) Then
        resultText = "Connection is still made."
 
        ' Use the connection...
 
        ' Close the connection.
        rmc.Disconnect
    Else
        resultText = "Connection has been broken."
    End If
 
End Sub

 

VBScript

Option Explicit
Dim srv, rmc, isConn
 
' First we need to create the RMCLinkServer COM object.
Set srv = CreateObject("RMCLink.RMCLinkServer")
 
' Use our RMCLinkServer to create the correct type of RMCLink object.
' NOTE: VBScript does not support enumerations, so we use the literal value (dtRMC70=2).
Set rmc = srv.CreateEthernetLink(2, "192.168.0.22")
 
' Establish the connection.
rmc.Connect
 
' Do some long task...
 
' Check to see if the link is still connected. Again we use the literal value
' for the enumeration (ptPing=1).
isConn = rmc.IsConnected(1)
If ( isConn ) Then
    WScript.Echo "Connection is still made."
 
    ' Use the connection...
 
    ' Close the connection.
    rmc.Disconnect
Else
    WScript.Echo "Connection has been broken."
End If

 

JScript

// First we need to create the RMCLinkServer COM object.
var srv = new ActiveXObject("RMCLink.RMCLinkServer");
 
// Use our RMCLinkServer to create the correct type of RMCLink object.
// NOTE: JScript does not support enumerations, so we use the literal value (dtRMC70=2).
var rmc = srv.CreateEthernetLink(2, "192.168.0.22");
 
// Establish the connection.
rmc.Connect();
 
// Do some long task...
// Check to see if the link is still connected. Again we use the literal value
// for the enumeration (ptPing=1).
var isConn = rmc.IsConnected(1);
if ( isConn )
{
    WScript.echo("Connection is still made.");
 
    // Use the connection...
 
    // Close the connection.
    rmc.Disconnect();
}
else
{
    WScript.echo("Connection has been broken.");
}

 

See Also

RMCLink Class | RMCLink COM Component


Send comments on this topic.

Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion