misc.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  Miscellaneous 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 LED_CHANNEL_U1 = 1
26 LED_CHANNEL_U2 = 2
27 LED_STATE_DARK = 0
28 LED_STATE_GREEN = 1
29 LED_STATE_RED = 2
30 
31 
32 def main():
33  parser = argparse.ArgumentParser(description="Miscellaneous sample program.")
34  parser.add_argument("-s", "--slot", dest="module_slot", type=int, default=1)
35  args = parser.parse_args()
36 
37  # initialize ioThinx I/O
38  misc_slot = 0
39  module_slot = args.module_slot
40  device = ioThinx_4530_API.ioThinx_4530_API()
41 
42  # module infomation
43  module_count = device.ioThinx_Misc_GetModuleCount()
44  print("Module count = {}".format(module_count))
45  print("Module slot = {}".format(module_slot))
46 
47  module_info = device.ioThinx_Misc_GetModuleInfo(module_slot)
48  print("Slot {} Module Information:".format(module_slot))
49  print("Model Name: {}".format(module_info["model_name"]))
50  print("Serial Number: {}".format(module_info["serial_number"]))
51 
52  # locating
53  device.ioThinx_Misc_SetLocateState(module_slot, 1)
54  print("Slot {}: Locating...".format(module_slot))
55  input("Press enter to stop locate.")
56  device.ioThinx_Misc_SetLocateState(module_slot, 0)
57  rs_state = device.ioThinx_Misc_GetRotarySwitchState(misc_slot)
58  print("Rotary switch state = {}".format(rs_state))
59 
60  # push button
61  pbtn_state = device.ioThinx_Misc_GetPushButtonState(misc_slot)
62  print("Push button state = {}".format(pbtn_state))
63 
64  # user led
65  device.ioThinx_Misc_SetUserLedState(misc_slot, LED_CHANNEL_U1, LED_STATE_GREEN)
66  print("Set LED U1 to GREEN")
67  device.ioThinx_Misc_SetUserLedState(misc_slot, LED_CHANNEL_U2, LED_STATE_RED)
68  print("Set LED U2 to RED")
69  input("Press enter to clear.")
70  device.ioThinx_Misc_SetUserLedState(misc_slot, LED_CHANNEL_U1, LED_STATE_DARK)
71  device.ioThinx_Misc_SetUserLedState(misc_slot, LED_CHANNEL_U2, LED_STATE_DARK)
72  input("Press enter to continue.")
73 
74 
75 if __name__ == '__main__':
76  main()
def main()
Definition: misc.py:32