|
RMCLink C++ Wrapper Class CRMCLink::FRegToLReg Method |
Converts to an L register value from an intermediate form used when reading mixed F and L registers with ReadFFile.
|
C++ |
|
static long FRegToLReg( float regValue ); |
regValue
The value corresponding to an L register from the array of float data types returned by ReadFFile. Notice that this value is not usable at this stage. That is, it will appear to be a garbage value, until converted by this method.
The L register value in a usable 32-bit integer format.
This function is used when reading L registers from an RMC70, RMC150, or RMC200 using the ReadFFile method. Notice that this should only be done when the read is reading a mixture of L and F registers. Otherwise the ReadLFile method should be used to read exclusively L registers. Refer to the RMC70, RMC150 and RMC200 Register Data Types topic for details on L and F register types and on how to mix the two in a single read or write.
The following code example illustrates the use of the FRegToLReg 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::CreateEthernetLink(CRMCLink::dtRMC70, _T("192.168.0.22"));
if ( pRMC != NULL )
{
// Establish the connection.
HRESULT hr = pRMC->Connect();
if ( SUCCEEDED(hr) )
{
// Assume that the Indirect Data Map has been set up so that its
// first four registers correspond to the following:
// F18:0 = Axis 0 Status Bits (L register)
// F18:1 = Axis 0 Error Bits (L register)
// F18:2 = Axis 0 Actual Position (F register)
// F18:3 = Axis 0 Target Position (F register)
// Read up all four registers in a single read.
float afData[4];
hr = pRMC->ReadFFile(CRMCLink::fn70IndDataValues, 0, 4, afData);
if ( SUCCEEDED(hr) )
{
// At this point, alData holds all four values. However, since
// the first two were strictly L registers, they cannot be used
// directly, since afData[0] would return a bogus floating point
// value, and even (long)afData[0] would return a bogus long
// value. Therefore, we use the FRegToLReg method. Notice that
// the F register values are used normally.
printf("Status Bits = 0x%08X\n", CRMCLink::FRegToLReg(afData[0]));
printf("Error Bits = 0x%08X\n", CRMCLink::FRegToLReg(afData[1]));
printf("Actual Position = %.3f\n", afData[2]);
printf("Target Position = %.3f\n", afData[3]);
}
// 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
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion