Object instance with parameters | 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
Object instance with parameters
July 28, 2021
9:44 pm
Avatar
VARTORTech
Member
Members
Forum Posts: 4
Member Since:
July 3, 2020
sp_UserOfflineSmall Offline

Greetings,

I successfully ported a library for Arduino to LabVIEW following the instructions in the Help File. However, I was unable to resolve the following: in the example provided by the library, an instance is created that receive two constant. Something like the following:

////////////////////////////////////////////

#include "ALHarduinoLibrary.h" // library that must be included

#define arduinoPIN 4 // Arduino Digital pin
#define ALTYPE 11 // Used by the library for some settings

// Create instance
ALH alhobject(arduinoPIN, ALTYPE);

void setup() {
    // Initialize
    alhobject.begin();
}

void loop() {
    // Reading
    float h = alhobject.reading();

...

//////////////////////////////////////////////////////

and so on. If I use a different pin on the Arduino, or need to change the number for ALTYPE, I can just change it in this source code. However, for the Arduino Compatible Compiler for LabVIEW I had to hardcode those values in "Translator.vi", specifically in the "Defines" and "Includes" portions. Therefore, if I need to change them, I need to modify "Translator.vi", but that seems to defeat the purpose of the whole process.

Is there a better way? Please advise.

Regards,

Enrique

July 28, 2021
10:22 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Instead of defining, them can you just pass those values (arduinoPIN and ALTYPE) into an Initialize VI  (such as begin()) that configures them in the library at runtime?

August 3, 2021
4:19 pm
Avatar
VARTORTech
Member
Members
Forum Posts: 4
Member Since:
July 3, 2020
sp_UserOfflineSmall Offline

It works. Thanks!

This brings another question about how the ACCL work. Please bear in mind that I am not proficient in C or arduino sketches. Having the capability to code Arduino in LabVIEW is amazing and for that I am grateful.

In the Arduino sketch that I shared as an example the instance "alhobject" is global to both "setup()" and "loop()".

From your suggestion, the way I modified the code is to create a VI, which in Translator.vi looks as follow:

ALH alhobject(%s,%s);

alhobject.begin();

This VI receive arduinoPIN and ALTYPE as inputs. When I check this using the "Arduino Code" in the compiler Window, this code ends up inside setup(), like this:

void setup()
{
unsigned char Const302;
unsigned char Const228;
Const302 = 11;
Const228 = 41;
ALH alhobject(%s,%s);
alhobject.begin();
}

As I mentioned, I am not proficient in C or arduino sketches, but it seems to me that alhobject won't work inside loop()... but somehow this code is working.

I was wondering: is it that the ACCL work some extra magic while compiling the code for Arduino and sort things out correctly?, or perhaps is that everything happens inside setup(), which means that loop() is not used?

Regards,

Enrique

August 4, 2021
4:58 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Everything happens in setup and loop is not used by the Compiler.  Arduino abstracts things by calling setup() then loop() from main() but the Compiler creates its own loops all within setup().  It just means the Arduino defined loop is never called or used. 

August 4, 2021
10:03 pm
Avatar
VARTORTech
Member
Members
Forum Posts: 4
Member Since:
July 3, 2020
sp_UserOfflineSmall Offline

Thanks for taking the time and sharing this information. It make it easier to port libraries and even my own. Kind regards.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
29
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