Versuchs mal mit dieser python Komponente.
1. Code unten als 'interval.py' im gleichen Ordner wie deine .ini Datei abspeichern und als Ausführbare Datei markieren.
Code:
#!/usr/bin/env python3
import time
import hal
h = hal.component("interval")
h.newpin("enable", hal.HAL_BIT, hal.HAL_IN) # HIGH enables the interval timer
h.newpin("reset", hal.HAL_BIT, hal.HAL_IN) # On change LOW->HIGH restarts the interval
h.newpin("start-with-pulse", hal.HAL_BIT, hal.HAL_IN) # If TRUE the interval starts with a pulse
h.newpin("out", hal.HAL_BIT, hal.HAL_OUT) # Output of the the interval timer, LOW if 'enable' is LOW
h.newpin("delay-time", hal.HAL_FLOAT, hal.HAL_IN) # Interval low time in milliseconds
h.newpin("pulse-time", hal.HAL_FLOAT, hal.HAL_IN) # Interval high time in milliseconds
h.newpin("time-elapsed", hal.HAL_FLOAT, hal.HAL_OUT) # Elapsed low/high time in milliseconds
h.ready()
running = False
reset = False
try:
while 1:
if h['enable']:
delay_time = h['delay-time']
pulse_time = h['pulse-time']
if not h['reset']: reset = False
if h['reset'] and not reset:
running = False
reset = True
if not running:
timer = round(time.time()*1000)
running = True
h['out'] = h['start-with-pulse']
else:
h['time-elapsed'] = round(time.time()*1000) - timer
if not h['out'] and round(time.time()*1000) >= timer + delay_time:
h['out'] = True
timer = round(time.time()*1000)
if h['out'] and round(time.time()*1000) >= timer + pulse_time:
h['out'] = False
timer = round(time.time()*1000)
else:
h['out'] = False
h['time-elapsed'] = 0
running = False
except KeyboardInterrupt:
raise SystemExit
2. in der ini unter [HAL] diese Zeilen hinzfügen.
Code:
HALCMD = loadusr -W ./interval.py
HALCMD = setp interval.delay-time 2000
HALCMD = setp interval.pulse-time 500
3. das 'Show HalConfiguration' tool öffnen, im linken Teil die 'interval' Komponente suchen und im 'Watch' tab die pins anzeigen. Dann 'interval.enable' auf True setzen und der Timer sollte laufen. :