LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing/Calling C code in labview

I use to program in C language in Microcontrollers.

Sometimes we make C code, which if we check for all the values it can take and check c code output, it takes lots of time since MCU are generally low speed.

 

What I want to do is: 

Write C function in labview, and pass all values and see output range. Can it be done.

 

Implemeting by calling labview blocks is easy that I can do. I want to know if I can copy entire C code and pass parameters into it and see. 

0 Kudos
Message 1 of 9
(2,894 Views)

What is your OS? Under windows, you can turn your text code into a dll and call it in LabVIEW.

Message 2 of 9
(2,863 Views)

wiebe@CARYA wrote:

LabVIEW NXG can do this 😋https://www.ni.com/documentation/en/labview/latest/c-prog/c-node-overview/


The Formula Node in LabVIEW is a (less extensive) variant of this. It uses C syntax, with a few notable differences, and allows to execute simple C code in it. However you do not have libraries like ANSI C or similar available and definitely not other functions (but that last one is the same for the NXG node).

 

There also was the C node but that was only available if you had the LabVIEW C Generator Toolkit installed. This Toolkit was meant to allow translating VIs into (rather convoluted C++ code) that then could be compiled with the toolchain for a specific embedded controller target. But NI discontinued that somewhere around LabVIEW 2017 as it was pretty much unsupportable.

Rolf Kalbermatter
My Blog
Message 4 of 9
(2,789 Views)
Thanks for reply. Function node solved the problem. Although i think labview c code generation was very good. & NI could make it much better. Like in newest versions of Matlab, you can generate PID code, motor code algorithms in C language and directly port to micro-controller. & many other Matlab functions to convert to c are available. Something similar could really of great help at-least for me in labview. Make a VI for specific task, convert it into C and run into MCU.
0 Kudos
Message 5 of 9
(2,748 Views)

That won't be easy.

 

LabVIEW's threading model doesn't translate to C very well. Same for LabVIEW's polymorphism model and >1D arrays, just to name a few problems.

 

To support only 'trivial' VIs would require a definition of 'trivial'. But I suspect it will be limited beyond usefulness.

0 Kudos
Message 6 of 9
(2,740 Views)

One extra complication in LabVIEW, to what Wiebe already names is the built in UI in every VI. Porting that to embedded targets is basically not a possibility, and even for NI's Linux realtime targets only for very specific models an option (with significant reduction in functionality in comparison to a desktop system).

Matlab started as text based scripting system in the first place and eventually gained some UI capabililities, although that really is tacked on to the whole and not a fundamental part of a function like in a LabVIEW VI. Translating that to C(++) is a comparably easy task, although even the resulting Matlab generated code isn't really very straightforward to follow. But it's simply sequential function calls that need to be translated to C, which is pretty much a 1 to 1 translation. A LabVIEW VI is a lot more than just a function even if it doesn't look like it when you work in LabVIEW.

Rolf Kalbermatter
My Blog
Message 7 of 9
(2,695 Views)

labview c code generator was doing this no?

NI have discontinued the product though

0 Kudos
Message 8 of 9
(2,652 Views)

@Vindhyachal.Takniki wrote:

labview c code generator was doing this no?

NI have discontinued the product though


Yes the C Code Generator was basically doing this. And it was discontinued because it was basically unsupportable.

 

People with the necessary knowledge to adapt the generated code to their specific target (you need some form of platform abstraction layer that translates between the LabVIEW generated code and platform specific resources like mutex, semaphore, threading and such rather complex mechanismes) won’t likely go to start code development in LabVIEW. If you know how to do that you are often much faster to do the rest in C(++) too.

 

Even if you can use the NI provided translation layers because your OS/compiler platform is exactly the same, most fail in getting the make scripts to produce a legit output. C(++) make scripts for non trivial library projects tend to get pretty complicated.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 9
(2,644 Views)