08-23-2010 01:41 PM
Hi, I have a function in C/C++, and I am wondering how I can have it translated into LabVIEW.
Thanks,
Andrea
08-23-2010 02:08 PM
You can either create a dll from it or actually translate and use LabVIEW functions. Depends on how much you understand C/C++.
08-23-2010 02:11 PM - edited 08-23-2010 02:12 PM
You can re-write it in LabVIEW (obviously! ) or you can call the C code (you'll need to create a DLL) with the Call Library Function Node.
EDIT: Too slow again!
08-23-2010 02:20 PM - edited 08-23-2010 02:21 PM
There are three ways to use the code in LV.
First create a DLL or .Net assembly and call it from LV.
Second use a Formula Node. You can enter your C code directly there.
Third rewrite the code in LV.
Which is approiate will depend on your Code.
Rewriting in LV will cost most work and you need to have a good experience in programming in C and LV.
Most language constructs of C are available in LV but not all, e. g. there is no while loop. The While loop in LV is a do { ...} while loop. It will execute at least once. For a while loop you must use a Case with a containing While loop. since your termination expression must be used twice create a subVI for it.
Another thing which will go not easy to handle is the switch statement. Basicly the Case structure is the same but you must take care of the following code in C:
case <value1> { ... } case <value2> { ... } break; case <value3> { ... } break;
You must handle this by additional nested Case structures.
Most runtime functins are available or can be build using two or more LV function, e. g. fprintf can be created by Format Into String followed by a File Write.
If your code contains functions pointer thats no problem. VI references are function pointers. Open VI Reference creates a function pointer and Call by Reference uses it.
Since you are mentioning C++ you may need to have a look to the object oriented programming in LV.
OK, I'm the last one, but Ihe written the most text and some hints.