LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queued state machine stuck on subVI

Solved!
Go to solution

Hi everyone,

 

i need to develope a test for a board using an Xjtag board, i've already made the code and it works, but i have a problem with a certain feature.

In fact the stop button should stop the process every time i press it and in every moment of the test, however it doesn't do so because during the execution (exe step) the program is stuck inside of the subVI "Xjtag run proj", where the main tests are done.

 

Do you know how can i solve this?

 

prog.png

0 Kudos
Message 1 of 6
(704 Views)
Solution
Accepted by topic author DavideBrusamolino02

As you have noticed, when you have a Project that involves multiple Loops running simultaneously, you need to think about a single process that can interact with each Loop and allow it to stop.  This should generally not involve using the Error Line as a "stop" mechanism (unless, of course, you also manage to create Errors in every loop, which seems silly and confusing).

 

From the small segment of code you chose to show, it is not clear (to me) the (parallel) construction of your Project nor the mechanism(s) in place to handle the parallel loops.  If your Project is contained in its own "Project" folder, it would be much more helpful if you compress the Project folder (right-click the Folder, choose "Send to" and then "Compressed (zipped) folder") and attached the .zip file.

 

Most of my Projects involve parallel loops.  I generally have a "main" Loop that runs a State Machine, and I use a "Wait/Run/Exit" Enum to control the starting, running, and stopping of all the parallel Loops using Tag Channel Wires to send the Enum to the Loops.  Here's an example (picture):

Stopping Parallel Loops.png

 

Bob Schor

0 Kudos
Message 2 of 6
(662 Views)

Thank you for your answer!

 

I will fix the error wire used to stop the loops (usually i don't do this either).

 

I can't put the whole project here though it involves different libraries and needs physical hardware to run.

 

But to answer you question, the major part of the program is shown in the picture, before there is just a setup for the hardware that runs only 1 time when you start the VI and after there is just the release queue and the error handler.

 

The main loop is up with the event structure and down there is the consumer loop where i send the commands through an enum constant (as you said), with idle, exe and close functions, and during the "exe" case the program runs all its tests that are inside the yellow subVI you see there and i cannot stop it pressing "Close"

DavideBrus_0-1681825612186.png

DavideBrus_1-1681825636427.png

 

 

0 Kudos
Message 3 of 6
(658 Views)

If you need to sub vi to be able to stop when you want within 100mS (as an example) then the sub vi needs to check that it is allowed to keep running every 100mS or quicker.  There are many ways of doing this, FGV, User events, etc. 

0 Kudos
Message 4 of 6
(645 Views)

I see you are already using what looks like a Producer/Consumer architecture.

 

It's a small step forward to a similar architecture using Channel Wires. 

 

Then you can have a Event Driven State Machine that runs independently to handle your GUI.

 

I know it looks complicated but it's actually pretty simple if you understand Channel Wires and Queues 

 

Screenshot 2023-04-18 073036.png

 

When the Stop button is pressed the GUI loop sends and Error 5003 to the Control Loop. 

 

The Error Case in the Control Loop then tells the other loops to shut down the test.

========================
=== Engineer Ambiguously ===
========================
Message 5 of 6
(634 Views)

@DavideBrusamolino02 wrote:

The main loop is up with the event structure and down there is the consumer loop where i send the commands through an enum constant (as you said), with idle, exe and close functions, and during the "exe" case the program runs all its tests that are inside the yellow subVI you see there and i cannot stop it pressing "Close"


That's why you need something like a Notifier or (my preference) a Tag Channel Wire that can "burrow" into a parallel process's loop.

Spool Events Exit.png

 

This is the Exit case of the Spool Events loop in the figure I showed.  When it is in the "Run" State, it is getting input from the Messenger Channel (the pink "pipe" (Messenger Channels are analogous to Queues).  The Channel Reader has a 100 ms Timeout, and if it "times out", it exits its Case and runs the surrounding While Loop again, allowing the Tag Channel Reader another chance to see if Exit has been sent (which, as you can see, causes this sub-VI to exit).  In other loops, I've put an explicit "Wait" of 1 to 100 ms before entering the Case Statement, depending on where the timing made more sense.  As these loops are often "Consumers" in a Producer/Consumer pattern, with the Main being the Producer, when the Main stops "producing" and sends the Exit request, the "Consumers" will stop getting requests, their "Queues" will time out, the Run case will finish, and the outer Loop will give the Tag/Notifier a chance to see if an Exit has been requested.

 

Bob Schor

0 Kudos
Message 6 of 6
(626 Views)