08-07-2015 07:43 PM
I'm develping a program to communicate with an external device, and it has a specific protocol. Often times, I need to make structs/typedefs of specific type (u8/u16/u32) that have values defined by multiple selection. For example, the protocol asks for the following:
The field is a bit field structure (multiple bits can be set simultaneously) defined as follows:
typedef u_16 COMM_TYPES;
#define A 0x8000
#define B 0x4000
#define C 0x2000
#define D 0x1000
How would you recommend implementing this? I've tried looping through a listbox in combination with a text ring that has the name and value pairs, but its cumbersome doing for each unique typedef (see image below)
08-07-2015 07:57 PM - edited 08-07-2015 07:58 PM
That's what I would do. Other than I might use OR instead of sum, but that shouldn't make a difference.
The other possibility would be to take the array of index values, to a 2^x where x the array of indices, then add that. This assumes that every index in the array matches bit for bit with the enum values. Nothing is missing, and array element 0 corresponds to bit 0. In your case, your order is reversed, but you can reverse the array. And all your values are in the highest nibble of the highest byte (hex ?000) So you'd have to do some bit shifting or multiplication to get the actual values.
But I think this would make your code that much more fragile. I would just do what you have shown.
08-07-2015 08:06 PM
08-07-2015 08:23 PM
I thought he had a ring going on in there.
Now that I copied the VI snipped so I could see it, and play with it, I see that it does, but the snippet is a lot more convoluted than it needs to be. I can't even tell what the user experience with this VI is supposed to be.