RMCLink COM Component

RMCLink Class

Use an instance of this class to link to RMC controllers to allow reading information from the controller and writing data to the controller.

An RMCLink object must be created using the CreateEthernetLink, CreateSerialLink, or CreateUSBLink methods of the RMCLinkServer object, as shown in the Example section below.

Methods

CancelRequest

This method can be used in multi-threaded applications to cancel the currently-in-progress read, write, or connect request.

Connect

Establishes a connection with a controller using the settings specified when the RMCLink instance was created (device type, port name, host name).

Disconnect

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

FRegToLReg

Converts to an integer (L) register value from an intermediate form used when reading mixed F and L registers with ReadFFile.

IsConnected

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

LRegToFReg

Converts an integer (L) register value into an intermediate form used when writing mixed F and L registers with WriteFFile.

ReadBit

Reads a single bit from an integer (L) register in the controller.

ReadBitField

Reads a bit field (range of bits) from an integer (L) register in the controller.

ReadFFile

Reads one or more floating-point (F) registers from the controller.

ReadFFile_Script

Scripting Languages Only: Reads one or more floating-point (F) registers from the controller.

ReadImage

Reads the controller image into an integer array.

ReadImageToFile

Reads the controller image and saves it in a file.

ReadLFile

Reads one or more integer (L) registers from the controller.

ReadLFile_Script

Scripting Languages Only: Reads one or more integer (L) registers from the controller.

WriteFFile

Writes to one or more floating-point (F) registers in the controller.

WriteImage

Writes the controller image from an integer array to the controller, and applies this image in the controller.

WriteImageFromFile

Writes the controller image from a file to the controller, and applies this image in the controller.

WriteLFile

Writes to one or more integer (L) registers in the controller.

Remarks

An RMCLink object is typically used through the following steps:

Notice that all of these steps need not be done in the same method in your application. Many applications will create an RMCLink instance when the application is started and use that instance for the life of the application.

Error handling

When programming communications, it is always possible for unexpected errors to occur. That is, the program can never predict when the cable may be disconnected or the remote device will be powered off. Therefore, many of RMCLink's methods can fail, particularly Connect, ReadBit, ReadBitField, ReadFFile, ReadLFile, WriteFFile, WriteLFile, ReadImage, ReadImageToFile, WriteImage, and WriteImageFromFile. When any of the RMCLink methods fail, they throw a COM exception. How COM exceptions are handled by each language varies; see the Error Handling topic for details.

Synchronous (Blocking) Methods

All RMCLink methods are synchronous, which means that they will not return until the requested action is completed or has failed (as noted above, failure will not strictly return, but instead throw an exception). Notice also that most communications methods, particularly the methods relating to reading, writing, and connecting, can take several seconds to complete, particularly if the connection is broken. If this method is called on the main thread, then the application will likely be unresponsive until the method completes. For applications where this is not acceptable, this and other synchronous methods should be called from a worker thread. To further enhance responsiveness, the CancelRequest method can be used to allow the main thread (through a Cancel button or similar) to cancel a communication in the worker thread.

Example

The following code example illustrates the basic use of the RMCLink class:

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

RMCLinkServer Class | RMCLink COM Component


Send comments on this topic.

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