/ examples / module_configuration.py
module_configuration.py
 1  """
 2  	Example: Module Configuration
 3   
 4   This example shows how to configure modules.
 5   Configuration is written to a module to change things such as:
 6   - number of active channels
 7   - type of input e.g. thermocouple type
 8   - input or output range
 9   
10   This example works with all P1000 Series:
11    - Analog input modules that can be configured such as P1-04ADL-1, P1-04ADL-2, etc.
12    - Other modules that can be configured
13    
14    This example will configure channel 1 of a P1-04AD to the 0-10V sensing range. 
15    Afterwards it will print the configuration status to the serial terminal and then the
16    converted units from each channel.
17   
18   Configuration data for P1000 modules can be found on https://facts-engineering.github.io/config.html 
19     _____  _____ 
20    |  P  ||  S  |
21    |  1  ||  L  |
22    |  A  ||  O  |
23    |  M  ||  T  |
24    |  -  ||     |
25    |  1  ||  0  |
26    |  0  ||  1  |
27    |  0  ||     |
28     ¯¯¯¯¯  ¯¯¯¯¯ 
29  	Written by FACTS Engineering
30  	Copyright (c) 2023 FACTS Engineering, LLC
31  	Licensed under the MIT license.
32  
33  """
34  
35  import time
36  import P1AM
37  
38  base = P1AM.Base() # Intializes base. Returns the base object.
39  module = base[1] # module object for slot 1
40  
41  # Config module channel 1 sensing to 0-10V, channels 2-4 be the default of 0-20mA
42  module.configure_module((0x40, 0x03, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x21, 
43                           0x03, 0x00, 0x00, 0x22, 0x03, 0x00, 0x00, 0x23, 0x03))
44  
45  print(module.current_config) # Print current config
46  
47  while True:
48  	# Loop through channel reals
49      for idx, real in enumerate(module.reals):
50          print(f"Channel {idx + 1} is reading {real} units")
51      time.sleep(.5)