LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset Shift Register to Multiple Values

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! 

0 Kudos
Message 1 of 9
(4,325 Views)

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!

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(4,290 Views)

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.

0 Kudos
Message 3 of 9
(4,280 Views)

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?

0 Kudos
Message 4 of 9
(4,276 Views)

Hi janed,

 

no, the enum will be held in a shift register. All you need is a typedef'd enum and some constant instances of this typedef…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(4,272 Views)

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? 

0 Kudos
Message 6 of 9
(4,268 Views)

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? 

0 Kudos
Message 7 of 9
(4,265 Views)

@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.

 

 

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide 

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

0 Kudos
Message 8 of 9
(4,239 Views)

All these are really helpful! 

Thank you very much!!

0 Kudos
Message 9 of 9
(4,218 Views)