Skip to content

Building MEL for NI Linux Real Time

Evan Pezent edited this page Feb 18, 2019 · 19 revisions

Note: This guide assumes you've already downloaded cmake, git, and cloned the MEL master repository (see Getting Started). It also assumes you have installed the appropriate device drivers and software from National Instruments (see myRIO).

Note for DAQ Users: Using MEL with National Instruments embedded devices running Linux Real-Time (LRT) is slightly different than with plug-and-play DAQs like Quanser's Q8-USB or NI's own DAQmx devices. Where as with those devices code is compiled for and run on a host PC like Windows, the code you write for NI LRT devices is actually run on the device itself. In a nutshell, code is written on a host development computer (Windows or Linux) and then compiled to a binary library or executable using NI's provided cross compiler. This binary is not executed on the host, but is instead transfered to the target NI device where finally it can be executed.

Required Setup and Installation

To build MEL for National Instruments embedded devices running real-time Linux, you will need the appropriate cross-compiler from NI and a few utility programs to aid in the deployment process. First, download the correct cross-compiler:

Host System NI LRT x64 (cRIO) NI LRT ARM (myRIO)
Windows Download Download
Linux Download Download

You will need 7-Zip or similar to extract the contents of the .tar.xz. MEL expects the compilers to be saved in C:/dev/nilrt-x64 or C:/dev/nilrt-arm, both of which should contain sysroots/, relocate_sdk.py, etc.

You will also need a CMake compatible build system for the GNU-based cross compiler, the two most popular being Ninja and Make. Make comes pre-installed on most Linux distros, so you should use it if your host system is Linux based. For Windows, the easiest solution is to use Ninja:

Ninja - Download

You can save ninja.exe wherever you like (e.g. C:/bin/), just make sure its location is added to the PATH system variable and that it can be executed from your command prompt/terminal.

Finally, you will need SFTP and SSH clients for your host platform. The SFTP client will allow you to transfer binaries and files from the host to the NI target, while the SSH client will allow you to open a terminal into the target from the host. On Windows, the two best options are WinSCP for SFTP and PuTTY for SSH:

WinSCP - Download

PuTTY - Download

Install both programs using the provided installers and default options.

Generating Build Files with CMake

Open command prompt in the root MEL folder (e.g. C:/Git/MEL/)) and run the following commands:

> mkdir build  # make new directory for our out-of-place build
> cd build     # change directory to ./MEL/build

Note: Here we have named our build folder build. We could have named this folder anything, and if you plan to build MEL for multiple devices/platforms, it's suggested you use a unique name such as build-quanser, build-myrio, etc.

Now you must choose the generator and options you wish CMake to use. Consult the Getting Started page for details. For example, if you're targeting myRIO and plan to use the Ninja generator:

> cmake .. -G "Ninja" -DNI_ARM=ON -DEXAMPLES=ON

Breaking these commands down, cmake .. calls CMake and tells it to look one directory up for CMakeLists.txt, -G "GENERATOR STRING" sets the generator, and -D[OPT]=ON turns the specified option on.

Once CMake has completed, the build folder will be populated with all of the necessary build files among other CMake specific files. Next, we move on to building MEL from the generated files.

Building

Compiling with Ninja is super simple. In the same terminal as before just call:

> ninja

or if you are using Make:

> make

The MEL library binary will be compiled to MEL/build/libMEL.so and example binaries will be compiled to MEL/build/examples/.

Transferring Binaries

Ensure your host PC and NI device are on the same local network. This can be accomplished by connecting via Ethernet, USB (emulated Ethernet) or over WiFi depending on the device. Open NI Measurement and Automation Explorer (MAX), find your device under Remote Systems, and obtain your devices IP address.

Open WinSCP and login into the device over SSH:

You should now be able to see the folders and files on the device in the right hand-side of WinSCP:

In WinSCP, go to Options > Preferences > Transfer. With Default selected, click Edit.... Under Upload options, check Set permissions: and click the ... button. Check all Read (R), Write (W), and Execute (X) boxes. The octal should change to 0777. This will ensure anything we upload to the device over WinSCP can be read, written, and executed.

Drag and drop the recently built libMEL.so from the host to /usr/local/lib. This will make it globally accessible by all MEL based programs.

Navigate to /home/[username]/ and create a folder named MEL and a sub-folder named examples, then copy over each example binary.

Note: For myRIO, you must also copy the default FPGA personality bitfile to the correct location on the device. Upload NiFpga_MyRio1900Fpga60.lvbitx to /var/local/natinst/bitfiles/.

Finally, restart the device so that libMEL.so will be loaded on boot.

Running the Examples

Open PuTTY. Enter your devices IP address and select Open. If you prompted to trust the device, select Yes.

In the PuTTY terminal, enter your device login information (e.g. admin, blank password).

Run the following commands:

> cd ~/MEL/examples # change location to MEL examples directory
> ls                # list all files located in directory
> ./hello_world     # runs MEL hello_world example, prints "Hello, World!"

Note: If you get error message ./hello_world: error while loading shared libraries: libMEL.so: cannot open shared object file: No such file or directory then you either forgot to copy over the libMEL.so binary in the previous section and/or forgot to reboot your device.

Proceed to run any other examples you wish.

Clone this wiki locally