LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI does not respond to DAQmx input change while running

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.

mmcgahan_0-1726000718828.png

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.

Download All
0 Kudos
Message 1 of 8
(236 Views)

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

Message 2 of 8
(212 Views)

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

0 Kudos
Message 3 of 8
(153 Views)

Hi mmcgahan,

 

Yes,sorry, that is confusing. 

 

Please check this VI snippet to better understand what I was saying. 

 

State machine.png

Edit: Added one more case if you want to add event structure to your code.

State machine.png

 

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:

Producer Consumer.png

 

X 

Message 4 of 8
(143 Views)

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.

mmcgahan_0-1726072791954.png

 

Thanks, Mark

 

0 Kudos
Message 5 of 8
(119 Views)

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)

Xonmyth_0-1726073652771.png

This will be your producer (more or less).


mmcgahan_0-1726072791954.png

 

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

0 Kudos
Message 6 of 8
(114 Views)
0 Kudos
Message 7 of 8
(108 Views)

Thanks. I will look into the producer/consumer design pattern.

0 Kudos
Message 8 of 8
(93 Views)