Shutting Down NI Linux Real-Time Devices Programmatically

Updated Nov 29, 2023

Environment

Hardware

  • CompactRIO Controller
  • PXI Controller

Operating System

  • LabVIEW Real-Time (NI Linux Real-Time)

The following tutorial provides 2 alternatives to shut down NI Linux Real-Time (RT) targets programmatically from LabVIEW. 

System Exec VI

The System Exec VI can be used within LabVIEW to call the Linux shutdown command to power off the system. However, by default LabVIEW doesn't have permission to run this command so shutdown permission must first be granted to LabVIEW by adding lvuser, to the Linux usergroup called shutdown

The following steps grant LabVIEW shutdown permissions and demonstrate the LabVIEW code to power the system off:
  1. Open an SSH session (i.e. using PuTTY ) with the RT target.
  2. Run the following command: usermod -a -G shutdown lvuser
  3. Make sure the permission for the shutdown command was properly added to the lvuser by running the groups lvuser command.
verify.png
  1. Reboot the target to apply changes.
  2. Run the shutdown command from the LabVIEW VI.
LV code.png
In this case, the -r parameter was used to reboot after shutting down, and now to shutdown immediately. If you need to remove the lvuser from the shutdown group later, follow these steps:
  1. Run the following command: gpasswd -d lvuser shutdown.
  2. Reboot the target to apply changes.
  3. Make sure the permission for the shutdown command was properly removed from the lvuser by running the groups lvuser command.

verify2.png

Call Library Function

You can use the Call Library Function node to call into a standard installed library glibc on your Linux Real-Time device. Libc.so.6 is a standard Linux library utility and exists on generic Linux systems. The lvuser by default has the priorities enabled to be able to run this. 

There are two ways to reference this library:
  • Note that "libc.so.6" is the soname of the library and it is possible to use libc.so.6 as the path element to the Call Library Function node to load the library without needing to specify the full path. This maintains compatibility across future glibc versions.
  • Alternatively, you can choose to call a specific libc.X.XX.so by a specific filepath.
An example VI of how to structure your shutdown VI is attached and will look like the following:
LabVIEW_4ioRApFY7U.png
  • This is calling into the function name "reboot" with a "cmd" I32 parameter.
  • The command 4321FEDC is to shutdown the device.

If you are using a full filepath, you can check the libc-x.xx.so file that is on your device, by accessing files > lib (ARM) or lib64 (Intel)libc-x.xx.so as shown below. 
To see how to access files on your device, refer to: Using WebDAV to Transfer Files to Real-Time Target

Additional Information

Because of the flash-based hardware on NI Linux Real-Time devices, it is highly recommended to shut down the device before loss of battery power. You can refer to Under the Hood of NI Linux Real-Time for more information on how to access the Linux Real-Time command line via LabVIEW.

If you wish to shut the Linux Real-Time target remotely but not programmatically, it is also possible to do this manually through SSH.