rtd.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  RTD 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 RTD_SENSOR_TYPE_PT100 = 1
26 
27 
28 def main():
29  parser = argparse.ArgumentParser(description="RTD sample program.")
30  parser.add_argument("-s", "--slot", dest="rtd_slot", type=int, default=8)
31  parser.add_argument("-c", "--channel_start", dest="rtd_channel_start", type=int, default=0)
32  parser.add_argument("-n", "--channel_count", dest="rtd_channel_count", type=int, default=2)
33  args = parser.parse_args()
34 
35  rtd_slot = args.rtd_slot
36  rtd_channel_start = args.rtd_channel_start
37  rtd_channel_count = args.rtd_channel_count
38  print("RTD slot = {}".format(rtd_slot))
39  print("RTD start channel = {}".format(rtd_channel_start))
40  print("RTD channel count = {}".format(rtd_channel_count))
41 
42  # initialize ioThinx I/O
43  device = ioThinx_4530_API.ioThinx_4530_API()
44 
45  # temporarily set config
46  rtd_types = [RTD_SENSOR_TYPE_PT100] * rtd_channel_count
47 
48  device.ioThinx_RTD_Config_SetSensorTypes(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_types)
49 
50  # reload config
51  device.ioThinx_IO_Config_Reload()
52 
53  # get value
54  while True:
55  rtd_values = device.ioThinx_RTD_GetValues(rtd_slot, rtd_channel_start, rtd_channel_count)
56  rtd_statuss = device.ioThinx_RTD_GetStatuss(rtd_slot, rtd_channel_start, rtd_channel_count)
57  for i in range(rtd_channel_count):
58  print("[ {}:{}] value = {}, status = {}".format(rtd_slot, rtd_channel_start + i, rtd_values[i], rtd_statuss[i]))
59  if input("Press 'q' to exit. other keys to continue") == 'q':
60  break
61 
62 
63 if __name__ == '__main__':
64  main()
def main()
Definition: rtd.py:28