RMCLink COM Component RMCLink.Connect Method |
Establishes a connection with a controller using the settings specified when the RMCLink object was created (device type, port name, host name).
Visual Basic (Declaration) |
Sub Connect () |
Visual Basic (Usage) |
Dim instance As RMCLink
instance.Connect |
This method is synchronous, which means that it will not return until the connection has been established, or the connection attempt fails and a COM exception is thrown, which may take several seconds to take place. 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.
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.
Error Code |
Description |
rmcEOutOfMemory = 5 |
Out of memory. |
rmcEAlreadyConnected = 1006 |
The link was already connected. To avoid this error, avoid calling Connect when the link is already connected. Use IsConnected if you are not sure if the connection is already made. |
rmcESocketInternal = 1008 |
Internal socket error. |
rmcESocketConnectionFailure = 1009 |
Unable to connect over TCP/IP to requested device. |
rmcECancelled = 1010 |
Operation cancelled by call to CancelRequest. |
rmcETimeout = 1011 |
Operation timed out. |
rmcESocketHostNameNotIPv4 = 1012 |
Host name did not resolve to an IPv4 address. |
rmcESocketHostNameNotResolved = 1013 |
Host name did not resolve. |
rmcESocketGracefullyClosed = 1014 |
TCP/IP connection closed by remote device. |
rmcESocketReadError = 1015 |
Connection error while waiting for response from the remote device. |
rmcESocketInvReadLen = 1016 |
Connection error while waiting for response from the remote device. |
rmcESocketWriteError = 1017 |
Connection error while sending request to the remote device. |
rmcESocketInvWriteLen = 1018 |
Connection error while sending request to the remote device. |
rmcEPortAccessDenied = 1019 |
Access to serial port denied. Verify not in use by another application. |
rmcEPortNotFound = 1020 |
Serial port not found. |
rmcESerialIOE = 1021 |
Serial IOE error. |
rmcESerialFramingError = 1022 |
Serial framing error. |
rmcESerialBreak = 1023 |
Serial Break error. |
rmcESerialOverrun = 1024 |
Serial overrun. |
rmcESerialRxOverrun = 1025 |
Serial receive overrun. |
rmcESerialParityError = 1026 |
Serial parity error. |
rmcESerialTxFull = 1027 |
Serial transmitter full. |
rmcEConnectionBroken = 1028 |
Connection broken. |
rmcEPartialWrite = 1029 |
Unable to send full request to the remote device. |
rmcESocketHostnameInvalid = 1033 |
Invalid host name format. |
rmcEWrongController = 1034 |
Remote device is the wrong controller type. |
rmcEUSBNoDrivers = 1049 |
Unable to access RMC USB driver. Please ensure that the driver has been properly installed. |
rmcEUSBDeviceNotFound = 1050 |
The controller with the specified DeviceId was not found on any USB port. |
rmcEUSBInternal1 = 1051 |
Internal USB driver error. |
rmcEUSBInternal2 = 1052 |
Internal USB driver error. |
rmcEUSBOperationAborted = 1053 |
Unsuccessful transfer of data between the PC and the controller. Ensure that the physical connection between the PC and controller is still intact. |
rmcEUSBDisconnected = 1054 |
The controller appears to have been disconnected from the USB port. Ensure that the physical connection between the PC and controller is still intact. |
rmcEUSBUnknownFailure = 1055 |
The requested RMC is plugged into a USB port, but cannot be accessed. Ensure that no other applications are using this RMC. If the problem persists, try unplugging and re-plugging the USB cable to this controller and retry. |
rmcEUSBInUse = 1056 |
The requested RMC is plugged into a USB port, but cannot be accessed. Ensure that no other applications are using this RMC. If the problem persists, try unplugging and re-plugging the USB cable to this controller and retry. |
rmcEUSBNoSetupAPI = 1057 |
Unable to access operating system functionality for connecting to USB devices. |
The following code example illustrates the use of the Connect 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
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion