DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Running a script periodically

Solved!
Go to solution

Hi,

I'd like to run a script in DIAdem periodically, for example everyday at 8 am.

I already tried things like :

while Time <> 08:00:00

  '-- Do Nothing

wend

And then i write the script i want to execute.

It does run the script at 8, but after that i have to press "run" again, and DIAdem is blocked because of an "infinite" loop until 8 am.

So, i'd like to run a script at 8am, but without having anything to press or blocking DIAdem.

Every trick is welcome 🙂

0 Kudos
Message 1 of 8
(3,400 Views)

Hi Romain,

There are two possible solutions that I can think of:

1. Open a non modal SUD dialog and include your timing loop there. As long as the dialog is open DIAdem will not be "blocked". You can continue working in DIAdem or run other scripts meanwhile. You could also hide the non modal dialog, so it's not visible at all but can trigger other actions in the background.

http://zone.ni.com/reference/en-XX/help/370858M-01/procsud/procsud/procsud_nonmodal/

2. Create a worker that runs in the background and triggers any actions in the master application.

http://zone.ni.com/reference/en-XX/help/370858M-01/parallelprocesscontrol/objects/parallelprocesscon...

 

Here's an example of how to realize the time detection:

dim EventOccurred
do while true
    EventOccurred = StrComp(Str(CurrDateTimeReal,"#hh:nn:ss"), "10:28:10") = 0
    call LogfileWrite(EventOccurred)
    call Pause(0.1)
loop

In this example you would need something like an additional "edge detection", so your event does not occurr multiple times for the same second.

Regards

Christian
CLA, CTA, CLED
Message 2 of 8
(3,363 Views)

Thanks for your help ! I chose to use the non modal SUD dialog solution, but what do you mean with "you would need something like an additional edge detection" ?

The time detection you gave me works fine, but as you said it occurs too many times in the same second, ad DIAdem is still "blocked".

0 Kudos
Message 3 of 8
(3,335 Views)

Hey Romain,

Here's one possible solution:

dim EventOccurred, Edge, EventCount
const EventTime = "14:31:10"

Edge = false
EventCount = 0
do while true
	'check if current time is equal to event time
	if not Edge and StrComp(Str(CurrDateTimeReal,"#hh:nn:ss"), EventTime) = 0 then
		'set to true to prevent event to occurr more than once for the same second
		Edge = true
		'increment event counter
		EventCount = EventCount + 1
		'call event handler which can also be a user command
		call EventHandler("Event no. " & EventCount)
	'if current second is over, reset edge detection variable
	elseif Edge and StrComp(Str(CurrDateTimeReal,"#hh:nn:ss"), EventTime) <> 0 then
		Edge = false
	end if
	'wait time here prevents high CPU load
	call Pause(0.1)
loop

sub EventHandler(parameter)
	call LogFileWrite(parameter)
end sub

If you put this in a non modal dialog it would make sense to call a user command as event handler.

Regards

Christian
CLA, CTA, CLED
0 Kudos
Message 4 of 8
(3,321 Views)

I just realized that it will not work with a non modal dialog as the loop is running continuously in the dialog and blocking DIAdem like you said. Sorry about the misunderstanding.

But I tested my previous script successfully in a worker and I think that is the only possible solution right now as a worker is not blocking the main DIAdem instance.

Christian
CLA, CTA, CLED
0 Kudos
Message 5 of 8
(3,305 Views)
Solution
Accepted by topic author Romain.P

Find an example attached. It uses a worker that's running in the background and calls a user command of the master application every minute.

Christian
CLA, CTA, CLED
Message 6 of 8
(3,292 Views)

Hi Christian,

Thanks a lot, your script runs perfectly, the time event doesn't block DIAdem anymore. You were right about the SUD nonMod Dialog Box, it didn't solve my problem.

I made a few arrangements i your code to let me choose the duration I want between runs thanks to a dialog box, I didn't have any trouble with it.

Thanks again !

0 Kudos
Message 7 of 8
(3,201 Views)

You're welcome. Thanks for the feedback!

Christian
CLA, CTA, CLED
0 Kudos
Message 8 of 8
(3,196 Views)