DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

abort script using Labview Diadem toolkit

I have a situation where I need to abort a script that was initiated by my LabVIEW software.
 
I have attached a sample VI that should stop a script.  The VI starts a script running that will never end.  This is done async.
 
Later the user can press the button and issue a command to stop the script.  Other threads have suggested "autoquit" and the help recommends "err.raise"
 
However, I find that the command is ignored until I halt the script in Diadem. I use the ESC key to do this.
 
Is there a way to stop a script execution using LV<>DD toolkit?
 
Jim West
Summitek Instruments
0 Kudos
Message 1 of 4
(4,537 Views)

Hi Jim,

It's good to hear from you.  Unfortunately, there's no way to kill a running script in VBS through the ActiveX server, because DIAdem has a script stack.  The VI can choose to run the script asynchronously as far as LabVIEW is concerned, but there is only one synchronous script stack in DIAdem, so a second ActiveX command has to wait until the first one has completed before DIAdem will run it.

You need to add polling to the VBScript, and you need to poll semthing that the DIAdem script can read from and which LabVIEW can write to without using the ToCommand ActiveX server.  A registry key or environment variable or just a plain old ASCII file would all fit the bill.

Here's the VI I used to test that my understanding of the script stack is correct-- note that this VI does NOT succeed in killing the running VBScript.

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 4
(4,523 Views)

Hello Brad!

I don't like to correct you but I have to Smiley Wink

While a script is running it is possible to use the ToCommand interface. There are no restrictions in setting variables. Assuming you have a script running in DIAdem like this:

Option Explicit
 
B1 = false
 
Do While not B1
  Pause 0.5
Loop
 
MsgBox "Finished"

You can change the B1 value via OLE. I can't test it with LabVIEW but you can use this script in Windows (outside of DIAdem) to test:

Option Explicit
 
Dim oDIAdem
 
Set oDIAdem = CreateObject("DIAdem.ToCommand")
 
Call oDIAdem.BoolVarSet("B1", true)

Or is there a limitation in the VI?

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 3 of 4
(4,518 Views)

Hi Matthias,

Well, that's exactly what I thought I had tried in the example I posted that I said did not work, except that I used T1 istead of B1.  But now that I look at your code closer, and try it out in a Windows VBScript on my machine, I now see my mistake.  The "___VarSet()" methods do indeed run asynchronously even while DIAdem is running a VBScript.  In the VI I posted yesterday, I had used "CmdExecuteAsync()" instead of "TextVarSet()" or "BoolVarSet()" to test my understanding of DIAdem's script stack.

It turns out you are completely correct.  The "___VarSet()" methods work just fine.  I still believe that the "CmdExecute___()" methods load up the DIAdem script stack and that the script stack executes sequentially, but the "BoolVarSet()" method you suggested is the ideal way to accomplish Jim's request, even if it does require polling within the running VBScript.  If it turns out that the DIAdem script stack does not execute sequentially, regardless of whether you use the "CmdExecuteSynch()" or "CmdExecuteAsync()" methods, please let me know.  My understanding is that the "Sync" or "Async" methods merely designate whether the command returns immediately in the calling language (C, LabVIEW, etc.), but has NO BEARING on how the commands are executed in DIAdem-- I believe these comands are always executed synchronously in DIAdem.  This is what I refer to as the DIAdem script stack, the list of all commands waiting to execute sequentially which have been requested through ToCommand.

I rebuilt the VI using Matthias' approach, and now it works in both DIAdem 10.2 and 11.0 Beta2.

Thanks Matthias,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 4
(4,491 Views)