LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping the VI when running a infinite simulation loop

Hi,

This is my first time on this forum and for that matter, I started with Labview a few months back. I am developing a standalone application for servo motor control through USB 6211. The motor control was completed and I created a DLL which I could run through VC++. My application requires me to call this DLL or an EXE based on this VI repeatedly with direction, velocity and angle parameters and the remainder of the program depends on the finishing of this executable.

The issue was that the VI did not stop execution after the motor was turned off, I suppose due to the simulation loop. I tried using the abort execution block but was advised to avoid doing so. My next step was to move all the DAQ assistant blocks into a while loop and couple the motor ON/OFF control with the stop button. But this hasn't helped either. I am attaching the VI and the SubVI here. I went through the board but did not come across a query involving a simulation loop. Any suggestions?
Download All
0 Kudos
Message 1 of 6
(4,414 Views)

Hi Vivek!

 

Thank you for contacting National Instruments.  From the information you have provided here, along with the attached VIs, I would agree that it is the simulation loop that is causing the problems when stopping the VI.  It looks like you are using the LabVIEW Simulation Module. 

 

When using these loops there are two primary ways of stopping their execution.  The total simulation time can be controlled from the input node, the box at the upper left of the loop, or the Halt Simulation VI can be used from within the Utilities palette.  I would suggest taking a look at the detailed help for the simulation loop in order to better understand the methods of stopping this execution.  As you mentioned it is always good programming practice to avoid using the abort button because this can result in open references being left without any programmatic resolution.

 

I hope this helps!  Let me know if there is anything else I can help with or clarify.  Have a great day!

 

Jason W.

National Instruments
Applications Engineer
0 Kudos
Message 2 of 6
(4,368 Views)
Hi Jason,

Thanks a lot. Yes the halt simulation block helped me stop the VI. But I have encountered another problem, this time involving the DLL. The DLL executes the motor operation correctly but it does not kill the cmd.exe process on its own after finishing. I have looked at the options in vc++ but it seems to be clean on that front. Is there some setting that has to be taken care of while building the DLL to avoid this issue? Thanks once again for your help.

Best,

Vivek
0 Kudos
Message 3 of 6
(4,365 Views)

Hi Vivek,

Are you using a VC++ program to invoke a dll created in LabVIEW. If so, you should probably be using the LoadLibrary method (http://msdn2.microsoft.com/en-us/library/ms684175.aspx) to call your dll. It seems to me that you might be using the CreateProcess method (http://msdn2.microsoft.com/en-us/library/ms682425.aspx) as this typically uses the command line to launch executables.

If you use the LoadLibrary method, then you donot have to deal with the command line as you can directly get a handle to the apporpriate function in your dll. If you are using the CreateProcess method then there are a couple of ways in which you can deal with the command line.

1. Specify CREATE_NO_WINDOW as one of the dwCreationFlags in the in the CreateProcess function. (http://msdn2.microsoft.com/en-us/library/ms684863.aspx). If there are already other flags in that argument then you need to 'or' them together.

2. Launch the command line in the CreateProcess function by using the /C option. For eg: cmd.exe /C

3. Run the exit command in the current console after the executable.

Also, you can refer to this Knowledge Base article: http://digital.ni.com/public.nsf/allkb/0E686E97C3A65EA8862565F60052A706?OpenDocument

Let me know if this helps.

Jaidev Amrite

National Instruments

 

0 Kudos
Message 4 of 6
(4,333 Views)
Hello Jaidev,

I am sorry that I wasn't able to reply sooner. Actually we are calling the function directly from the C code, using header header file created by labview and linking using .lib file created while making dll. The called function in dll executes correctly but the program never exits completely (maybe due to lingering threads / processes created by the vi execution). The methods suggested by you didn't feature and was wondering if there was some other way to use the dll. Thanks again,

Vivek
0 Kudos
Message 5 of 6
(4,301 Views)

Hi Vivek,

It looks like you are calling the DLL right.  You should debug your program to see if there is a loop that doesnt stop executing after doing its job. This might be a loop in the DLL. So i suggest looking at the LabVIEW code as well.

Jaidev 

Senior Product Manager
National Instruments
0 Kudos
Message 6 of 6
(4,269 Views)