From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

A quick query about LV functionality

Given this vi that controls a motor based on some sensor data, I have some logic that determines the next motor state (based on the previous state & some sensor input). Furthermore, I need to test/evaluate different logical methods to determine the best motor/sensor approach for our application. This currently leads me to the practice using nodes/wires to encapsulate the state logic into a subVi, then trying the sub in the larger test vi.

 

My question is, can I compose the logic in C and make this usable (by some means) to the test vi, instead of wiring the logic into subVIs? Since the logic can be distilled to primitive data types, it seems like it would be much faster to type the transition function into C than it would be to encode it into a subVi w/wires & nodes.

 

Am I making any sense here? I've been using LV for about four weeks now. I'm wondering if there is a method of "compiling" a function written in C into a node that can be placed into a vi. Thanks in advance for you help.

0 Kudos
Message 1 of 8
(2,464 Views)

You could certainly compile a dll in C that you could call from LabVIEW. There may be other approaches of which I am not aware. However, that seems like a lot of trouble to me. You're still going to have to connect the inputs and outputs of the dll in LabVIEW. Perhaps if you shared your code there might be a better way to do what you want to do.

0 Kudos
Message 2 of 8
(2,431 Views)

Hmmm, I don't think performance is going to be an issue here.  The bottleneck in your code is not likely to be the logic that determines the next state.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 8
(2,407 Views)

Yes, you can compile a C program as a DLL and use the Call Library node to use it, though i would assume the overhead of calling a DLL is a lot higher than simply using the basic datatypes in LV (LV is quite efficient). It can be a good experience to do and compare both, though.

This looks like a case of "When all you have is a hammer, everything looks like a nail." 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 8
(2,381 Views)

The DLL calling overhead is not the problem but the development and maintenance of such a devided solution certainly will be. Putting code into an external DLL just for the sake of it is ALWAYS going to give you a more complex and much harder to debug solution. => Absolutely not worth the trouble.

Learn to use LabVIEW correctly and do it all in LabVIEW or do it all in C but do not mix such things just because of a presumed performance gain.

 

There isn't, LabVIEW code is not fundamentally slower than C code but you can make in LabVIEW much easier software that works but is programmed awfully than in C. In C if you program awfully you are very likely that the software simply crashes and never will produce anything, in LabVIEW it's surprisingly easy to program bad code and still get a somewhat working solution. Applying the same level of good software knowledge in a LabVIEW program will however lead to a just as performant solution as when doing the same in LabVIEW. The only problem for some people is to understand the difference of data flow programming in LabVIEW and sequential programming in C.

Rolf Kalbermatter
My Blog
Message 5 of 8
(2,372 Views)

Maybe I misunderstood the OP. I thought that he had several options for algorithms that he wanted to test to determine which approach gives the best results. To do this he has encapsulated this piece of code into a subvi which he is recreating each time. He finds this creation of a new subvi to be tedious and feels that he could more efficiently write these pieces of code in C and call it in LabVIEW. I think that this is a bad idea and suspect that with a little more information he could receive guidance to make his process less tedious. I did not get that he thought he would get a performance gain by using C.

0 Kudos
Message 6 of 8
(2,368 Views)

jophntrich1971,

 

Yes, your comments reflect the matter of the question I was originally asking. We're attempting to apply certain sensor/actuator devices in a somewhat novel way. We need to try several algorithms, through numerous variations, to decide what's actually possible and what's the actual achievable performance.

 

I've don't have any significant problems implementing state machines or parallel loop interoperation in LV (at this time). My original interest was in whether or not I could write the state transition functions (the things we're testing) in C and have them available as nodes in the LV pallet. From the comments, it looks like I can, but with no gain in productivity. If it was productive to encode some things in C, somebody would have mentioned it by now. Also, the many comments about poor performance in doing such was helpful in the deciding, but not technically the answer to the question (my error in the wording).

0 Kudos
Message 7 of 8
(2,309 Views)

I hate myself for mentioning this, but have you considered the MathScript node? Does that give you what you need?

I really don't suggest it in general, but it might be relevant here.


GCentral
0 Kudos
Message 8 of 8
(2,278 Views)