CAN Initialize.vi

NI-CAN

CAN Initialize.vi

Purpose

Initialize a task for the specified channel list.

Format

Inputs

filepath is an optional path to a CAN database file from which to import the channel (signal) configurations.

If filepath is unwired (empty), the channel configuration is obtained from MAX. The MAX CAN channels are in the MAX CAN Channels listing within Data Neighborhood.

channel list is the array of channel names to initialize as a task. Each channel name is provided in an array entry.

For more information, refer to the channel list input of CAN Init Start.vi.

interface specifies the CAN interface to use for this task.

The interface input uses a ring typedef in which value 0 selects CAN0, value 1 selects CAN1, and so on.

The default (unwired) value is MAX default, which means to use the default interface as defined in the Message/Channel configuration properties. If the default interface in MAX is All, or if filepath is wired to use a CAN database (not MAX), the interface is a required input to this VI.

The Channel API and Frame API cannot use the same CAN network interface simultaneously. If the CAN network interface is already initialized in the Frame API, this function returns an error.

The special interface values 256 and 257 refer to virtual interfaces. For more information on usage of virtual interfaces, refer to Frame to Channel Conversion.

mode specifies the I/O mode for the task. For an overview of the I/O modes, including figures, refer to the Channel API Basic Programming Model.

Input

Input channel data from received CAN messages. Use CAN Read.vi to obtain input samples as single-point, array, or waveform.

Use this input mode to read waveforms of timed samples, such as for comparison with NI-DAQ waveforms. You also can use this input mode to read a single point from the most recent message, such as for control or simulation.

For this mode, the channels in channel list can be contained in multiple messages.

Output

Output channel data to CAN messages for transmit. Use CAN Write.vi to write output samples as single point, array, or waveform. Each sample value that you write is transmitted in a message on the network. If you write an array or waveform, the samples are buffered for subsequent transmit.

For this mode, there are restrictions on using channels in channel list that are contained in multiple messages. Refer to CAN Write.vi for more information.

Output Recent

Output channel data to CAN messages for transmit. This mode is used with sample rate greater than zero (periodic transmit). Use CAN Write.vi to provide a single sample per channel. Each periodic message uses the sample values from the most recent CAN Write.vi.

For this mode, there are restrictions on using channels in channel list that are contained in multiple messages. Refer to CAN Read.vi for more information.

Timestamped Input

Input channel data from received CAN messages. Use CAN Read.vi to obtain input samples as an array of sample/timestamp pairs (Poly VI types ending in Timestamped Dbl).

Use this input mode to read samples with timestamps that indicate when each message is received from the network.

For this mode, the channels in channel list must be contained in a single message.

sample rate specifies the timing to use for samples of the task. The sample rate is specified in Hertz (samples per second). A sample rate of zero means to sample immediately.

For mode of Input, sample rate of zero means that CAN Read returns a single point from the most recent message received, and greater than zero means that CAN Read returns samples timed at the specified rate.

For mode of Output, sample rate of zero means that CAN messages transmit immediately when CAN Write is called, and greater than zero means that CAN messages are transmitted periodically at the specified rate.

For mode of Output Recent, sample rate must be greater than zero (periodic transmit).

For mode of Timestamped Input, sample rate is ignored.

When the interface specifies a virtual interface (256 or 257), and mode is Output or Output Recent, this sample rate must be zero (greater than zero not supported).

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

Use task reference out with all subsequent VIs to reference the task. Wire this task reference to CAN Start.vi before you read or write samples for the message.
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.

Description

The CAN Initialize VI does not start communication. This enables you to use CAN Set Property.vi to change the properties of the task, or CAN Connect Terminals.vi to synchronize CAN or DAQ cards. After you change properties or connections, use CAN Start.vi to start communication for the task.