Namespaces | Functions
do.py File Reference

DO Sample More...

Go to the source code of this file.

Namespaces

 do
 

Functions

def main ()
 

Detailed Description

DO 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  DO 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="DO sample program.")
26  parser.add_argument("-s", "--slot", dest="do_slot", type=int, default=1)
27  parser.add_argument("-c", "--channel", dest="do_channel", type=int, default=0)
28  args = parser.parse_args()
29 
30  do_slot = args.do_slot
31  do_channel = args.do_channel
32  do_count = 1
33  do_mode = [0] * do_count
34  do_values = 0
35  print("DO slot = {}".format(do_slot))
36  print("DO channel = {}".format(do_channel))
37 
38  # initialize ioThinx I/O
39  device = ioThinx_4530_API.ioThinx_4530_API()
40 
41  # temporarily set config
42  device.ioThinx_DO_Config_SetModes(do_slot, do_channel, do_count, do_mode)
43 
44  # reload config
45  device.ioThinx_IO_Config_Reload()
46  do_values = device.ioThinx_DO_GetValues(do_slot)
47  print("do_values = {}".format(do_values))
48 
49  # set value
50  while True:
51  # invert do value
52  if do_values[do_channel] == 0:
53  do_values[do_channel] = 1
54  else:
55  do_values[do_channel] = 0
56  device.ioThinx_DO_SetValues(do_slot, do_values)
57  print("[ {}:{}] DO value = {}".format(do_slot, do_channel, do_values[do_channel]))
58  if input("Press 'q' to exit. other keys to continue") == 'q':
59  break
60 
61 
62 if __name__ == '__main__':
63  main()

Definition in file do.py.