2 Copyright (C) 2019 Moxa Inc. All rights reserved. 3 SPDX-License-Identifier: Apache-2.0 5 PWM Python Sample Application 8 2019-02-11 William Chang Created it. 22 from ioThinx_4530
import ioThinx_4530_API
29 parser = argparse.ArgumentParser(description=
"PWM sample program.")
30 parser.add_argument(
"-s",
"--slot", dest=
"do_slot", type=int, default=3)
31 parser.add_argument(
"-c",
"--channel_start", dest=
"pwm_channel_start", type=int, default=0)
32 parser.add_argument(
"-n",
"--channel_count", dest=
"pwm_channel_count", type=int, default=2)
33 args = parser.parse_args()
35 do_slot = args.do_slot
36 pwm_channel_start = args.pwm_channel_start
37 pwm_channel_count = args.pwm_channel_count
38 print(
"DO slot = {}".format(do_slot))
39 print(
"PWM start channel = {}".format(pwm_channel_start))
40 print(
"PWM channel count = {}".format(pwm_channel_count))
43 device = ioThinx_4530_API.ioThinx_4530_API()
46 do_modes = [DO_MODE_PWM] * pwm_channel_count
47 device.ioThinx_DO_Config_SetModes(do_slot, pwm_channel_start, pwm_channel_count, do_modes)
49 pwm_counts = [0] * pwm_channel_count
50 device.ioThinx_DO_Config_SetPwmCounts(do_slot, pwm_channel_start, pwm_channel_count, pwm_counts)
51 pwm_freqs = [5] * pwm_channel_count
52 pwm_dutys = [50] * pwm_channel_count
53 device.ioThinx_DO_Config_SetPwmConfigures(do_slot, pwm_channel_start, pwm_channel_count, pwm_freqs, pwm_dutys)
56 device.ioThinx_IO_Config_Reload()
60 for i
in range(pwm_channel_start, pwm_channel_start + pwm_channel_count):
62 device.ioThinx_DO_SetPwmStarts(do_slot, pwm_starts)
66 pwm_dutys[0] = 0
if (pwm_dutys[0] >= 100)
else pwm_dutys[0] + 10
67 device.ioThinx_DO_SetPwmConfigures(do_slot, pwm_channel_start, pwm_channel_count, pwm_freqs, pwm_dutys)
68 for i
in range(pwm_channel_count):
69 print(
"[ {}:{}] frequency = {}, duty cycle = {}".format(do_slot, pwm_channel_start + i, pwm_freqs[i], pwm_dutys[i]))
71 if input(
"Press 'q' to exit. other keys to continue") ==
'q':
74 device.ioThinx_DO_SetPwmStops(do_slot, pwm_starts)
77 if __name__ ==
'__main__':