Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Latest commit

 

History

History
56 lines (40 loc) · 4.44 KB

README.md

File metadata and controls

56 lines (40 loc) · 4.44 KB

Rust - LabVIEW Integration Examples

This repo demonstrates Rust-LabVIEW integration with a basic example and a more advanced use case.

NI.com describes LabVIEW as "systems engineering software for applications that require test, measurement, and control with rapid access to hardware and data insights". From This Week in Rust, "Rust is a systems language pursuing the trifecta: safety, concurrency, and speed".

Combining Rust with LabVIEW's automated test and measurement systems can help demonstrate the benefits of Rust to the scientific and engineering community.

These examples were written with:

  • Rust 1.42.0
  • LabVIEW 2019
  • LabVIEW NXG 4.0
  • NI-DAQmx 19.0

Interoperability Overview

In 2015, the Rust team published a Rust Once, Rust Everywhere article. A few snippets are particularly interesting:

To communicate with other languages, Rust provides a foreign function interface (FFI). Following Rust's design principles, the FFI provides a zero-cost abstraction where function calls between Rust and C have identical performance to C function calls."

Despite guaranteeing memory safety, Rust does not have a garbage collector or runtime, and one of the benefits of this is that Rust code can be called from C with no setup at all."

If Rust plays nice with C, then we can integrate it smoothely into LabVIEW. The Call Library Funcion Node allows LabVIEW 20XX to directly call external libraries. Similarly, LabVIEW NXG uses the Shared Library Interface to interact with external code.

The Rust-perspective on interacting with foreign code is well documented in the manual and the Rust Omnibus. Basically, you can use the libc crate to build dynamically linked libraries that interoperate with C code.

Getting Started Example

Using the Rust Omnibus Integers approach, rust-labview-basic demonstrates a simple incrementing function written in Rust and then consumed by a LabVIEW VI (.vi) and a LabVIEW NXG VI (.gvi).

More Advanced Example

It is relatively common for teams with shared measurement systems to specify configuration files that define how to acquire data. In this example, a team uses YAML to define their analog input measurements. For example:

cDAQ_configurations:
  - configuration_name: medium_voltage
    hardware_channels: cDAQ1Mod1/ai0:3
    min_voltage: -5
    max_voltage: 5
    sample_rate_Hz: 100

After looking through the NI Tools Network, I could not find any pre-existing libraries for parsing YAML. Fortunately there is a yaml-rust crate.

Using the Rust Omnibus Objects approach, rust-labview-yaml handles the YAML parsing so the corresponding LabVIEW and LabVIEW NXG systems can correctly configure the analog input measurement hardware.

To use the examples in the lv2019 and NXG directories, simulate the following CompactDAQ hardware in NI MAX:

  • NI cDAQ-9189 "cDAQ1"
  • NI 9201 "cDAQ1Mod1"
  • NI 9205 "cDAQ1Mod2"
  • NI 9206 "cDAQ1Mod3"

Additional ideas

With the Rust trifecta and LabVIEW's domain expertise, there are a lot of project opportunities. Here are a few ideas:

  • Rust program using the FPGA C API running on a Linux Real-Time target
  • Highly parallelized data file publishing service
  • LabVIEW NXG UI for prototyping Rust signal analysis libraries
  • Rust-built server managing distributed measurement systems (nodes programmed with LabVIEW Real-Time and LabVIEW FPGA)