di.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  DI 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 
26 def main():
27  parser = argparse.ArgumentParser(description="Counter sample program.")
28  parser.add_argument("-s", "--slot", dest="di_slot", type=int, default=1)
29  parser.add_argument("-c", "--channel", dest="di_channel", type=int, default=0)
30  parser.add_argument("-f", "--filter", dest="di_filter", type=int, default=2)
31  args = parser.parse_args()
32 
33  di_slot = args.di_slot
34  di_channel = args.di_channel
35  di_count = 1
36  di_filter = [args.di_filter] * di_count
37  print("DI slot = {}".format(di_slot))
38  print("DI channel = {}".format(di_channel))
39  print("DI filter = {}".format(di_filter))
40 
41  # initialize ioThinx I/O
42  device = ioThinx_4530_API.ioThinx_4530_API()
43 
44  # temporarily set config
45  device.ioThinx_DI_Config_SetFilters(di_slot, di_channel, di_count, di_filter)
46 
47  # reload config
48  device.ioThinx_IO_Config_Reload()
49 
50  while True:
51  di_values = device.ioThinx_DI_GetValues(di_slot)
52  print("[ {}] di_values = {}".format(di_slot, di_values))
53  print("[ {}:{}] di_val = {}".format(di_slot, di_channel, di_values))
54  if input("Press 'q' to exit. other keys to continue") == 'q':
55  break
56 
57 
58 if __name__ == '__main__':
59  main()
def main()
Definition: di.py:26