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. 20 from ioThinx_4530
import ioThinx_4530_API
27 parser = argparse.ArgumentParser(description=
"PWM sample program.")
28 parser.add_argument(
"-s",
"--slot", dest=
"do_slot", type=int, default=3)
29 parser.add_argument(
"-c",
"--channel_start", dest=
"pwm_channel_start", type=int, default=0)
30 parser.add_argument(
"-n",
"--channel_count", dest=
"pwm_channel_count", type=int, default=2)
31 args = parser.parse_args()
33 do_slot = args.do_slot
34 pwm_channel_start = args.pwm_channel_start
35 pwm_channel_count = args.pwm_channel_count
36 print(
"DO slot = {}".
format(do_slot))
37 print(
"PWM start channel = {}".
format(pwm_channel_start))
38 print(
"PWM channel count = {}".
format(pwm_channel_count))
41 device = ioThinx_4530_API.ioThinx_4530_API()
44 do_modes = [DO_MODE_PWM] * pwm_channel_count
45 device.ioThinx_DO_Config_SetModes(do_slot, pwm_channel_start, pwm_channel_count, do_modes)
47 pwm_counts = [0] * pwm_channel_count
48 device.ioThinx_DO_Config_SetPwmCounts(do_slot, pwm_channel_start, pwm_channel_count, pwm_counts)
49 pwm_freqs = [5] * pwm_channel_count
50 pwm_dutys = [50] * pwm_channel_count
51 device.ioThinx_DO_Config_SetPwmConfigures(do_slot, pwm_channel_start, pwm_channel_count, pwm_freqs, pwm_dutys)
54 device.ioThinx_IO_Config_Reload()
58 for i
in range(pwm_channel_start, pwm_channel_start + pwm_channel_count):
60 device.ioThinx_DO_SetPwmStarts(do_slot, pwm_starts)
64 pwm_dutys[0] = 0
if (pwm_dutys[0] >= 100)
else pwm_dutys[0] + 10
65 device.ioThinx_DO_SetPwmConfigures(do_slot, pwm_channel_start, pwm_channel_count, pwm_freqs, pwm_dutys)
66 for i
in range(pwm_channel_count):
67 print(
"[ {}:{}] frequency = {}, duty cycle = {}".
format(do_slot, pwm_channel_start + i, pwm_freqs[i], pwm_dutys[i]))
69 if input(
"Press 'q' to exit. other keys to continue") ==
'q':
72 device.ioThinx_DO_SetPwmStops(do_slot, pwm_starts)
75 if __name__ ==
'__main__':
char const int const cJSON_bool format