CAN Write.vi

NI-CAN

CAN Write.vi

Purpose

Write samples to a CAN task initialized as Output (refer to the mode parameter of CAN Init Start.vi). Samples are placed into transmitted CAN messages. The poly VI selection determines the data type to write.

To select the data type, right-click the VI, go to Select Type, and select the type by name.

For LabVIEW 7.0 and later, you can right-click the VI and select Visible Items»Poly VI Selector to select the data type from within the diagram.

For an overview of CAN Write, refer to the Write section of Using the Channel API.

Format

Inputs

task reference in is the task reference from the previous NI-CAN VI. The task reference is originally returned from CAN Init Start.vi, CAN Initialize.vi, or CAN Create Message.vi, and then wired through subsequent VIs.

The mode initialized for the task must be Output.

number of samples to write specifies the number of samples to write for the task. For single-sample Poly VI types, CAN Write always accepts one sample, so this input is ignored.

The poly input samples specifies the samples to transmit in CAN messages. The poly input type is determined by the Poly VI selection. For information on the different poly VI types provided by CAN Write, refer to the Poly VI Types section.

To select the data type, right-click the VI, go to Select Type, and select the type by name.

Error in describes error conditions occurring before the VI executes. If an error has already occurred, the VI returns the value of the Error in cluster in Error out.
status is True if an error occurred. If status is True, the VI does not perform any operations.
code is the error code number identifying an error. A value of 0 means success. A negative value means error: VI did not execute the intended operation. A positive value means warning: VI executed intended operation, but an informational warning is returned. For a description of the code, wire the error cluster to a LabVIEW error-handling VI, such as the Simple Error Handler.
source identifies the VI where the error occurred.

Outputs

task reference out is the same as task reference in. Wire the task reference to subsequent VIs for this task.
Error out describes error conditions. If the Error in cluster indicated an error, the Error out cluster contains the same information. Otherwise, Error out describes the error status of this VI.
status is True if an error occurred.
code is the error code number identifying an error. A value of 0 means success. A negative value means error: VI did not execute the intended operation. A positive value means warning: VI executed intended operation, but an informational warning is returned. For a description of the code, wire the error cluster to a LabVIEW error-handling VI, such as the Simple Error Handler.
source identifies the VI where the error occurred.

Poly VI Types

The name of each Poly VI type uses the following conventions:

  • The first term is either Single-Chan or Multi-Chan. This indicates whether the type specifies data for a single channel or multiple channels. Multi-Chan types specify an array of analogous Single-Chan types, one entry for each channel initialized in channel list of CAN Init Start. Single-Chan types are convenient because no array indexing is required, but you are limited to writing only one CAN channel.
  • The second term is either Single-Samp or Multi-Samp. This indicates whether the type specifies a single sample, or an array of multiple samples. Single-Samp types are often used for single-point control applications, such as within LabVIEW RT. Single-Samp types are required for the Output Recent mode.
  • The third term indicates the data type used for each sample. The word Dbl indicates double-precision (64-bit) floating point. The word Wfm indicates the waveform data type. The words 1D and 2D indicate one and two-dimensional arrays, respectively.

Single-Chan Single-Samp Dbl

Writes a single sample for the first channel initialized in channel list.

You can use this type with Output mode or Output Recent mode.

If the initialized sample rate is greater than zero, the task transmits a CAN message periodically at the specified rate. The first CAN Write transmits a message immediately, and then begins a periodic timer at the specified rate. In Output mode, samples are queued and each subsequent message transmission uses the next available sample. When there are no more samples, the last sample is retransmitted until a new sample is provided or the task is stopped. In Output Recent mode, only the last provided sample is transmitted periodically, based on the timer.

If the initialized sample rate is zero, the message is transmitted immediately each time you call CAN Write.

Because all channels of a message are transmitted on the network as a unit, CAN Write enforces the following rules:

  • You cannot write the same message in more than one Output task.
  • You can write more than one message in a single Output task.
  • You can write a subset of channels for a message in a single Output task. For channels that are not included in the task, the Default Value is transmitted in the CAN message. Because this Poly VI writes only one channel, the Default Value will always be used for any remaining channels in the associated message.

For many applications, the most straightforward technique is to assign a single task for each message you want to transmit. In each task, include all channels of that message in the channel list. This ensures that you can provide new samples for the entire message with each CAN Write.

Multi-Chan Single-Samp 1D Dbl

Writes an array, one entry for each channel initialized in channel list. Each entry consists of a single sample.

You can use this type with Output mode or Output Recent mode.

The messages transmitted by CAN Write are determined by the associated channel list. If all channels are contained in a single message, only that message is transmitted. If a few channels are contained in one message, and the remaining channels are contained in a second message, two messages are transmitted.

If the initialized sample rate is greater than zero, the task transmits associated CAN messages periodically at the specified rate. The first CAN Write transmits messages immediately, and then begins a periodic timer at the specified rate. In Output mode, samples are queued and each subsequent message transmission uses the next available sample. When there are no more samples, the last sample is retransmitted until a new sample is provided or the task is stopped. In Output Recent mode, only the last provided sample is transmitted periodically, based on the timer.

If the initialized sample rate is zero, the messages are transmitted immediately each time you call CAN Write.

Because all channels of a message are transmitted on the network as a unit, CAN Write enforces the following rules:

  • You cannot write the same message in more than one task.
  • You can write more than one message in a single task.
  • You can write a subset of channels for a message in a single task. For channels that are not included in the task, the Default Value is transmitted in the CAN message.

For many applications, the most straightforward technique is to assign a single task for each message that you want to transmit. In each task, include all channels of that message in the channel list. This ensures that you can provide new samples for the entire message with each CAN Write.

Single-Chan Multi-Samp 1D Dbl

Writes an array of samples for the first channel initialized in channel list.

You can use this type with Output mode only (not Output Recent mode).

If the initialized sample rate is greater than zero, the task transmits a CAN message periodically at the specified rate. This Poly VI is used to transmit a sequence of messages periodically, with a unique sample value in each message. The first CAN Write transmits a message immediately using the first sample in the array, and then begins a periodic timer at the specified rate. Each subsequent message transmission is based on the timer, and uses the next sample in the array. After the final sample in the array has been transmitted, subsequent behavior is determined by the Behavior After Final Output property. The default Behavior After Final Output is to retransmit the final sample each period until CAN Write is called again.

If the initialized sample rate is zero, a message is transmitted immediately for each entry in the array, with as little delay as possible between messages. After the message for the final sample is transmitted, no further transmissions occur until CAN Write is called again, regardless of the Behavior After Final Output property.

Because all channels of a message are transmitted on the network as a unit, CAN Write enforces the following rules:

  • You cannot write the same message in more than one task.
  • You can write more than one message in a single task.
  • You can write a subset of channels for a message in a single task. For channels that are not included in the task, the Default Value is transmitted in the CAN message. Because this Poly VI writes only one channel, the Default Value will always be used for any remaining channels in the associated message.

For many applications, the most straightforward technique is to assign a single task for each message that you want to transmit. In each task, include all channels of that message in the channel list. This ensures that you can provide new samples for the entire message with each CAN Write.

Multi-Chan Multi-Samp 2D Dbl

Writes an array, one entry for each channel initialized in channel list. Each entry consists of an array of samples.

You can use this type with Output mode only (not Output Recent mode).

The messages transmitted by CAN Write are determined by the associated channel list. If all channels are contained in a single message, only that message is transmitted. If a few channels are contained in one message, and the remaining channels are contained in a second message, two messages are transmitted.

If the initialized sample rate is greater than zero, the task transmits associated CAN messages periodically at the specified rate. This Poly VI is used to transmit a sequence of messages periodically, with unique sample values in each set of messages. The first CAN Write transmits associated messages immediately using the first sample in the array of each channel, and then begins a periodic timer at the specified rate. Each subsequent transmission of messages is based on the timer, and uses the next sample in the array of each channel. After the final sample in the array of each channel has been transmitted, subsequent behavior is determined by the Behavior After Final Output property. The default Behavior After Final Output is to retransmit the final sample each period until CAN Write is called again.

If the initialized sample rate is zero, the task transmits associated messages immediately for each entry in the array of each channel, with as little delay as possible between messages. After the message for the final sample is transmitted, no further transmissions occur until CAN Write is called again, regardless of the Behavior After Final Output property.

Because all channels of a message are transmitted on the network as a unit, CAN Write enforces the following rules:

  • You cannot write the same message in more than one task.
  • You can write more than one message in a single task.
  • You can write a subset of channels for a message in a single task. For channels that are not included in the task, the Default Value is transmitted in the CAN message.

For many applications, the most straightforward technique is to assign a single task for each message that you want to transmit. In each task, include all channels of that message in the channel list. This ensures that you can provide new samples for the entire message with each CAN Write.

Single-Chan Multi-Samp Wfm

Writes a single waveform for the first channel initialized in channel list.

The start time and delta time of the waveform does not affect the beginning of message transmission. Therefore, this Poly VI type is equivalent to the Single-Chan Multi-Samp 1D Dbl Poly VI type.

Multi-Chan Multi-Samp 1D Wfm

Writes an array, one entry for each channel initialized in channel list. Each entry consists of a single waveform.

The start time and delta time of each waveform does not affect the beginning of message transmission. Therefore, this Poly VI type is equivalent to the Multi-Chan Multi-Samp 2D Dbl Poly VI type.