08-07-2017 07:54 AM - edited 08-07-2017 08:17 AM
Hi,
I have a while loop and a case structure inside it and uses the shift register for case selector.
As you can see under the "default" case, it looks for the change in the buttons (in fact, "true" status of the boolean) on the front panel and executes the corresponding programs inside the case for that particular button.
I have a case for reset that I want to use to initialize both "asp" and "disp" cases to zero together.
I know that I can achieve initializing one case by wiring the corresponding case number to the inner input of right side of the shift register, but I cannot think of any way to wire two numbers together.
Thank you in advance!
08-07-2017 08:30 AM - edited 08-07-2017 08:31 AM
Hi Janed,
use an enum for that state shift register. Then create as many states (enum entries) as you need, among them one "Reset" state.
Use an additional shift register to hold your other state data (like TDV, vol, etc.) and process this data as required in each state!
Suggestion: Draw the state machine on a sheet of paper! Sort out any logic issues before starting to code!
08-07-2017 08:40 AM - edited 08-07-2017 08:41 AM
Is there a reason you aren't using an event structure for handling the events of the UI? Attached is a quick re-write using an event structure and a queued message handler using strings (enums are another good solution that you may prefer but this was faster for the demo).
There are other options but I think this design is pretty clean and simple. You can see that the Vol, TAV, and TDV are basically variables in a shift register. These can be read or written using unbundle and bundle by name. Adding new variables can be done by adding them to the bundle function outside of the while loop. The event structure also allows for handling the close better. Now when you close the window it gets an event to stop the VI instead of running forever. Also this design means no local variables are needed, and no hidden controls.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
08-07-2017 08:42 AM
I am sorry, but I am not understanding this.
Wire the enum to the shift register of "reset" case?
And for enum, it will be control, I assume?
08-07-2017 08:44 AM
08-07-2017 08:56 AM
Thank you for the rewrite of the VI!
I was using the case structure because that was the example VI that I was provided for the hardware.
I was never exposed to labview, so I was just basing on the provided VI.
I will look over your code one by one as everything is new to me.
Also one more thing, the reason I had the while loops in each "asp" and "disp" cases was for my plan to have a tank indicator on the front panel to reflect the status of the instrument, which is a syringe pump. I do not always aspirate and dispense right away, but rather aspirate in different volumes multiple times and dispense in multiple steps. So it is important to carry over the value from the previous iteration.
Will I be able to implement that function in your event structure?
08-07-2017 08:58 AM
GerdW,
I am still not following this. I am new to labview and I have been learning different functions just based off the example VI provided.
So having an enum will replace the whole code on the "default" case?
08-07-2017 09:33 AM
@janed0714 wrote:
Will I be able to implement that function in your event structure?
I think so, it is hard to know what you are asking. The re-write I show allows for entering a different value to be added to either the asp or disp and updating the numeric indicator by calling the state that updates the UI. If you are asking for something to happen periodically, this can be done in the event structure with the timeout case, which is an event that gets generated if no other UI events happen within the timeout.
Being new to LabVIEW is fine, but if you get some time you may want to brush up on some of the free training around the internet. I'd recommend the self paced training if you have an SSP. The fact that your VI was written in 2012 tells me this probably isn't the case. But there is online training for students, and the 6 hour training is a good start if none of those are options. I'd avoid taking any training focusing on hardware just yet since your questions don't seem to be related to that yet.
-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)
Learn NI Training Resource Videos
6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
In addition to this you may want to read up on some of the whitepapers on state machines. Things can get complicated, but I hope you see like in the example re-write I did that things will be much easier to change, and the code will be much more readable if you have clearly named states, and an order of things to do on an event.
http://www.ni.com/white-paper/3024/en/
http://www.ni.com/white-paper/2926/en/
https://forums.ni.com/t5/Example-Program-Drafts/State-machine-using-Queues/ta-p/3535013
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
08-08-2017 06:35 AM
All these are really helpful!
Thank you very much!!