Functions
do Namespace Reference

Functions

def main ()
 

Detailed Description

Copyright (C) 2019 Moxa Inc. All rights reserved.
SPDX-License-Identifier: Apache-2.0

DO Python Sample Application

Date          Author            Comment
2019-02-11    William Chang     Created it.

Function Documentation

◆ main()

def do.main ( )

Definition at line 26 of file do.py.

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