RMCLink Class |
This class is used to communicate with RMC controllers both by reading information from the controller and writing data to the controller. Notice that there are no public constructors, and that instead the static CreateEthernetLink and CreateSerialLink methods are used to create RMCLink instances.
Public Static Methods
Creates an RMCLink object for communicating with a controller (RMC70, RMC150, RMC200, RMC100) over Ethernet. |
|
Creates an RMCLink object for communicating with a controller (RMC70, RMC100) over a serial port. |
|
Creates an RMCLink object for communicating with a controller (RMC70, RMC150, RMC200) over a USB port. |
|
Converts to an integer (L) register value from an intermediate form used when reading mixed F and L registers with ReadFFile. |
|
Converts an integer (L) register value into an intermediate form used when writing mixed F and L registers with WriteFFile. |
Public Instance Methods
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. |
|
Releases the unmanaged resources used by the RMCLink object. |
|
Checks to see if the link is currently connected to a controller. |
|
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. |
|
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. |
|
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. |
This type is safe for multithreaded operations.
An RMCLink object is typically used through the following steps:
Create an RMCLink instance by calling one of the static CreateEthernetLink, CreateSerialLink or CreateUSBLink methods, which specify the types and address (serial port or host name) of the controller you want to connect to. Notice that the new operator is not used for creating RMCLink instances.
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, 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 .NET exceptions. Each method's help topic lists the exceptions that can be thrown by the method and the circumstances that can cause each exception.
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 |
Imports RMCLinkNET Module Example Sub Main() ' Create the object itself. Dim rmc As RMCLink = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1") ' Connect to the controller. rmc.Connect() ' Read and display Axis 0's Actual Position (F8:8). Dim data() As Single = New Single(0) {} rmc.ReadFFile(FileNumber70.fn70StatusAxis0,8,data,0,1) Console.WriteLine("Axis0 Actual Position = " & data(0) & " inches") ' Disconnect from the controller. rmc.Disconnect() End Sub End Module |
C# |
using System; using RMCLinkNET; namespace Example { public class Program { static void Main() { // Create the object itself. RMCLink rmc = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1"); // Connect to the controller. rmc.Connect(); // Read and display Axis 0's Actual Position. float[] data = new float[1]; rmc.ReadFFile(FileNumber70.fn70StatusAxis0,8,data,0,1); Console.WriteLine("Axis0 Actual Position = " + data[0] + " inches"); // Disconnect from the controller. rmc.Disconnect(); } } } |
Visual C++/CLI |
using namespace System; using namespace RMCLinkNET; int main() { // Create the object itself. RMCLink^ rmc = RMCLink::CreateSerialLink(DeviceType::RMC70, "COM1"); // Connect to the controller. rmc->Connect(); // Read and display Axis 0's Actual Position. array<float>^ data = gcnew array<float>(1); rmc->ReadFFile(FileNumber70::fn70StatusAxis0,8,data,0,1); Console::WriteLine("Axis0 Actual Position = " + data[0] + " inches"); // Disconnect from the controller. rmc->Disconnect(); return 0; } |
Requirements
Namespace: RMCLinkNET
Assembly: RMCLink.Interop (in RMCLink.Interop.dll)
See Also
RMCLink.Interop .NET Assembly | RMCLinkNET Namespace
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion