01-19-2011 02:33 PM - edited 01-19-2011 02:41 PM
In the attached VI I am trying to achieve 2 things.
1) When I press the ON boolean, I want the power level to go to to 100%
2) When I press the STOP boolean I want to do all 4 of the following
a) Overwrite the ON boolean
b) set "Power Level" to go to "Off"
c) The desired hex string at "Off" is sent to VISA
d) switching off the program.
Can this be done?
Other criticisms of the block diagram are also appreciated!
Thanks
mhaque
Solved! Go to Solution.
01-19-2011 03:58 PM
01-19-2011 05:40 PM
The checksum VI is neat, but overly advanced.
If the char is a hex character, add it to an array, feed the array to a shift register. Once it has looped through you've done both your first loops in one small one. Then you only need to convert back to string and Hexadecimal string to number.
/Y
01-19-2011 10:50 PM
Hi mhaque,
one of the things i would point out is the use of the property nodes. In some circumstances they are necessary but you still need to be careful with how you use them. In the top left corner of your main vi you are writing to property nodes each iteration whether the controls for Fans or Lamps should be visible or not:
Above is a snippet of that section (Looks messier then it actually is due to the way snippets are created). Each iteration you are reading from a local variable the amount of Lamps or Fans. From that string you are then outputting booleans from a case structure into the visible properties of the indicators. Writing to a property node is a slow operation as it forces a thread change to the UI thread. I cannot remember the exact speeds but its enough to make you want to limit the amount of times you do it to a minimum. I was very recently helping a guy who was failing to get a sample rate he required to read from an external piece of equipment. One of the main reasons causing this was because he was writing to 100+ property nodes every iteration. In your example you will not notice the impact of the property nodes as you have a 350ms pause per iteration. It is still good habit to handle property nodes correctly though as you dont know what might change in the future.
To make your code more efficient i would start off by placing all your lamp indicators in a cluster and all your fan indicators in a cluster. If you use the Cluster from the classic palette you can use the paint brush tool to make it transparent, giving you the effect you currently have. I would ensure that all the indicators in the cluster where in the correct order. I would then encapsulate the changing of the property within a subvi that can be used by either the Fans or the Lamps.
:
In your main vi i would then use shift registers to see whether the #Fans or #Lamps Enum had changed (In yours you use a combobox, i have changed this to an Enum for this example). If there has been a change you could then use the subvi to change the visibility accordingly:
Now you will only write to a property node when the value of your Enums change. If it was a large vi and i didnt want lots of shift registers i would use a small vi to indicate whether the Enum had changed since the last iteration:
This does exactly the same as the shift register but helps reduce clutter and keep the vi tidy.
Is there a reason you are using a combobox? An enum would better suit your needs from what i have seen. As long as the amount of Fans or Lamps are continuous, ie from 0,1,2,3,4,5. If you do need to miss some values, ie can never be 3, then i would use a text ring. Both of these control output a number instead of a string.
Rgs,
Lucither
01-20-2011 02:29 AM
In general the program could easily be converted to an Event structure which'll make it tidier and better structured. The Visibility would then automatically only be performed when a button is pressed.
/Y
01-20-2011 08:36 AM
Thank you all for the constructive critcism!
But my main issue has still gone unanswered. Where would the event structure fit in? I am fairly new to LabVIEW and I have had minimal succes in using event strctures.
mhaque
01-20-2011 01:33 PM - edited 01-20-2011 01:34 PM
How's this as a first look at an event based change?
I also modified the Checksum, i should work the same (dont throw your current code until you've double checked)
/Y
01-20-2011 01:35 PM
could you post this in LabVIEW 9 or less?
mhaque
01-20-2011 02:19 PM
your version of labVIEW is 10.0. I currently only have 9 😞 so it won't open.
01-20-2011 02:26 PM
@Yamaeda wrote:
The checksum VI is neat, but overly advanced.
If the char is a hex character, add it to an array, feed the array to a shift register. Once it has looped through you've done both your first loops in one small one. Then you only need to convert back to string and Hexadecimal string to number.
/Y
On a side note (if he used your method this would be a non-issue anyways) but delete from array is being used in a loop. Have a look at using replace array subset then replacing the array afterwards.