Namespaces | Functions
di.py File Reference

DI Sample More...

Go to the source code of this file.

Namespaces

 di
 

Functions

def main ()
 

Detailed Description

DI Sample

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

Definition in file di.py.