hsc_rotary.py
1 """ 2 Example: hsc_rotary 3 4 This example shows how to use the rotary setting of the of the P1-02HSC 5 6 This example works with the P1-02HSC 7 8 This example will print the position of each counter every second. 9 10 _____ _____ 11 | P || S | 12 | 1 || L | 13 | A || O | 14 | M || T | 15 | - || | 16 | 2 || 0 | 17 | 0 || 1 | 18 | 0 || | 19 ¯¯¯¯¯ ¯¯¯¯¯ 20 Written by FACTS Engineering 21 Copyright (c) 2023 FACTS Engineering, LLC 22 Licensed under the MIT license. 23 24 """ 25 26 import time 27 import P1AM 28 29 base = P1AM.Base() 30 hsc = base[1] # P1-02HSC module in slot 1 31 cnt1 = hsc[1] # Channel 1 32 cnt2 = hsc[2] # Channel 2 33 34 cnt1.is_rotary = True 35 cnt2.is_rotary = True 36 37 cnt1.rollover_position = 5000 38 cnt2.rollover_position = 1000 39 40 cnt2.positive_polarity = False # Channel 2 counts backwards 41 42 hsc.update_settings() # Write new settings to module 43 44 last_time = time.monotonic() 45 while True: 46 if time.monotonic() - last_time > 1: 47 print(f"Channel 1 position is {cnt1.position}") 48 print(f"Channel 2 position is {cnt2.position}") 49 last_time = time.monotonic()