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: 

Simple C code scripting environment in LabVIEW

Hello, 

 

I'd like to create a simple C code scripting control in GUI and convert those text to LabVIEW code.

I have been thinking how to make a most effective structure for that but is not easy to design.

So, kindly ask is there any idea or experience about this from you globally?

Users want to typing some conditions and logic based on C style text scripting.

 

Thanks in advance!!

 

Best Regards,

Best Regards,
-----------------------------------------------------------------------------------------------------------


0 Kudos
Message 1 of 6
(1,815 Views)

You could look at the Formula Parsing Vis which come together with LabVIEW. They "only" implement mathematical formulas in text form and are already fairly complex. Mathematical formulas are in many ways a subset of the C programming language, so you can safely assume that a proper C like parser is going to be considerably more complex to implement.

 

This is doubtlessly a very fun and interesting project to attempt to do, but do you even remotely comprehend what you are trying to do here? Do you have the preseverence to do this for real AND the time to spend for that? A reasonably C like parser will quickly require weeks if not months of development time, even if you don't implement all the different C syntax features.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(1,751 Views)

Why?

It's probably a lot easier to make some sort of interpreter of a simple c-like text if you want the text-based script functionality. But sure, you can interpret text and use scripting to create items on a VI. As mentioned, if you want to make it a true parser it's a pretty big job.

There's examples of how to create items on a block diagram through scripting, that's actually the easy part.

Connecting them to each other and in the right hierarchy is the next hurdle.

There should be plenty of external parsers that can check the validity of the text, i'd use that as a shortcut to know i don't have to handle all syntax checks myself.

And so on.

What have you tried?

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 6
(1,740 Views)

Maybe it'd be worth exploring LabVIEW's Python nodes.   That might make for a more straightforward path forward overall.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 6
(1,727 Views)

Hello, 

 

Thanks for your comments. Unfortunately, I'm using LV 2017 now. 😞

Best Regards,
-----------------------------------------------------------------------------------------------------------


0 Kudos
Message 5 of 6
(1,675 Views)

Rather than parsing text input and generating/running LabVIEW code, would using a string control to populate a temporary text file and then actually compiling it with a C compiler into a DLL, then calling the DLL with Call Library Function Node be a possible workaround?

 

Making it 'interactive' might be tricky, since you'll have to have some 'update' function that causes the compilation and then wait, but for simple enough programs it might be possible.

You could consider always wrapping the input in a suitable template, such that the function name and parameters/return type were known and the appropriate declarations were in place, perhaps something like:

 

#if defined(_MSC_VER)
#define EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define EXPORT __attribute__((visibility("default")))
#endif

<separate string control for includes here. Maybe a string array and some nice parsing?>

EXPORT char* myFunction() {
    <fill in the text input here, e.g. return "Hello World"; >
}

 


GCentral
Message 6 of 6
(1,655 Views)