main.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. print("main.py")
  2. import machine, gc, sys
  3. # Start the pyprofibus application.
  4. # Modify this to your needs.
  5. # This function should never return. If it does nevertheless, a reboot is attempted.
  6. def start_pyprofibus():
  7. print("Starting pyprofibus...")
  8. # Start dummy example that uses virtual bus hardware.
  9. import example_dummy
  10. example_dummy.main(watchdog=watchdog) # Run main loop
  11. return
  12. # Start the S7-312-2DP example.
  13. #import example_s7_315_2dp
  14. #example_s7_315_2dp.main(watchdog=watchdog) # Run main loop
  15. #return
  16. # Start the ET200S example.
  17. #import example_et200s
  18. #example_et200s.main(watchdog=watchdog) # Run main loop
  19. #return
  20. # Main execution loop.
  21. # This runs start_pyprofibus and does its best to catch exceptions.
  22. count = 0
  23. while True:
  24. try:
  25. count += 1
  26. gc.collect()
  27. start_pyprofibus()
  28. except KeyboardInterrupt as e:
  29. raise e
  30. except Exception as e:
  31. try:
  32. print("FATAL exception:")
  33. sys.print_exception(e)
  34. except: pass
  35. except: pass
  36. try:
  37. if count >= 5:
  38. count = 0
  39. machine.reset()
  40. except: pass