LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LabVIEW to call MATLAB-generated .so on cRIO-9040 (Linux RT)

 

Hello NI community,

I’m working with a cRIO-9040 running NI Linux Real-Time. Following the steps in the links below, I generated a shared library (.so) from a simple MATLAB script and uploaded it to the cRIO via PowerShell. In LabVIEW, I’m calling it through the Import Shared Library Wizard, but the VI hangs at run time and the cRIO then disconnects. After that, I have to reformat the controller before LabVIEW can connect again.


1. Environment

  • Hardware: cRIO-9040

  • OS: NI Linux Real-Time

  • LabVIEW version: 2023 Q3

  • Matlab version: R2023b
  • cRIO software: Linux RT System Image 2023 Q1

2. MATLAB to .so

As described here:

Convert LabVIEW MATLAB Functions to Shared Objects on Linux Real Time Targets With Intel x64 Archite...

and

Use LabVIEW to Call .so File in NI Linux Rt Target - NI

 

My MATLAB function is:

TCNI_0-1751986100026.png

 

I want A, x, and y all to be double 1D arrays.

The generated untitled.h is attached below.

 

3. Upload to cRIO

 

powershell
scp "C:\path\to\untitled.so" ` admin@IP:/home/lvuser/untitled.so

 

On the cRIO I verified that the file is at the desired place

 

ls -l /home/lvuser/untitled.so

4. Import Shared Library Wizard settings in LabVIEW

gave me 

TCNI_3-1751986569023.png

so I imported (I am very unsure which header files I am looking for, but I found these in the matlab and CVI2020 folders)

TCNI_2-1751986467020.png

In the next step I defined my parameters as Arrays as shown:

TCNI_5-1751986960717.png

After generating the VI I get the following report that I can't quite make sense of.

TCNI_6-1751987515263.png

6. Question

Can anyone do more with the report or already see errors in my execution of the previous steps?

Could the reason be that labview cannot do anything with the parameter types emxArrays? if so, how do I change this?

Thank you in advance for any advice!


Best regards,

TCNI

0 Kudos
Message 1 of 2
(229 Views)

Those arrays are Matlab managed arrays as you can see in your last image. They are really pointers to a structure that contains the array data pointer, and additional management information. You can't just treat them like C array pointers and neither as LabVIEW arrays. Your Matlab .so should also export functions to manage these arrays, creating them, accessing their information and deallocating them. It's a long time that I looked at it and most likely there are differences between your Matlab Coder version and what was used in the Knowledge article.

 

What they suggest in there that you can just call it with C arrays as parameters was not possible at the time I looked at it without writing your own wrapper C code that translated the C parameters to Matlap Mex arrays through the additionally exported helper functions.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 2
(211 Views)