RMCLink COM Component

RMCLink.Disconnect Method

Closes the connection, if one has been established, associated with this RMCLink object.

Syntax

Visual Basic (Declaration)

Sub Disconnect ()

 

Visual Basic (Usage)

Dim instance As RMCLink

 

instance.Disconnect

Remarks

On serial connections, the serial port will be released for use by other applications. On Ethernet connection, the TCP/IP connection will be closed.

This method is synchronous, which means that it will not return until the link is disconnected. However, disconnecting generally takes only a fraction of a second.

WARNING: For Ethernet connections, it is highly recommended that the connection not be disconnected and re-connected between transactions. Doing so will have lower performance, and more importantly, each call to Connect() will consume a TCP connection in the Windows operating system. This TCP connection will not be fully released by the operating system until typically 2 minutes after Disconnect() is called. Therefore, it is possible to consume all available TCP connections by repeated calls to Connect()/Disconnect() and as a result be unable to re-connect over RMCLink or even adversely affect other applications running on the same PC.

Exceptions

Error Code

Description

rmcEAlreadyDisconnected = 1007

The link was already disconnected. To avoid this error, avoid calling Disconnect when the link is already disconnected. Use IsConnected if you are not sure if the link is connected or not.

Example

The following code example illustrates the use of the Disconnect 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
 
    ' Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
    Dim data As Variant
    data = rmc.ReadFFile(fn70StatusAxis0, 8, 2)
    resultText = "Actual Position = " & data(0) & ", Actual Velocity = " & data(1)
 
    ' Close the connection.
    rmc.Disconnect
End Sub

 

VBScript

Option Explicit
Dim srv, rmc, data
 
' 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
 
' Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
data = rmc.ReadFFile_Script(8,8,2)
WScript.Echo "Actual Position = " & data(0) & ", Actual Velocity = " & data(1)
 
' Close the connection.
rmc.Disconnect
                

 

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();
 
// Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
var data = rmc.ReadFFile_Script(8,8,2).toArray();
WScript.echo("Actual Position = " + data[0] + ", Actual Velocity = " + data[1]);
 
// Close the connection.
rmc.Disconnect();
                

 

See Also

RMCLink Class | RMCLink COM Component


Send comments on this topic.

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