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
Creates an instance of the CRMCLink class for communicating with a controller (RMC70, RMC150, RMC200, or RMC100) over Ethernet. |
|
Creates an instance of the CRMCLink class for communicating with a controller (either RMC70 or RMC100) over a serial port. |
|
Creates an instance of the CRMCLink class for communicating with a controller (either RMC70, RMC150, or 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. |
|
Creates an integer (L) register value that corresponds to a reference to another file:element register. |
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 CRMCLink instance was created (device type, port name, host name). |
|
Closes the connection associated with this instance, if one has been established. |
|
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. |
Public Enumeration Types
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. |
|
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. |
|
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. |
|
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. |
|
Constants used by CreateEthernetLink, CreateSerialLink and CreateUSBLink to select which type of controller will be connected to the link. |
|
File numbers used when communicating with the RMC70. These are often used as the file parameter in read and write methods. |
|
File numbers used when communicating with the RMC150. These are often used as the file parameter in read and write methods. |
|
File numbers used when communicating with the RMC200. These are often used as the file parameter in read and write methods. |
|
File numbers used when communicating with the RMC100. These are often used as the file parameter in read and write methods. |
|
Error values returned by many of the RMCLink methods. |
A CRMCLink object is typically used through the following steps:
Create a CRMCLink instance by calling one of the CreateEthernetLink, CreateSerialLink, or CreateUSBLink static methods, which specify the type and address (serial port, host name, or device ID) 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: ReadLFile, ReadFFile, ReadBit, ReadBitField, WriteLFile, WriteFFile, ReadImage, ReadImageToFile, WriteImage, and 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 a CRMCLink 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 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.
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.
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
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion