ai.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 2019 Moxa Inc. All rights reserved.
3  SPDX-License-Identifier: Apache-2.0
4 
5  AI Python Sample Application
6 
7  Date Author Comment
8  2019-02-11 William Chang Created it.
9 '''
10 
11 
21 
22 from ioThinx_4530 import ioThinx_4530_API
23 import argparse
24 
25 AI_RANGE_4_20mA_BURNOUT = 3
26 
27 
28 def main():
29  parser = argparse.ArgumentParser(description="AI sample program.")
30  parser.add_argument("-s", "--slot", dest="ai_slot", type=int, default=1)
31  parser.add_argument("-c", "--channel_start", dest="ai_channel_start", type=int, default=0)
32  parser.add_argument("-n", "--channel_count", dest="ai_channel_count", type=int, default=8)
33  args = parser.parse_args()
34 
35  ai_slot = args.ai_slot
36  ai_channel_start = args.ai_channel_start
37  ai_channel_count = args.ai_channel_count
38  print("AI slot = {}".format(ai_slot))
39  print("AI start channel = {}".format(ai_channel_start))
40  print("AI channel count = {}".format(ai_channel_count))
41 
42  # initialize ioThinx I/O
43  device = ioThinx_4530_API.ioThinx_4530_API()
44 
45  # temporarily set config
46  ai_ranges = [AI_RANGE_4_20mA_BURNOUT] * ai_channel_count
47  device.ioThinx_AI_Config_SetRanges(ai_slot, ai_channel_start, ai_channel_count, ai_ranges)
48  ai_burnouts = [2.0] * ai_channel_count
49  device.ioThinx_AI_Config_SetBurnoutValues(ai_slot, ai_channel_start, ai_channel_count, ai_burnouts)
50 
51  # reload config
52  device.ioThinx_IO_Config_Reload()
53 
54  # get value
55  while True:
56  ai_engs = device.ioThinx_AI_GetEngs(ai_slot, ai_channel_start, ai_channel_count, )
57  ai_statuss = device.ioThinx_AI_GetStatuss(ai_slot, ai_channel_start, ai_channel_count, )
58  for i in range(ai_channel_count):
59  print("[ {}:{}] eng = {}, status = {}".format(ai_slot, ai_channel_start + i, ai_engs[i], ai_statuss[i]))
60  if input("Press 'q' to exit. other keys to continue") == 'q':
61  break
62 
63 
64 if __name__ == '__main__':
65  main()
def main()
Definition: ai.py:28