creating a class instance | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
creating a class instance
May 12, 2017
4:10 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

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!

May 15, 2017
3:15 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Yes it is possible.  Here is an example.

May 15, 2017
3:10 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

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.

May 15, 2017
3:16 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

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?

May 15, 2017
3:42 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

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.

May 15, 2017
3:46 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

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.

May 15, 2017
3:48 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

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. 

May 15, 2017
4:13 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

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.

May 15, 2017
8:42 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

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.

May 15, 2017
9:19 pm
Avatar
David
Member
Members
Forum Posts: 22
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

Thanks Steffan

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
11
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356