09-10-2024 03:49 PM
I am trying to implement the simple example VI shown below where a DAQmx digital input is saved as a boolean and fed as input to a state machine. My eventual goal is to implement a more sophisticated state machine as a subVI and keep that state machine independent from the DAQmx inputs so that the state machine can be reused in later versions of the overall VI where the input logic will be different.
The hardware DAQ used here is USB-6001. If the digital input changes state while this VI is running, the VI does not see or react to the input change. Please let me know how to fix this.
09-10-2024 05:42 PM - edited 09-10-2024 05:48 PM
Hi mmcgahan,
Your VI is from a newer version of LabVIEW so I cannot open it but one thing that stands out is the inner while loop.
Code should start normally, read first element normally BUT then its value goes into the second while loop that keep running as fast as possible with nothing telling it to stop. So, your code must be getting stuck in the second while loop.
To fix it, remove internal while loop. Move out your shift registers to the outer while loop. Add a wait time in the outer while loop, 100ms. Have a stop button for outer while loop that allows you to close it when you wish to.
EDIT:
If you want to incorporate a state machine, start with using cases inside the main while loop. Before completion of each iteration of while loop, you get to pick which case should get triggered next or if it should stay the same. You should be able to use your existing control.
X
09-11-2024 10:42 AM
Thanks, I will try what you suggest. But I have some questions to make sure I understand. You make this statement -- "If you want to incorporate a state machine, start with using cases inside the main while loop." When you say "main while loop" here, do you mean the outer one? If I move the state machine to the outer loop, it seems to me that flattens the design in a way that defeats my goal of separating the inputs and the state machine by calling state machine hierarchically as a subVI within the loop that includes the DAQmx reads.
Are you saying that that sort of hierarchical design is not possible here?
Mark
09-11-2024 10:56 AM - edited 09-11-2024 11:13 AM
Hi mmcgahan,
Yes,sorry, that is confusing.
Please check this VI snippet to better understand what I was saying.
Edit: Added one more case if you want to add event structure to your code.
If you download--->drag--->drop the VI snippet on the block diagram, you will be able to see all the cases.
I hope this helps.
What do you mean by hierarchical design? Do you mean a consumer producer design? If yes, then check this out: Producer/Consumer Architecture in LabVIEW - NI
How you can add that in the code above:
X
09-11-2024 11:43 AM
Regarding what I mean by hierarchical design, my goal is to implement the state machine as a subVI that is called within the top level VI that contains the inputs that get fed to the state machine. The block diagram below shows what I mean. Here the state machine is a subVI inside the outer loop. That is why I did not start with a flat design where the inputs and the state machine are all at the same level.
Thanks, Mark
09-11-2024 11:57 AM - edited 09-11-2024 11:58 AM
Okay, it still sounds like you need producer consumer architecture/ design.
You can do something like this:
- A top level VI (holds two subVIs)
- First subVI is producer (produces/ collects data)
- Second subVI is consumer (consumes/ utilizes data coming from producer)
This will be your producer (more or less).
Thanks, Mark
Your subVI with state machine will be the consumer. Then they both will be placed on a top level VI, as I attempted to show in the image I attached above.
Also, please check the link in my previous reply.
X
09-11-2024 12:16 PM
check this out.
09-11-2024 01:35 PM
Thanks. I will look into the producer/consumer design pattern.