Will it work Timer
? This form Timer
calls your function in Task
, so you need to periodically call control from your main loop to allow the timer task to run. You can get by calling yield
, sleep
, wait
or doing the IO, here I show waiting on the timer.
tstart = time()
ncalls = 0
read_modbus() = (global ncalls+=1;@show (time()-tstart)/ncalls,ncalls)
t=Timer((timer)->read_modbus(),0,0.25)
while true
wait(t)
println("mainloop $ncalls")
end