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