LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue on Queued message handler and dynamically load/close subvi

Solved!
Go to solution

Hi, Dear LV users

 

I am learning how to use the Queued Sate machine Architecture. I created a simple project including a "main.vi" to dynamically load a sub vi "sub_Vi2.vi" in the "initialize" case. The sub vi simply open a setting file and load setting to some control and write those values back to the setting file. If the setting file is not created, the sub vi will create it before user close the subvi. 

In the "Exit" case of my "main.vi", I send "true" to the stop button in subvi to stop running it. But the sub vi did not write those values back to the setting file, nor created a new one when I delete the setting file. 

There is another vi I made "main1.vi", which dynamically load and close the subVi. And it work as well as I expected: create the file and write data back!

Can any one help me to understand the code? I also attached the front panel and diagrams and the source code. It is in LV 2012. 

 

Best regards

 

CQ Li 


CQ
Download All
0 Kudos
Message 1 of 12
(3,591 Views)

Just a couple of observations.

 

Clean up that block diagram.  It hurts to look at it, and it distracts from the task at hand if you need to concentrate on following all those criss-crossing wires and wires end up behind other wires.  Besides, in just about every case I've seen, disorganized wires promote disorganized thinking.  But the other way is true, also.  Cleaning up your wires organizes your thoughts.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 12
(3,577 Views)

Hi, Bill

 

thank you very much for your suggestion. I cleaned the block digrams and simplified some functions. Infact, most of the code in "Main.vi" was generated by Labview templete. I only added some portion in "initialize" and "Exit" case in Main.vi. 

 

The strange thing is:

 

Main1.Vi works well: load subvi, create or replace the setting.txt file. Although Main.vi can load subvi, the subvi could not write data back to setting.txt, nor create a new file if setting.txt was not there. 

 

thank you very much. 

 

I reposted the source code too. 

 

Main_ini.png

 

 

"exit" case

Main1.vi

 

sub__Vi.png


CQ
Download All
0 Kudos
Message 3 of 12
(3,536 Views)

I would get rid of sub_vi2.vi and take its sequences and put the first sequence (minus the sequence structure itself) in your init state and your write sequence (minus the sequence structure) in your exit state.  Wire the data directly since you will no longer need the controls to shuttle the data back and forth...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 12
(3,477 Views)

Hi, Bill

 

In fact, the Sub vi was a very simple version of a Vi by third party for controlling some equipment. I hide the controlling part with the while loop. 

 

The puzzle is: in the exit case, the sub vi stops after "true" was sent to its stop button, but the setting file was not replaced/created. But in the Main1.vi, it works fine. 

 

best regards

 

 


CQ
0 Kudos
Message 5 of 12
(3,466 Views)

Your ideas are difficult to follow but  you might want to at least check and see what the IO/ error channel in the subVI might be doing before it closes. Inserting A breakpoint should work even though it is launched dynamically. Just save it with the breakpoint embedded then call it normally. Save it without the breakpoint when its all fixed up.

 

 

Also I don't know if the close method waits for anything before dropping the VI out of Memory. (I still use FP close in 2010) 

 

If close VI method is immediate than it must not be executed too soon in your code scenario.

 

 

0 Kudos
Message 6 of 12
(3,447 Views)

@CQ_Li wrote:

Hi, Bill

 

In fact, the Sub vi was a very simple version of a Vi by third party for controlling some equipment. I hide the controlling part with the while loop. 

 

The puzzle is: in the exit case, the sub vi stops after "true" was sent to its stop button, but the setting file was not replaced/created. But in the Main1.vi, it works fine. 

 

best regards

 

 


LOL - sorry that I didn't recognize that.  I was wondering why absolutely nothing was going on inside that VI.  That's a neat way of incorporating a standalone VI into your code.  I see nothing wrong with the implementation of main1.vi, actually.  If I was being nitpicky, I would say replace the polling of the stop button with an event structure, but is it really worth the effort for something so simple?  Unless this is kind of like a "self-training exercise" (I do this a lot to solidify my understanding of new methodds of doing things) to try to implent a QMH architecture, I see no problem using the main1 method.

 

[edit] This is a great day for me to not read things thorughly.  Sorry, you ARE trying to learn!  Sorry  😞  [/edit]

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 12
(3,442 Views)

Hi,  Bill

 

yes, you are right. it is a self training. I also want to check if my idea of stopping a Vi by "sending command" outside of it works or not with QMH. 

 

 


CQ
0 Kudos
Message 8 of 12
(3,436 Views)

Finally I think I figured out how to do it. Will do more test on it 


CQ
0 Kudos
Message 9 of 12
(3,433 Views)

@CQ_Li wrote:

Finally I think I figured out how to do it. Will do more test on it 


I'm sorry I ended up being more of a distraction than a help this time.  😞

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 12
(3,429 Views)