04-26-2017 02:58 AM
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 🙂
Solved! Go to Solution.
04-26-2017 07:23 AM - edited 04-26-2017 07:28 AM
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.
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
04-27-2017 04:17 AM
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".
04-27-2017 07:34 AM
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
04-27-2017 11:22 AM - edited 04-27-2017 11:24 AM
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.
04-28-2017 02:56 AM
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.
05-05-2017 08:57 AM
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 !
05-05-2017 09:23 AM
You're welcome. Thanks for the feedback!