The luascript record (https://github.com/epics-modules/lua) makes this pretty simple. Your record would look
like:
record(luascript, NAME)
{
field(SCAN, "1 second")
field(OOPT, "Transition to Non-zero")
field(CODE, "@script.lua timecheck()")
field(OUT, "RECORD_TO_PROCESS.PROC")
}
and then have a file "script.lua" either in the IOC's startup directory or in any directory specified by the environment variable LUA_SCRIPT_PATH. The file would have a function timecheck that looks like so:
function timecheck()
-- Get the current time as a table of information
local curr_time = os.date("*t")
-- Check for your target time (HOURS is in 24-hour format)
if (curr_time.hour == HOURS and curr_time.min == MINUTES and curr_time.sec == SECONDS) then
return 1
end
return 0
end
Every second the luascript record processes and checks the time, if it's the time you specified, the record's VAL field gets set to 1 and that value gets sent to the PROC field of the record you want to process at that
point. If you have multiple fields to process at various times, you can use the same script and just send the time values as parameters like so:
record(luascript, OneThirtyRecord)
{
field(SCAN, "1 second")
field(OOPT, "Transition to Non-zero")
field(CODE, "@script.lua timecheck(1,30,0)")
field(OUT, "RECORD_TO_PROCESS_1.PROC")
}
record(luascript, TwoThirtyRecord)
{
field(SCAN, "1 second")
field(OOPT, "Transition to Non-zero")
field(CODE, "@script.lua timecheck(2,30,0)")
field(OUT, "RECORD_TO_PROCESS_2.PROC")
}
function timecheck(hours, minutes, seconds)
-- Get the current time as a table of information
local curr_time = os.date("*t")
-- Check for your target time (HOURS is in 24-hour format)
if (curr_time.hour == hours and curr_time.min == minutes and curr_time.sec == seconds) then
return 1
end
return 0
end
Good Day,
I tend to avoid cron job on the control system since I don't know that it is *guaranteed* to run, and at specified time - though it usually does. Even though crontab is a great tool, it isn't a control system tool,
so my preference is to avoid it (except for say, booting a control system).
I implemented a calc record that uses inputs from the devIocStats (synapps) to get the second, minute, and hour, and compare them with your desired values and make the Val=1 if equal, which is essentially what you want.
If you connect that to the SDIS of a fanout and process the fanout every 1/2 second then you will get a single process signal output, at the time of day you specify (because usually it's disabled).
You can do the same thing but only use seconds, and minutes for something that happens every hour, and likewise for month and day. Sometimes I want to process a record, but only once every 10 minutes.
Cheers
James Larsson
Hi Michael,
I have a cron job that runs once a day that resets the value of several records by
running cau (with an input file). If you don't find a record that can be made to do
that I'm sure you can adapt the cron job idea.
Maren Purves, EAO/JCMT