soft_tim.py 482 B

1234567891011121314151617181920212223
  1. from PikaStdDevice import Timer
  2. import time
  3. tim = Timer()
  4. cb_times = 0
  5. def cb_test(signal):
  6. global cb_times
  7. if cb_times > 0:
  8. return
  9. cb_times += 1
  10. print("cb_test: signal = %d, cb_times = %d" % (signal, cb_times))
  11. tim.setCallback(cb_test, Timer.SIGNAL_ANY)
  12. tim.setId(-1) # -1 means soft timer
  13. tim.setPeriod(100) # 100ms
  14. tim.enable()
  15. while True:
  16. time.sleep(1)
  17. print("cb_times = %d" % cb_times)
  18. if cb_times >= 1:
  19. tim.close()
  20. break