soft_tim.py 379 B

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