- Main
- Tutorials
- Library
- Samples

- File List
- Globals

relay.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 Relay 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="Relay sample program.")
28 parser.add_argument("-s", "--slot", dest="relay_slot", type=int, default=6)
29 parser.add_argument("-c", "--channel", dest="relay_channel", type=int, default=3)
30 args = parser.parse_args()
31
32 relay_slot = args.relay_slot
33 relay_channel = args.relay_channel
34 relay_values = 0
35 print("Relay slot = {}", relay_slot)
36 print("Relay channel = {}", relay_channel)
37
38 # initialize ioThinx I/O
39 device = ioThinx_4530_API.ioThinx_4530_API()
40 relay_values = device.ioThinx_Relay_GetValues(relay_slot)
41 print(relay_values)
42
43 # set value
44 while True:
45 # invert relay value
46 relay_values[relay_channel] = 0 if relay_values[relay_channel] == 1 else 1
47
48 device.ioThinx_Relay_SetValues(relay_slot, relay_values)
49 print("[ {}:{}] relay value = {}".format(relay_slot, relay_channel, relay_values))
50
51 relay_count = device.ioThinx_Relay_GetCurrentCounts(relay_slot, relay_channel, 1)
52 print("[ {}:{}] relay count = {}".format(relay_slot, relay_channel, relay_count))
53 if input("Press 'q' to exit. other keys to continue") == 'q':
54 break
55
56
57 if __name__ == '__main__':
58 main()
relay.main
def main()
Definition: relay.py:26
format
char const int const cJSON_bool format
Definition: cJSON.h:161