nimcReadEncoderData

NI-Motion Functions

nimcReadEncoderData

Device Compatibility

Device Compatibility
7330
N
7340
N
7344
N
7350
Y
7390
Y
NI SoftMotion Controller for CANopen—Xenus
N
NI SoftMotion Controller for CANopen—Accelnet
N

Read Encoder Data

Usage

status = nimcReadEncoderData(TnimcDeviceHandle deviceHandle, TnimcAxisHandle axisHandle, i32 index TnimcEncoderData attribute, TnimcData* data);

Purpose

Reads status and data from the selected encoder.

Parameters

Name Type Description
deviceHandle TnimcDeviceHandle assigned by Measurement & Automation Explorer (MAX)
axisHandle TnimcAxisHandle axis to read encoder information from
index i32 encoder index
attribute TnimcEncoderData attribute to read
data TnimcData* the value for the attribute you are reading

Parameter Discussion

axisHandle is the axis to read with this function. Valid values are 1 through 30. On motion controllers that support fewer than thirty axes, reading non-existent axes returns error –70006 (NIMC_badResourceIDOrAxisError).

index is the encoder index value. Valid value is 1 for the primary encoder.

attribute is the attribute to read. The following are valid attributes:

  • TnimcEncoderDataPosition
  • TnimcEncoderDataIndexPosition
  • TnimcEncoderDataIndexCaptureOccurred

data is the value for the attribute you are reading in the following structure:

struct{
   i32 longData;
   u8 boolData;
   f64 doubleData;
} TnimcData;

Based on the attribute, the correct member of TnimcData will be returned by the motion controller. The values of the other elements in the structure are undefined.

Read doubleData in the TnimcData structure to retrieve the encoder position or encoder index position.

Using This Function

Use this function to read status and data from the selected encoder.

Caution  If this function uses reflective memory, it should not be used for event checking. In this case, only use the information returned by this function for display purposes. Refer to Reflective Memory Functions for more information.

For encoder position, this function returns the quadrature count value of the encoder mapped to the selected axis.

For encoder index position, this function returns the captured index position after a Find Index search.

Read boolData in the TnimcData structure to retrieve the encoder index capture status. A value of TnimcTrue indicates that the encoder index position capture occurred. A value of TnimcFalse indicates that the encoder index position was not captured.

Note  Refer to Function Execution Times for benchmark timing information about your controller.