Functions
counter Namespace Reference

Functions

def main ()
 

Detailed Description

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

Counter Python Sample Application

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

Function Documentation

◆ main()

def counter.main ( )

Definition at line 29 of file counter.py.

29 def main():
30  parser = argparse.ArgumentParser(description="Counter sample program.")
31  parser.add_argument("-s", "--slot", dest="di_slot", type=int, default=11)
32  parser.add_argument("-c", "--channel_start", dest="counter_channel_start", type=int, default=0)
33  parser.add_argument("-n", "--channel_count", dest="counter_channel_count", type=int, default=2)
34  args = parser.parse_args()
35 
36  di_slot = args.di_slot
37  counter_channel_start = args.counter_channel_start
38  counter_channel_count = args.counter_channel_count
39  print("DI slot = {}".format(di_slot))
40  print("Counter start channel = {}".format(counter_channel_start))
41  print("Counter channel count = {}".format(counter_channel_count))
42 
43  # initialize ioThinx I/O
44  device = ioThinx_4530_API.ioThinx_4530_API()
45 
46  # temporarily set config
47  di_modes = [DI_MODE_COUNTER] * counter_channel_count
48  device.ioThinx_DI_Config_SetModes(di_slot, counter_channel_start, counter_channel_count, di_modes)
49 
50  counter_triggers = [CNT_TRIGGER_BOTH] * counter_channel_count
51  device.ioThinx_DI_Config_SetCntTriggers(di_slot, counter_channel_start, counter_channel_count, counter_triggers)
52  counter_values = [0] * counter_channel_count
53  device.ioThinx_DI_Config_SetCntValues(di_slot, counter_channel_start, counter_channel_count, counter_values)
54 
55  # reload config
56  device.ioThinx_IO_Config_Reload()
57 
58  # start counter
59  counter_start = [0] * 4
60  for i in range(counter_channel_start, counter_channel_start + counter_channel_count):
61  counter_start[i] = 1
62  device.ioThinx_DI_SetCntStarts(di_slot, counter_start)
63 
64  # get value
65  while True:
66  counter_values = device.ioThinx_DI_GetCntValues(di_slot, counter_channel_start, counter_channel_count)
67  for i in range(counter_channel_count):
68  print("[ {}:{}] counter = {}".format(di_slot, counter_channel_start + i, counter_values[i]))
69 
70  if input("Press 'q' to exit. other keys to continue") == 'q':
71  break
72 
73 
def main()
Definition: misc.py:32