- Main
- Tutorials
- Library
- Samples

- File List
- Globals

Namespaces | Functions | Variables
ai.py File Reference

AI Sample More...

Go to the source code of this file.

## Namespaces
| ai

## Functions
def | main ()

## Variables
int | AI_RANGE_4_20mA_BURNOUT = 3

## Detailed Description

AI 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 AI 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 AI_RANGE_4_20mA_BURNOUT = 3
  24
  25
  26 def main():
  27 parser = argparse.ArgumentParser(description="AI sample program.")
  28 parser.add_argument("-s", "--slot", dest="ai_slot", type=int, default=1)
  29 parser.add_argument("-c", "--channel_start", dest="ai_channel_start", type=int, default=0)
  30 parser.add_argument("-n", "--channel_count", dest="ai_channel_count", type=int, default=8)
  31 args = parser.parse_args()
  32
  33 ai_slot = args.ai_slot
  34 ai_channel_start = args.ai_channel_start
  35 ai_channel_count = args.ai_channel_count
  36 print("AI slot = {}".format(ai_slot))
  37 print("AI start channel = {}".format(ai_channel_start))
  38 print("AI channel count = {}".format(ai_channel_count))
  39
  40 # initialize ioThinx I/O
  41 device = ioThinx_4530_API.ioThinx_4530_API()
  42
  43 # temporarily set config
  44 ai_ranges = [AI_RANGE_4_20mA_BURNOUT] * ai_channel_count
  45 device.ioThinx_AI_Config_SetRanges(ai_slot, ai_channel_start, ai_channel_count, ai_ranges)
  46 ai_burnouts = [2.0] * ai_channel_count
  47 device.ioThinx_AI_Config_SetBurnoutValues(ai_slot, ai_channel_start, ai_channel_count, ai_burnouts)
  48
  49 # reload config
  50 device.ioThinx_IO_Config_Reload()
  51
  52 # get value
  53 while True:
  54 ai_engs = device.ioThinx_AI_GetEngs(ai_slot, ai_channel_start, ai_channel_count, )
  55 ai_statuss = device.ioThinx_AI_GetStatuss(ai_slot, ai_channel_start, ai_channel_count, )
  56 for i in range(ai_channel_count):
  57 print("[ {}:{}] eng = {}, status = {}".format(ai_slot, ai_channel_start + i, ai_engs[i], ai_statuss[i]))
  58 if input("Press 'q' to exit. other keys to continue") == 'q':
  59 break
  60
  61
  62 if __name__ == '__main__':
  63 main()

Definition in file ai.py.