RMCLink.Interop .NET Assembly

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

CreateEthernetLink

Creates an RMCLink object for communicating with a controller (RMC70, RMC150, RMC200, RMC100) over Ethernet.

CreateSerialLink

Creates an RMCLink object for communicating with a controller (RMC70, RMC100) over a serial port.

CreateUSBLink

Creates an RMCLink object for communicating with a controller (RMC70, RMC150, RMC200) over a USB port.

FRegToLReg

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

LRegToFReg

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

Public Instance 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.

Dispose

Releases the unmanaged resources used by the RMCLink object.

IsConnected

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

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.

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.

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.

Thread Safety

This type is safe for multithreaded operations.

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 .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.

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

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


Send comments on this topic.

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