From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

NI-985x Write and Read on One CAN Port

Code and Documents

Attachment

Overview


This example demonstrates basic communication on the CAN bus. The example runs standalone (without a host VI).

It reads CAN frames on CAN 0 and displays a count along with the most recent frame. It transmits a CAN frame on CAN 0 with the delay specified in WAIT (uSec). To use the example you will need an external CAN device (such as an ECU). Connect the device to CAN 0. This enables you to interactively transmit and receive CAN frames with the external device. In this example, the CAN port is not enabled for self-reception of frames, so you will not see the messages transmitted in the Recent Receive indicator. The external CAN device will receive the messages.

This example assumes the following configuration for CAN 0: Auto Start = True, Listen Only = False, Input Timeout = 10000ms, Output Timeout = 10000ms. The CAN Input and CAN Output nodes are configured to use Cluster for the CAN frame. For more information on configuration, refer to the Help for the NI 9853 CAN module.

If you change this example such that the loops exit normally (such as a stop button), you must add the CAN Stop method to stop CAN communication before the VI stops execution. Only the LabVIEW abort button stops CAN communication when running standalone (no host VI).

Note: Prior to running the VI, you will need to specify the VISA resource name for the FPGA target. You can specify the VISA resource name by right clicking the FPGA Target in the Project Explorer, then selecting Properties... and then specifying the VISA resource string.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors