4:10 pm
January 28, 2017
I am trying to port a library that requires an instance of a class be created, then the functions are called on that instance. Is it possible to port this? I (mostly) understand how the C code examples work, but I'm not sure how I would set up the Translator.vi in a way that would accept the class instance as an input prefix to the function calls. The libraries are the Adafruit_LEDBackpack and Adafruit_GFX. Any help is appreciated!
3:10 pm
January 28, 2017
Thanks Steffan. That was really simple and I've gotten my library working! I had tried putting the class generation in the includes, but didn't realize it needed to be in the same string entry as the .h file.
Side note with the example.. If I make a test VI for any of the BMP180 libarary VIs, I always get an error like this when trying to generate the Arduino code or compile:
Error in Test.vi: Arduino function "BMP180:lvlib:BMP180 Read Pressure" not supported.
3:16 pm
January 28, 2017
Follow up question... Is it possible to create multiple class instances in the same VI? Or would I have to create a finite number of copies of the functions, and call the class constructor that number of times in the Translator VI? Maybe that's what the SoftwareSerial library port is doing for 3 serial ports?
3:42 pm
March 12, 2015
David said
Thanks Steffan. That was really simple and I've gotten my library working! I had tried putting the class generation in the includes, but didn't realize it needed to be in the same string entry as the .h file.Side note with the example.. If I make a test VI for any of the BMP180 libarary VIs, I always get an error like this when trying to generate the Arduino code or compile:
Error in Test.vi: Arduino function "BMP180:lvlib:BMP180 Read Pressure" not supported.
You need to make sure the library is placed in the proper directory. Please refer to Step 3 of "Porting an Arduino Library to LabVIEW" of the user manual:
IMPORTANT: It is extremely important to point out that, like the Digilent Analog Shield set of API VIs that were created to illustrate how existing Arduino libraries can be ported into the Arduino Compatible Compiler for LabVIEW, any user created set of API VIs need to reside in the directory: "[LABVIEWDIR]\vi.lib\Aledyne-TSXperts\Arduino Compatible Compiler for LabVIEW\addons". This indicates to the compiler that those VIs are user created, and they corresponding C-code can be displayed by the Arduino Code Display Tool, explained in step 5 below.
3:46 pm
March 12, 2015
David said
Follow up question... Is it possible to create multiple class instances in the same VI? Or would I have to create a finite number of copies of the functions, and call the class constructor that number of times in the Translator VI? Maybe that's what the SoftwareSerial library port is doing for 3 serial ports?
Im not sure how the SoftwareSerial was implemented but take a look at this example. This was written before the Servo functionality was implemented natively. It shows how to instantiate and address up to 4 separate instances of the Servo class. I think this is what you are looking for.
3:48 pm
January 28, 2017
Steffan said
David said
Thanks Steffan. That was really simple and I've gotten my library working! I had tried putting the class generation in the includes, but didn't realize it needed to be in the same string entry as the .h file.Side note with the example.. If I make a test VI for any of the BMP180 libarary VIs, I always get an error like this when trying to generate the Arduino code or compile:
Error in Test.vi: Arduino function "BMP180:lvlib:BMP180 Read Pressure" not supported.
You need to make sure the library is placed in the proper directory. Please refer to Step 3 of "Porting an Arduino Library to LabVIEW" of the user manual:
IMPORTANT: It is extremely important to point out that, like the Digilent Analog Shield set of API VIs that were created to illustrate how existing Arduino libraries can be ported into the Arduino Compatible Compiler for LabVIEW, any user created set of API VIs need to reside in the directory: "[LABVIEWDIR]\vi.lib\Aledyne-TSXperts\Arduino Compatible Compiler for LabVIEW\addons". This indicates to the compiler that those VIs are user created, and they corresponding C-code can be displayed by the Arduino Code Display Tool, explained in step 5 below.
Oh yeah, thanks. I had it in a temp directory rather than the addons.
4:13 pm
January 28, 2017
Steffan said
David said
Follow up question... Is it possible to create multiple class instances in the same VI? Or would I have to create a finite number of copies of the functions, and call the class constructor that number of times in the Translator VI? Maybe that's what the SoftwareSerial library port is doing for 3 serial ports?Im not sure how the SoftwareSerial was implemented but take a look at this example. This was written before the Servo functionality was implemented natively. It shows how to instantiate and address up to 4 separate instances of the Servo class. I think this is what you are looking for.
That's pretty close. I think I understand what that's doing. It creates 4 instances of the class in the Include string and then the functions are written to select one of 4 instances. Is it always required to pre-define the number of class instances? I have some functions that are callable by two different classes. I'd like to set up the library so that I can create either of the class instances dynamically and then call the functions on the appropriate class. Is that possible? Or should I always be creating an instance of each class and then using an init function to select which one I want to use..? Or, lastly, should these be in two separate labview libraries, one for each class? It seems like I should only be making one version of the common functions. Thanks for the help. I'm learning more C++ than labview right now. I managed to write one of my programs in a few hours on Friday in pure C++, but now that I have the library port mostly working, it's probably an hour to re-create it in Labview.
8:42 pm
March 12, 2015
It doesn't create 4 instances, it just creates a pointer to the max number of supported instances (could be limited by hardware for example). The actual object is created with the "new" during the Init call. So you can pre-define the max number of objects that can be supported and can Init with an object number as many times as needed from the LabVIEW code. Without seeing what you are doing, Id say make the function specific to the classes themselves. Having a separate LabVIEW library for each class may also be a good idea.
11
1 Guest(s)