Visual Basic for Windows
u8 Data Type Not Supported
Because Visual Basic does not support the u8 data type, all the NI-Motion functions that take parameters that are of type u8 can be passed integers (%). The NI-Motion DLL ignores the upper byte of the integer passed.
For example, the Enable Axis function, which has the data type for boardID and PIDrate as u8, can be called as shown in the following example.
Example
Dim status as long
Dim boardID as integer
Dim PIDrate as integer
Dim
axisMap as integer
boardID = 1 The board identification number
PIDrate =
NIMC_PID_RATE_250 250 microsecond update rate
axisMap = &H1E Enable
axes 1 through 4
status = flex_enable_axes (boardID, 0, PIDrate, axisMap)
Data Returned by Reference
The NI-Motion functions that return data do so in variables passed into the function by reference.
Example
Dim status as long
Dim boardID as integer
Dim position as long
Dim
axis as integer
boardID = 1
axis = NIMC_AXIS1
status = flex_read_pos_rtn
(boardID, axis, position)
The position for axis one is returned in the position variable.
Data Returned in Arrays
While passing an array to a NI-Motion function in Visual Basic, you need to pass the first element of the array by reference.
Example
You would pass in returnData& (0) as the parameter, where returnData (0 to MAX) is an array of MAX longs.
Dim status as longDim boardID as integer
Const MAX = 12
Dim returnData (0 to MAX) as long
boardID = 1
status = flex_read_trajectory_data_rtn(boardID, returnData&(0))
Trajectory data is returned in the returnData array and can be accessed by incrementing through the array.
User-Defined Data Types
Two user-defined data types are used by the NI-Motion functions under Visual Basic—the registry information data type registryRecord, and the PID parameters data type PIDVals.
The registry information data type registryRecord is used by the Read Object Registry function to get the information about the object registry on the NI motion controller. Refer to Onboard Programming Functions for more information about the object registry.
Type registryRecorddevice As IntegerThe object number
type As IntegerThe type of object
pStart As LongThe address where the object is stored
size As LongSize of the object
End Type
The PID parameters data type PIDVals is used by the Load All PID Parameters function to load the PID and PIVFF parameters for an axis. Refer to Axis & Resource Configuration Functions for more information about PID and PIVFF parameters.
Type PIDValskp As IntegerProportional Gain
ki As IntegerIntegral Gain
ilim As IntegerIntegration Limit
kd As IntegerDerivative Gain
td As IntegerDerivative Sample Period
kv As IntegerVelocity Gain
aff As IntegerAcceleration Feedforward
vff As IntegerVelocity Feedforward
End Type
Example
While using user-defined data types, pass the data types by reference to the function.
Dim boardID as integerDim axis as integer
Dim pidvalues As PIDVals
Dim inputVector as integer
pidvalues.kp = 100
pidvalues.ki = 0
pidvalues.ilim = 1000
pidvalues.kd = 1000
pidvalues.td = 2
pidvalues.kv = 0
pidvalues.aff = 0
pidvalues.vff = 0
boardID =1
axis = NIMC_AXIS1
inputVector = &HFF
status = flex_load_loop_params(boardID, axis, pidvalues, inputVector)