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.
This method can be used in multi-threaded applications to cancel the currently-in-progress read, write, or connect request. |
|
Establishes a connection with a controller using the settings specified when the RMCLink instance was created (device type, port name, host name). |
|
Closes the connection associated with this instance, if one has been established. |
|
Converts to an integer (L) register value from an intermediate form used when reading mixed F and L registers with ReadFFile. |
|
Checks to see if the link is currently connected to a controller. |
|
Converts an integer (L) register value into an intermediate form used when writing mixed F and L registers with WriteFFile. |
|
Reads a single bit from an integer (L) register in the controller. |
|
Reads a bit field (range of bits) from an integer (L) register in the controller. |
|
Reads one or more floating-point (F) registers from the controller. |
|
Scripting Languages Only: Reads one or more floating-point (F) registers from the controller. |
|
Reads the controller image into an integer array. |
|
Reads the controller image and saves it in a file. |
|
Reads one or more integer (L) registers from the controller. |
|
Scripting Languages Only: Reads one or more integer (L) registers from the controller. |
|
Writes to one or more floating-point (F) registers in the controller. |
|
Writes the controller image from an integer array to the controller, and applies this image in the controller. |
|
Writes the controller image from a file to the controller, and applies this image in the controller. |
|
Writes to one or more integer (L) registers in the controller. |
An RMCLink object is typically used through the following steps:
Create an RMCLink instance by calling CreateEthernetLink, CreateSerialLink or CreateUSBLink on an instance of the RMCLinkServer class, which specify the types and address (serial port or host name) of the controller you want to connect to.
Connect to the controller by calling Connect.
Read from and/or write to the controller using any of the following methods: ReadBit, ReadBitField, ReadFFile, ReadLFile, WriteFFile, and WriteLFile, ReadImage, ReadImageToFile, WriteImage, WriteImageFromFile. Notice that it is not necessary to disconnect and re-connect after each call.
After you are done communicating with the controller, call the Disconnect method to free up the serial port or close the TCP/IP connection.
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.
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.
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.
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
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion