base_disable.py
1 """ 2 Example: Base Disable 3 4 This example shows how use the disable method in a try/except clause to turn 5 off output modules in the case of an unexpected error. 6 7 Discrete ouputs are any output that is only ON or OFF such as a relay. 8 This example works with all P1000 Series: 9 - Discrete ouput modules such as P1-08TRS, P1-08TD1, P1-16TR, etc. 10 - Discrete combo modules such as P1-15CDD1, P1-15CDD2, P1-16CDR, etc. 11 12 This example will toggle channel 2 of slot 1 on and off 4 times and then trigger 13 an error at which point it will turn off the output. 14 _____ _____ 15 | P || S | 16 | 1 || L | 17 | A || O | 18 | M || T | 19 | - || | 20 | 2 || 0 | 21 | 0 || 1 | 22 | 0 || | 23 ¯¯¯¯¯ ¯¯¯¯¯ 24 Written by FACTS Engineering 25 Copyright (c) 2023 FACTS Engineering, LLC 26 Licensed under the MIT license. 27 """ 28 29 import time 30 import P1AM 31 import traceback 32 33 def main(base): 34 35 output = base[1][2] # set output object to slot 1 channel 2 36 for i in range(4): # blink 4 times 37 output.value = 0 # off 38 time.sleep(1) 39 output.value = 1 # on 40 time.sleep(1) 41 42 import this_module_doesnt_exist # force an import error error 43 44 45 try: 46 base = P1AM.Base() # init base object 47 main(base) # call our main function 48 except Exception as e: # if our main function throws an exception 49 traceback.print_exception(e) # print out the error 50 base.deinit() # disable the base and turn off outputs 51 52 while True: 53 pass