NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling and using Shared Library from Labview Programm

Hello!

Iam using the sbRIO-9627 with Real Time Linux.

I want to access external code i have written in Matlab on this embedded System within the Labview RT Software iam running on it.

I have to admit that i am a newbie concerning compiling C programms and integrating .dll/ .so into labview. On a Windows host i successfully managed to include the Matlab code using a dll file.

But i need to run the Matlab code on the RT Target.

Could anybody please explain how to compile C code (which i got from using the Matlab coder) and wrap it to a .so File and furthermore use it within Labview code?

I have installed the Eclipse 2014 mentioned in a couple of Knowledge Base Postings and compiled a .o file from my C code. But how to get the Library from this and how to put it on the RT target (i read about using ldconfig for instance, but have no clue what to do).

Thank you very mouch!

- Elbflorace e.V. -
0 Kudos
Message 1 of 5
(4,114 Views)

This may be a silly question, but do you have access to the NI Mathscript RT Module? This supports running computation-oriented .m files on RT.

If you create a project as a "Shared Library" type of project, this will handle compiling the .c file to a .o and finally to a .so file. There are many good examples out there, this guide is specifically for NI Linux RT: http://www.ni.com/tutorial/14690/en/

Message 2 of 5
(3,760 Views)

If you are using Simulink, another option is to use following SW package:

http://sine.ni.com/nips/cds/view/p/lang/cs/nid/211815

http://www.ni.com/white-paper/31488/en/

that allows you to run the models created in Simulik and compiled by Simulink coder and Eclipse on LV linux targets.

CLA, CTA, CLED

Message 3 of 5
(3,760 Views)

Another option is the LabVIEW Control Design and Simuation Module (www.ni.com/cdsim) because it comes with a simulation model converter (shows up under the tools menu in LabVIEW) that can import .mdl and .m files and automatically generate native LabVIEW models that can run on all of the NI real-time targets. It has been tested on general control systems and also on motor and hydraulic plant models.

0 Kudos
Message 4 of 5
(3,760 Views)

Hi,

 

Here are steps that worked for me: 

Step 1: Write your MATLAB code.

Step 2: Convert your MATLAB code to C (or C++, but better to be C because the Call Library Function Node in LabVIEW only accepts C code style, otherwise you need to do something like a wrapper). You can use coder in MATLAB to do so.

Step 3: Compile it using gcc. Reading the following link: 

http://www.ni.com/tutorial/14625/en/

https://forums.ni.com/t5/Developer-Center-Resources/Tutorial-Configuring-the-Call-Library-Function-N...

Step 4: Write a LabVIEW program to call Call Library Function Node. Configure Call Library Function Node properly. Copy the shared library to a folder in your sbRIO and set the path in Call Library Function Node. The path worked for me was: /home/lvuser.

Step 5: Run the program.

Bests,

-P

0 Kudos
Message 5 of 5
(2,332 Views)