RMCLink C++ Wrapper Class

CRMCLink::CreateSerialLink Method

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

Syntax

C++

static CRMCLink* CreateSerialLink(

   enumDEVICETYPE devType,

   LPCTSTR portName

);

Parameters

devType

Specifies which type of RMC will be linked to. It must be either dtRMC70 or dtRMC100.

portName

Specifies the serial port to use for communicating with the device. Typical names include "COM1" and "COM2".

Return Value

On success, a pointer to a newly allocated CRMCLink object  is returned. On failure, NULL is returned.

Remarks

Notice that this method does not in any way try to connect to the controller. This method simply creates the CRMCLink object. To connect to the device, you will need to call the CRMCLink::Connect instance method.  This method will support any com port on the PC.

Because the object is only created and the connection is not made, this method returns immediately.

Free the CRMCLink class instance with the C++ delete keyword when you are done with it.

Example

The following code example illustrates the use of the CreateSerialLink method.

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::CreateSerialLink(CRMCLink::dtRMC70, _T("COM1"));
    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

CRMCLink Class | RMCLink C++ Wrapper Class | CRMCLink::enumDEVICETYPE


Send comments on this topic.

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