Write Buffer

NI-Motion VI

Write Buffer

Writes data to a previously configured buffer.

Details

Device Compatibility

DeviceCompatibility
7330
N
7340
Y
7344
Y
7350
Y
7390
N
NI SoftMotion Controller for CANopen—Accelnet
Y
NI SoftMotion Controller for CANopen—Xenus
Y
Board ID is a unique number assigned by Measurement & Automation Explorer (MAX) used to send and receive commands and data to or from a specific NI motion controller.
Buffer is the buffer to configure. Valid buffer numbers are 1 through 255 (0x01 through 0xFF).
Inp Vect indicates the source of the data for this VI. Available input vectors include immediate (0xFF), variable (0x01 through 0x78), or indirect variable (0x81 through 0xF8). Refer to Input and Return Vectors for more detailed information.
error in (no error) describes error conditions that occur before this VI runs. The default input of this cluster is no error. If an error already occurred, this VI returns the value of error in in error out. The VI runs normally only if no incoming error exists. Otherwise, the VI passes the error in value to error out. The error in cluster contains the following parameters:
status is TRUE if an error occurred before this VI was called, or FALSE if not. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code.
code is a number identifying an error or warning. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code. Use the error handler VIs to look up the meaning of this code and display the corresponding error message.
source is a string that indicates the origin of the error, if any. Typically, source is the name of the VI in which the error occurred.
Number of Points (0) is the number of 32-bit data points to read from the buffer.
Regeneration Mode (No Change) allows you to specify whether the current write is the last write for the buffered operation. This parameter is normally set to 0 (No Change), but can be set to 1 (Last Write) if you want to write fewer points to the buffer than originally indicated by Total Points in the Configure Buffer VI. This is useful when the total number of points you want to write is not known ahead of time. When all of the data in the buffer is consumed, the operation completes with a normal status, even if it completed by encountering older data.
Data is the array of data to write to the buffer.
Bd ID Out is provided for flow control. You can string together NI-Motion VIs by wiring the Bd ID Out terminal of one VI to the Board ID terminal of the next VI.
Buffer Out is provided for flow control. You can string together NI-Motion VIs by wiring the Buffer Out terminal of one VI to the Buffer terminal of the next VI.
error out contains error information. If error in indicates an error, error out contains the same error information. Otherwise, it describes the error status that this VI produces.
status is TRUE if an error occurred, or FALSE if not. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code.
code is a number identifying an error or warning. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code. Use the error handler VIs to look up the meaning of this code and display the corresponding error message.
source is a string that indicates the origin of the error, if any. Typically, source is the name of the VI in which the error occurred.

Using This VI

After a buffer has been configured for an output operation such as contouring, you must write data to the buffer before starting the operation. When all of the data fits in the buffer (Buffer Size Total Points), you need only fill the buffer one time with the appropriate data.

When using the buffer as a circular buffer (Total Points > Buffer Size), with Old Data Stop turned on, you need to write fresh data to the buffer faster than the motion controller consumes the data. After filling the buffer once, and starting the buffered operation, you can determine the number of points you can safely write to the buffer by calling the Check Buffer VI. The Backlog parameter tells you how many points you can safely write to the buffer without overwriting data that has yet to be consumed by the controller.

If you try to write new data on top of old data, which is data that has not been consumed by the controller, the write command does not execute, and the controller generates an Old Data Stop error. If you configure the buffer with Old Data Stop set to false, however, the controller does not enforce the Old Data Stop condition and you can write data freely to the buffer.

Example Uses

Basic Uses

Suppose you have a contour move of 25,107 points, and configure a buffer with Buffer Size of 1,000 points and Total Points of 25,107. You set Old Data Stop in the Configure Buffer VI to True, and use the Check Buffer and Write Buffer VIs as you write data to the buffer in small chunks while the data is consumed by the motion controller. When you write the last points to the controller, you can still set Regeneration Mode to 0 (no change) and the motion controller knows you are done writing data to the buffer because you have written 25,107 points in total. When the controller is unable to read any more because the read mark has caught up to the write mark, the controller checks Regeneration Mode, recognizes this stop is intentional because the total points written to the buffer is equal to Total Points, and completes the operation without generating an Old Data Stop error.

Advanced Uses

To write data to the buffer from an onboard variable, use an Inp Vect other than 0xFF. The variable you specify for Inp Vect indicates the starting point for the data for this VI, including Number of Points and Regeneration Mode, followed by the data to write to the buffer. To write ten data points to the buffer, you must use twelve variables.

The Read Buffer VI generates an illegal buffer operation error if you try to read data from an output buffer after the specified number of points has already been read from the buffer. The specified number of points is generally defined as the number of iterations times the size of the buffer.

The Regeneration Mode parameter allows you to gracefully complete a buffered output operation without generating an Old Data Stop error, even though the operation completes as the read mark catches up to the write mark and the operation terminates because there's no more data available for the controller to consume.

For example, assume you have a contour move of less than 16,000 points, so you configure a buffer for 1,000 points and 16,000 total points. You set the Old Data Stop parameter to True with Configure Buffer, and use the Check Buffer and Write Buffer VIs to write the points to the buffer as the data is being consumed by the motion controller. During run-time you are able to determine the exact number of points needed for the contoured operation, and you discover you only need to write x more points to the buffer instead of the originally configured 16,000. To force the controller to stop after reading those x remaining points and prevent Old Data Stop error conditions, set the Regeneration Mode parameter to 1 (Last Write) when you write the last set of points to the buffer. When the controller is unable to read any more data from the buffer because the read mark has caught up to the write mark, the controller recognizes that this is intentional because the Last Write condition was set. This means that the controller does not generate an Old Data Stop error.