- Main
- Tutorials
- Library
- Samples

- File List
- Globals

Namespaces | Functions
relay.py File Reference

Relay Sample More...

Go to the source code of this file.

## Namespaces
| relay

## Functions
def | main ()

## Detailed Description

Relay Sample

Copyright
  2019 Moxa Inc. All rights reserved.

Date
  2019-02-11

Author
  William Chang

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

Definition in file relay.py.