07-23-2014 10:03 AM - edited 07-23-2014 10:07 AM
Hello,
I was wondeirng if anyone had some suggestions about how I could make a control that needs to take 18 boolean inputs each that enable a different logging option on my instrument. Here are some of the current solutions that I've come up with but each with its own major issue.
1) Boolean array. User inputs a booean array that cooresponds to each value {1,1,1,0,0,1,1,0...}. The problem with this method is that it is very error prone, what if the user doesn't input all 18 values or mis-aligns the values etc. Also it is not very descriptive and the user wouldn't remember which value cooresponds to which logging item.
2) Bitmap/mask. Each logging option is a mask of a power of two, eg 0x01 = Watts, 0x02 = Amps 0x04 = Volts etc. The user could then add together all the options (s)he wanted and I could mask out the bits to get the boolean values. The problem here is that this requires a lot of manual labor by the user with adding and subtracting powers of two from a cumulative sum. Also the numbers get very large especially around the 2^15 - 2^17 power.
3) 18 individual boolean slider inputs. This one would solve the problem about the user not being able to keep track of what (s)he was logging but, this requires passing 18+ parameters to a function.
4) Create a custom boolean array control. I wish I knew how to make a custom boolean array control and then add this control to a CVI PnP Instrument Driver project.
Any other suggestions would be greatly appreciated.
Thanks,
Lawler
07-23-2014 10:36 AM
Create one boolean slider (or checkbox). Then use DuplicateCtrl to create the others and use an array to keep their ID, and another to keep their order, like this:
char *Names[18]={"Volt, "Amps"...};
int CtrlofIdx[18], IdxOfCtrl[100];
for (i=1; i<18; i++)
IdxOfCtrl[ CtrlOfIdx=DuplicateCtrl(Pnl, ORIG_SELECTOR,...Names[i]) ] =i;
Then in the common callback function you can use IdxOfCtrl[control] to know which control was triggered.
07-23-2014 10:43 AM
Unfortunetly I can't group controls into an array in a function panel window node, as far as I know.
07-24-2014 02:47 AM
Not sure what you mean by that... You can't have arrays in your program ?!?
07-24-2014 08:54 AM
No ha, array of controls. I can just pass a boolean array through the function but the idea is that people would be able to configure the options using sliders or buttons on the front panel itself if they were not inclined to use the function programatically.
07-26-2014 02:52 PM
You can create a new type using bit fields.
Each bit corresponds to an option and it takes only 1 bit of memory.
18 bits fit into an (unsigned) int.
No need to shift/mask/add numbers.
And you can name every bit meaningfully so that people can set and get options with their names.
Put a single poimter to struct parameter to your function and pass the object (option struct) pointer to it.
Hope this helps.