LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Type Def constants

I tried doing some searching but I just see stuff on enums vs rings.
 
I am trying to set up HW configuration. I have multiple boards I am talking to and would like to combine the IO into 4 arrays. DI, DO, AI, and AO. I can do this fine but I am worried if the designer decides to insert/change one IO point. (e.g. Board 1 slot 2 is an input and it is desired to change to an output). This would of course shift every point after that alteration by 1 and I would have to go through all of the code from the ground up an modify it. Instead it seems I should be able to create a I32 cons array that is a type def used through out the code that would look something like the following:
 
[i32 array]
0
1
2
15
3
4
5
6
16
7
8
.
.
.
 
The idea is that at initial design the array was likely 0,1,2,3,4,5,6 etc but since slot 2 was changed it ended up being 15 and I just have to shift the type def constant. I would then use the type def constant to map the data properly before it reaches any of the other code.
 
Am I missing something or is there no way to have constants update in this manner??? Only enums? that seems poorSmiley Sad


Message Edited by CJasnoch on 03-26-2008 01:00 PM
0 Kudos
Message 1 of 7
(3,777 Views)

create a custom array control, input your various data points, and right click->data operations->make current value default

 

make sure you click on the outer border instead of one of the elements, or else the elements inside will default to the one you clicked

0 Kudos
Message 2 of 7
(3,755 Views)

I usually simulate the CONST by using a vi that returns the constant.  An example is pi (YES I KNOW THIS IS ALREADY PROVIDED BY LV) place the double constant 3.14.....on the block diagram, and wire it to an indicator, select one terminal and wire it out.  Change the icon and your done.  This is different from the saved value typedef in one important way, the data can not be changed without opening the vi, which can be protected.  this can be used in conjunction with a typdef for complex data types.    An example of this is a version cluster, having a major, minor and revision integer inside of a cluster, typedef this and then make a vi called application version use the typdef for the constant on the diagram and the indicator out of the CONST Vi.  This is my prefered method to simulate a CONST in labview.  This is not as elegant as a preprocessor directive in C but it works nicely.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 3 of 7
(3,727 Views)


falkpl wrote:

I usually simulate the CONST by using a vi that returns the constant.  An example is pi (YES I KNOW THIS IS ALREADY PROVIDED BY LV) place the double constant 3.14.....on the block diagram, and wire it to an indicator, select one terminal and wire it out.  Change the icon and your done.  This is different from the saved value typedef in one important way, the data can not be changed without opening the vi, which can be protected.  this can be used in conjunction with a typdef for complex data types.    An example of this is a version cluster, having a major, minor and revision integer inside of a cluster, typedef this and then make a vi called application version use the typdef for the constant on the diagram and the indicator out of the CONST Vi.  This is my prefered method to simulate a CONST in labview.  This is not as elegant as a preprocessor directive in C but it works nicely.

 

Paul



That's the way I do it, too.  This method, combined with blanking the B&W icon of the VI and drawing an icon that doesn't use all the space of the 256 color slot lets you create something effectively similar to the primitive constants NI has.
0 Kudos
Message 4 of 7
(3,698 Views)

And if that does not meet your needs you can assemble a translator that accepts the enum value and use a look-up table to find the appropriate value. The "translator" approach bring with it the ability to redefine the translations "on the fly".

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 7
(3,695 Views)
I have always wondered why there isnt a true constant, the method I describe is close, it essentially encapsulates and protects the data as a constant but still has the overhead of a function (vi) call.  Not a problem for modern computers but for longtime programmers I cringe knowing that there should be a more efficient method. Maybe the compiler is smart enough to minimize the overhead but there is not too much info on the deep innerworkings of the Gcompiler.  I employ my method from a maintenance and scalability standpoint and not a program size or speed view.  I am curious to know if there is something better than this method, so far I havent come up with one. 
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 7
(3,688 Views)

Thank you Paul! That is what I was looking for. The idea of pre-defined constants is where I get hung up... I am with you thinking there should be a better way but we have to make do with what we have available.

 

Thanx again.

0 Kudos
Message 7 of 7
(3,658 Views)