LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shift Registers in while loop when string is connected to registers

Solved!
Go to solution

Hello everyone !! I just need to know how these shift registers work. For example in added picture, I have a stacked sequence structure. Then there is a while loop with case structures inside it. As you can see, there is shift register in while loop with string initial and on the right side shift register there is string "input ". So my question is when we run the VI, for check error case is it going to start from case initial and then pass the information to the input case in case structure. So basically, I need to know how shift registers can be used with case structures and while loop.

0 Kudos
Message 1 of 13
(3,701 Views)

Look up "LabVIEW State Machine" and you will get a lot of info.

0 Kudos
Message 2 of 13
(3,695 Views)
Solution
Accepted by topic author studentgirl

http://www.ni.com/tutorial/9330/en/

 

With that you can post a picture that is executable code.  For us looking at your picture of code is no better than looking at a picture of notepad with text in it.

 

That being said here is some information on shift registers.

 

http://www.ni.com/getting-started/labview-basics/shift-registers

https://zone.ni.com/reference/en-XX/help/371361H-01/lvconcepts/shift_registers_concepts/

 

To simplify your code I'd highly recommend getting rid of the outer sequence structure.  Stacked sequence structures generally are used in ways that cause new users problems, and sequence variables compound that.  If you want some code to run before the main states are called, you can have an initialize state in your state machine and have it be more managable.

 

Message 3 of 13
(3,693 Views)

Sorry I marked it solution by mistake but what else I can use to replace stacked sequence structures?

0 Kudos
Message 4 of 13
(3,630 Views)

As Hooovahh suggested, just make more states. This means adding a case to the case structure, and editing the strings that go into the shift registers on the right. After the loop runs once, the string you put in on the right, will come out on the left, and select which case to run next. You can draw out a flow chart on paper, and each state on the flow chart can usually be implemented by a case in the case structure.

0 Kudos
Message 5 of 13
(3,618 Views)

As I mentioned, a sequence structure usually isn't needed to keep things like "Make X happen before Y" because data flow in most cases handles this for you.  Y can't happen until all inputs are provided, and if an output of X is used in Y then you already have data flow.

 

In the cases that explicit data flow doesn't control order of execution, you can still use a state machine like the one you already have.  Just make a case like "Initialize" that you run before doing anything else.  Then you have the same functionality as a sequence structure, but can choose to do other things like abort and not do anything else if Initialize fails.  With a sequence structure you must go to the next state.  Or what about wanting to revisit the initialize case maybe for a retry?  With a state machine that's simple just go back to it.  But with a sequence structure you can't really go back, without extra looping code, and even then you again must go through all states of the structure.  To be fair a state machine really needs a loop too but these are usually included in the template.

0 Kudos
Message 6 of 13
(3,615 Views)

So, I do have initial case in case structure. Basically, whatever I wired to the shift registeres is available in case structures. If I am correct, the case which is wired to the right shift register is the next state right? 

For example, I connect initial state to the left register and check error to the right register .The first iteration will start from initial state and then pass to check error state. Then, let's assume in check error case, I connect right register to display which shows next state is display but initial is still connected to left register. So, how will it run in this case?

Also, should I take stack sequence structure completely out?

0 Kudos
Message 7 of 13
(3,608 Views)

Yes, just turn on Highlight Execution (the lightbulb on the block diagram toolbar) to see what is coming out of the shift registers.

 

If you can figure out what that sequence structure is doing, it would be a good exercise to take it out.

0 Kudos
Message 8 of 13
(3,604 Views)

@studentgirl wrote:

 

Also, should I take stack sequence structure completely out?


Because you never posted your source code I have no idea what is happening in case 0 or case 2 so I can't say for sure.  But I can say that whatever is happening in case 0 could be done in the state machine first, and whatever is happening in case 2 could be done in the state machine as a cleanup state.

0 Kudos
Message 9 of 13
(3,599 Views)

So if we have case structure with three cases 

check error 

initial 

display

Then left register in all the cases is connected to initial.

The right register in check error is connected initial , the right register in initial is  connected to check error and in display case it is connected to initial again.

When the program runs is it going to start with initial then check error case is going to execute. How is it going to display case?

I have attatched example so that you guys can explain more.

0 Kudos
Message 10 of 13
(3,583 Views)