hsc_inhibit_counting.py
1 """ 2 Example: hsc_inhibit_counting 3 4 This example shows how to set a counter to stop counting based on the state of one 5 of the hsc inputs of the of the P1-02HSC 6 7 This example works with the P1-02HSC 8 9 This example will print the value of each input every second and whether the channel 10 is actively being inhibited. 11 12 _____ _____ 13 | P || S | 14 | 1 || L | 15 | A || O | 16 | M || T | 17 | - || | 18 | 2 || 0 | 19 | 0 || 1 | 20 | 0 || | 21 ¯¯¯¯¯ ¯¯¯¯¯ 22 Written by FACTS Engineering 23 Copyright (c) 2023 FACTS Engineering, LLC 24 Licensed under the MIT license. 25 26 """ 27 28 import time 29 import P1AM 30 31 base = P1AM.Base() 32 hsc = base[1] # P1-02HSC module in slot 1 33 cnt1 = hsc[1] # Channel 1 34 cnt2 = hsc[2] # Channel 2 35 36 cnt1.inhibit_on_input = "3in" # Inhibit counting when 3in input is high 37 cnt2.inhibit_on_input = "2z" # Inhibit counting when 2z input is high 38 39 hsc.update_settings() # Write settings to module 40 41 last_time = time.monotonic() 42 while True: 43 if time.monotonic() - last_time > 1: 44 if cnt1.inhibit_active: 45 print("cnt1 is being inhibited") 46 print(f"cnt1 position = {cnt1.position}") 47 48 if cnt2.inhibit_active: 49 print("cnt2 is being inhibited") 50 print(f"cnt2 position = {cnt2.position}\n") 51 last_time = time.monotonic() 52