aboutsummaryrefslogtreecommitdiffstats
path: root/micropython/main.py
blob: dc6178cdebbf9166d6b85719c489d2a53c2c90fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
print("main.py")
import machine, gc, sys

# Start the pyprofibus application.
# Modify this to your needs.
# This function should never return. If it does nevertheless, a reboot is attempted.
def start_pyprofibus():
	print("Starting pyprofibus...")

	# Start dummy example that uses virtual bus hardware.
	import example_dummy_oneslave
	example_dummy_oneslave.main(confdir="examples", watchdog=watchdog) # Run main loop
	return

	# Start the S7-312-2DP example.
	#import example_s7_315_2dp
	#example_s7_315_2dp.main(confdir="examples", watchdog=watchdog) # Run main loop
	#return

	# Start the ET200S example.
	#import example_et200s
	#example_et200s.main(confdir="examples", watchdog=watchdog) # Run main loop
	#return


# Main execution loop.
# This runs start_pyprofibus and does its best to catch exceptions.
count = 0
while True:
	try:
		count += 1
		gc.collect()
		start_pyprofibus()
	except KeyboardInterrupt as e:
		raise e
	except Exception as e:
		try:
			print("FATAL exception:")
			sys.print_exception(e)
		except: pass
	except: pass
	try:
		if count >= 5:
			count = 0
			machine.reset()
	except: pass
bues.ch cgit interface