Hi again… after a while without posting anything, I am here .
The initial idea with this blog, was to post information related with NI LabVIEW programming environment for the Spanish Speakers, this because there are few LabVIEW resources in Spanish compared against English, but I have received many suggestions from non Spanish speakers so I have been consider seriously post in English also. I am not a native English Speaker, and I hate to use on-line translators, So I will do my best.
This time let’s review a code I developed months ago, this is comment parser based on Python & C/ C++.
You could wonder how come a comment parser could be useful for a graphical programming environment such as LabVIEW?
It is quite common to use external files in our projects: Test executives or Script runners, configuration files, etc.
This is where a Comment parser could be useful.
This is an specific example of a Script runner application, where the commands could be saved in external files to call them later if needed. The application send those commands to a micro controller, and the micro controller firmware process it and returns a value for each command.
W//xxx;
WR107ABB1;
R108458E2;
Wait(100);
W104D02C4;
Despite of the possible documentation about those commands, it could be handy have a small description of each command… So here is where a comment parser makes sense.
W//1234; # This command give access to the : enter test mode.
WR107ABB1; # Sets a temperature value.
R108458E2; # Reads the current temperature setpoint.
Wait(100); # Waits 100 mS.... this is command is not for the firmware,
# this command is processed by LabVIEW application.
W104D02C4; #Locks the enter access mode.
Now, the external Script contains the commands which makes more readable using comments, this VI parsed out the comments and returns the commands which invokes firmware functions Notice for this particular case I use the Python comment style, because C/C++ comment convention is not recommended since the first command (W//1234;) contains the “//” characters which in C/C++ are considered as comment line… If the C/C++ convention is used for this particular case all the text after the “W” will be swept out.
Different example, using again a Script runner or test executive.
/*Test sequence for BP products*/
#define CONST_VAR1 3.000
#define CONST_VAR2 2.502
#define CONST_SR 20000
#define CONST_SA 2000
//#include<C:\a.txt>
BP.Init
BP.PowerOn adjVdc(5.105)
BP.Gain (CONST_VAR1) arg1(3.141516) sr(CONST_SR) sa(CONST_SA)
BP.PowerOn
BP.Offset goal(CONST_VAR2)
BP.Offset goal(CONST_VAR2)
BP.PowerOff
BP.End
//Developed by eZ
This time I want to use an additional feature from C/C++. The directive: #define
I use it to define a variable value in my Test Sequence file… but the application will parsed out the variable and its value and the code will substitute the variable name for its variable value…
So, If I will use then the directive #define… This time it is not recommended to use the Python convention for the comments… But the C/C++ conventions fits quite well..
Take a look the picture shown below.
You may notice the output did not contain the variable name as the Input did… Now the Output(Right side) have the variable values instead… Also the comments did not appear at the right side… Now you could use then the data to feed a sequencer (Queued State Machine, etc) using the commands without ignoring the useful comments.
Feel free to write a comment (Python or C/C++ style… ) about this article
eZ