09-09-2014 04:07 PM - edited 09-09-2014 04:23 PM
I have 20 test I want to run .. Each test is represented by a bit
If all the test are running all the bits are set to one ( 0xFFFFF - which is default setting).
If a test is not supposed to run we will minus that hex number from defualt number.
If test 19 is not supposed to run I will subtract default setting 0xFFFFF by 0x40000 (bit for test 19).
Is there better way to do bit manipulation without remember each bit hex number?
I basically just want to put the test number in without having to worry about the hex decimal number.
*also want to add test too.
Solved! Go to Solution.
09-09-2014 04:10 PM
Why don't you make the boolean array a control, initialize it to all true, and then let the user turn LEDs off as needed. (show the exact number of elements and hide the index display to prevent the user from adding elements). Now convert the final boolean array to a number to be used.
09-09-2014 04:16 PM
Without looking at your code (I have LV 2009 on the PC) I guess you could convert the number to an array of booleans, flip the appropriate bit and then change it back into a number. I know there are better ways, but I like this way because you it's like you are physically manipulating the bits and not doing a bitwise operation - which I'm terrible at doing.
09-09-2014 04:26 PM
I changed the code to LV 8. it not best looking (or design) code i just wanted to work on concept.
thanks for concept. i did not think of that. I am not great with bit manipulation too. that why i figure the forum could help me with that.
09-09-2014 04:27 PM - edited 09-09-2014 04:29 PM
I think it will be neater if i do not use whole array on the front panel. I rather the user put in the test number or maybe use a enum. both method will take up less space.
but then i will have to worrry about overflow if the user add test when all the bits are set to one.
09-09-2014 04:51 PM - edited 09-09-2014 04:53 PM
It doesn't have to be plain-jane boolean LEDs. You can use switches or toggles. Just right-click on the LED and choose replace... and then replace them with various boolean controls until you find one you like. Also, since elements of an array have to have the same property values, you'll have to use free labels or text boxes next to each boolean control to "label" the tests. But if you arrange the boolean in a vertical fashion, you can get a decent UI going...
Oh and you can use the Number of Rows property to display the proper amount of booleans.
09-09-2014 05:11 PM - edited 09-09-2014 05:11 PM
Are you aware that most boolean functions work on integers?
Although your description of what you want is not entirely clear, I think that Scale by power of 2 and Boolean Invert and AND may do what you want.
Lynn
09-09-2014 05:13 PM
@billko wrote:
It doesn't have to be plain-jane boolean LEDs. You can use switches or toggles. Just right-click on the LED and choose replace... and then replace them with various boolean controls until you find one you like. Also, since elements of an array have to have the same property values, you'll have to use free labels or text boxes next to each boolean control to "label" the tests. But if you arrange the boolean in a vertical fashion, you can get a decent UI going...
Oh and you can use the Number of Rows property to display the proper amount of booleans.
I would suggest the Check Boxes. They are very intuitive and simple to use.
09-10-2014 10:17 AM - edited 09-10-2014 10:23 AM
Thanks alot for all the suggestions.
@johnsold
In the first version of the program (which need to be done in couple weeks) I can use an array on front panel. In the second version of the program a plc will send me hex value of the test to disable or enable.
And thanks for answering my question.
@Billko thanks for the suggestion on how to update plain jain Boolean LEDS. I will use that on first version of the program.
@anyone
I will have to worry about bit manipulation in the second version of the program. To disable a bit I just add number and to enable a bit a subtract number. But what happen if all the bits are set to true and the plc still send me bit to turn on test 1.
Example ( situation 1 ) – if current value is default ( 0xFFFFF) and I add 1 the result of the number will be 0x100000. Basically turning off all the number
Situation 2. If all the test are disable (0x0) and the plc send command to disable test 1 all the bits will be set to one.
And idea on how I can do this? This being dealing with input command from plc ?
09-10-2014 10:28 AM - edited 09-10-2014 10:29 AM
@sticyfinger wrote:
Thanks alot for all the suggestions.
In the first version of the program (which need to be done in couple weeks) I can use an array on front panel. In the second version of the program a plc will send me hex value of the test to disable or enable.
And thanks for answering my question.
@billko thanks for the suggestion on how to update plain jain Boolean LEDS. I will use that on first version of the program.
@anyone
I will have to worry about bit manipulation in the second version of the program. To disable a bit I just add number and to enable a bit a subtract number. But what happen if all the bits are set to true and the plc still send me bit to turn on test 1.
Example – if current value is default ( 0xFFFFF) and I add 1 the result of the number will be 0x100000. Basically turning off all the number
Numbers are numbers are numbers. If you just change the control radix to hex, you can view/enter the number in hex. 🙂
How does the data arrive? As a string? As an array of bits? As a binary string - i.e., "0001 0000"?