Changing NI-XNET CAN Device Baud Rate During Runtime

Updated Feb 19, 2025

Environment

Driver

  • NI-XNET

The baud rate of NI-XNET session is normally specified in the NI-XNET database or programmatically set when a dynamic database is being used. In the shipping example, you will need to stop the VI to change the baud rate.
This article will explain the programming required to change the baud rate during runtime without stopping the VI which might be useful in some application.

Required Software

  • LabVIEW
  • NI-XNET

Required Hardware

  • NI-XNET CAN Device (eg. USB-8502 or NI 9862)

Notes: Baud rate can only be changed when the interface is stopped so some modification to the shipping example is required to stop and restart the interface after changing the baud rate.
  1. Open the Frame Input Stream Session.vi shipping example.
  2. Place the XNET Stop with Interface only selected after the While loop.
  3. Place the XNET Start after setting the CAN interface baud rate.
  4. Wrap the code after XNET Create Session until XNET Stop in a While loop.
You can refer to the below image as an example for a completed code.
 
Change baud rate stream example.png
This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. 
To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW 
diagram.

You should be able to change the baud rate during runtime by filling in the BaudRate numeric control and click the change baudrate boolean button.

Please note that this is only possible in LabVIEW with previous versions of XNET which are older than the 2024 Q4 release, and not using the XNET C API. In this case, to change the Baud Rate, the session must be stopped completely and started again. 

It is possible to change the baud rate with the XNET C API with the XNET 2024 Q4 release.