- Main
- Tutorials
- Library
- Samples

- File List
- Globals

do.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 DO 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="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
64 if __name__ == '__main__':
65 main()
do.main
def main()
Definition: do.py:26
format
char const int const cJSON_bool format
Definition: cJSON.h:161