RMCLink C++ Wrapper Class

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

Instances of this class are created using the CRMCLink::CreateEthernetLink, CRMCLink::CreateSerialLink and CRMCLink::CreateUSBLink static methods.

Public Static Methods

CreateEthernetLink

Creates an instance of the CRMCLink class for communicating with a controller (RMC70, RMC150, RMC200, or RMC100) over Ethernet.

CreateSerialLink

Creates an instance of the CRMCLink class for communicating with a controller (either RMC70 or RMC100) over a serial port.

CreateUSBLink

Creates an instance of the CRMCLink class for communicating with a controller (either RMC70, RMC150, or 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.

MakeRMCAddr

Creates an integer (L) register value that corresponds to a reference to another file:element register.

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 CRMCLink instance was created (device type, port name, host name).

Disconnect

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

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.

Public Enumeration Types

enumCONSTANTS70

Miscellaneous constants for use when communicating with the RMC70. These are typically used when computing file, element, or count parameters in read or write methods.

enumCONSTANTS150

Miscellaneous constants for use when communicating with the RMC150. These are typically used when computing file, element, or count parameters in read or write methods.

enumCONSTANTS200

Miscellaneous constants for use when communicating with the RMC200. These are typically used when computing file, element, or count parameters in read or write methods.

enumCONSTANTS100

Miscellaneous constants for use when communicating with the RMC100. These are typically used when computing file, element, or count parameters in read or write methods.

enumDEVICETYPE

Constants used by CreateEthernetLink, CreateSerialLink and CreateUSBLink to select which type of controller will be connected to the link.

enumFILENUMBER70

File numbers used when communicating with the RMC70. These are often used as the file parameter in read and write methods.

enumFILENUMBER150

File numbers used when communicating with the RMC150. These are often used as the file parameter in read and write methods.

enumFILENUMBER200

File numbers used when communicating with the RMC200. These are often used as the file parameter in read and write methods.

enumFILENUMBER100

File numbers used when communicating with the RMC100. These are often used as the file parameter in read and write methods.

enumRMCLINKERRORS

Error values returned by many of the RMCLink methods.

Remarks

A CRMCLink 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 a CRMCLink 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 CRMCLink's methods can fail, particularly Connect, ReadLFile, ReadFFile, ReadBit, ReadBitField, WriteLFile, WriteFFile, ReadImage, ReadImageToFile, WriteImage, and WriteImageFromFile. When any of the CRMCLink methods fail, they return an HRESULT value other than S_OK. See the Error Handling topic for details on handling these errors.

Synchronous (Blocking) Methods

All CRMCLink 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 CRMCLink class:

C++

#include <windows.h>
#include <stdio.h>
#include "RMCLink.h"
 
void main()
{
    // In order to create COM objects, we must initialize the COM sub-system.
    ::CoInitialize(0);
 
    // Create a new RMCLink object.
    CRMCLink* pRMC = CRMCLink::CreateEthernetLink(CRMCLink::dtRMC70, _T("192.168.0.22"));
    if ( pRMC != NULL )
    {
        // Establish the connection.
        HRESULT hr = pRMC->Connect();
        if ( SUCCEEDED(hr) )
        {
            // Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
            float afData[2];
            hr = pRMC->ReadFFile(CRMCLink::fn70StatusAxis0, 8, 2, afData);
            if ( SUCCEEDED(hr) )
            {
                printf("Actual Position = %.3f, Actual Velocity = %.3f\n",
                    afData[0], afData[1]);
            }
 
            // Close the connection.
            pRMC->Disconnect();
        }
 
        // Free the RMCLink object we created.
        delete pRMC;
    }
    // Release the COM sub-system.
    ::CoUninitialize();
}

 

See Also

RMCLink C++ Wrapper Class


Send comments on this topic.

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