|
1 | 1 | #!/usr/bin/env python |
2 | | -# |
3 | | -# Copyright (C) 2015 Analog Devices, Inc. |
4 | | -# Author: Paul Cercueil <[email protected]> |
5 | | -# |
6 | | -# This program is free software; you can redistribute it and/or |
7 | | -# modify it under the terms of the GNU General Public License |
8 | | -# as published by the Free Software Foundation; either version 2 |
9 | | -# of the License, or (at your option) any later version. |
10 | | -# |
11 | | -# This program is distributed in the hope that it will be useful, |
12 | | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | -# GNU General Public License for more details. |
15 | | -# |
16 | | -# You should have received a copy of the GNU General Public License |
17 | | -# along with this program; if not, write to the Free Software |
18 | | -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 2 | +""" |
| 3 | +Copyright (C) 2015 Analog Devices, Inc. |
| 4 | +Author: Paul Cercueil <[email protected]> |
| 5 | +
|
| 6 | +This program is free software; you can redistribute it and/or |
| 7 | +modify it under the terms of the GNU General Public License |
| 8 | +as published by the Free Software Foundation; either version 2 |
| 9 | +of the License, or (at your option) any later version. |
| 10 | +
|
| 11 | +This program is distributed in the hope that it will be useful, |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with this program; if not, write to the Free Software |
| 18 | +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | +""" |
19 | 20 |
|
20 | | -import iio |
21 | 21 | from sys import argv |
| 22 | +import iio |
| 23 | + |
22 | 24 |
|
23 | 25 | def main(): |
24 | | - print('Library version: %u.%u (git tag: %s)' % iio.version) |
| 26 | + """ |
| 27 | + Dump iio devices, list all iio attributes. |
| 28 | + """ |
| 29 | + print("Library version: %u.%u (git tag: %s)" % iio.version) |
| 30 | + |
| 31 | + if len(argv) == 3 and argv[1] == "--uri": |
| 32 | + uri = argv[2] |
| 33 | + else: |
| 34 | + contexts = iio.scan_contexts() |
| 35 | + if len(contexts) > 1: |
| 36 | + print("Multiple contexts found. Please select one using --uri:") |
| 37 | + for index, each in enumerate(contexts): |
| 38 | + print("\t%d: %s [%s]" % (index, contexts[each], each)) |
| 39 | + return |
25 | 40 |
|
26 | | - if len(argv) == 3 and argv[1] == '--uri': |
27 | | - uri = argv[2] |
28 | | - else: |
29 | | - contexts = iio.scan_contexts() |
30 | | - if len(contexts) > 1: |
31 | | - print('Multiple contexts found. Please select one using --uri:') |
32 | | - for index, each in enumerate(contexts): |
33 | | - print('\t%d: %s [%s]' % (index, contexts[each], each)) |
34 | | - return |
| 41 | + uri = next(iter(contexts), None) |
35 | 42 |
|
36 | | - uri = next(iter(contexts), None) |
| 43 | + ctx = iio.Context(uri) |
37 | 44 |
|
38 | | - ctx = iio.Context(uri) |
| 45 | + if uri is not None: |
| 46 | + print('Using auto-detected IIO context at URI "%s"' % uri) |
39 | 47 |
|
40 | | - if uri is not None: |
41 | | - print('Using auto-detected IIO context at URI \"%s\"' % uri) |
| 48 | + print("IIO context created: " + ctx.name) |
| 49 | + print("Backend version: %u.%u (git tag: %s)" % ctx.version) |
| 50 | + print("Backend description string: " + ctx.description) |
42 | 51 |
|
43 | | - print('IIO context created: ' + ctx.name) |
44 | | - print('Backend version: %u.%u (git tag: %s)' % ctx.version) |
45 | | - print('Backend description string: ' + ctx.description) |
| 52 | + if len(ctx.attrs) > 0: |
| 53 | + print("IIO context has %u attributes:" % len(ctx.attrs)) |
| 54 | + for attr, value in ctx.attrs.items(): |
| 55 | + print("\t" + attr + ": " + value) |
46 | 56 |
|
47 | | - if len(ctx.attrs) > 0: |
48 | | - print('IIO context has %u attributes:' % len(ctx.attrs)) |
49 | | - for attr, value in ctx.attrs.items(): |
50 | | - print('\t' + attr + ': ' + value) |
| 57 | + print("IIO context has %u devices:" % len(ctx.devices)) |
51 | 58 |
|
52 | | - print('IIO context has %u devices:' % len(ctx.devices)) |
| 59 | + for dev in ctx.devices: |
| 60 | + print("\t" + dev.id + ": " + dev.name) |
53 | 61 |
|
54 | | - for dev in ctx.devices: |
55 | | - print('\t' + dev.id + ': ' + dev.name) |
| 62 | + if dev is iio.Trigger: |
| 63 | + print("Found trigger! Rate: %u Hz" % dev.frequency) |
56 | 64 |
|
57 | | - if dev is iio.Trigger: |
58 | | - print('Found trigger! Rate: %u Hz' % dev.frequency) |
| 65 | + print("\t\t%u channels found:" % len(dev.channels)) |
59 | 66 |
|
60 | | - print('\t\t%u channels found:' % len(dev.channels)) |
| 67 | + for chn in dev.channels: |
| 68 | + print( |
| 69 | + "\t\t\t%s: %s (%s)" |
| 70 | + % (chn.id, chn.name or "", "output" if chn.output else "input") |
| 71 | + ) |
61 | 72 |
|
62 | | - for chn in dev.channels: |
63 | | - print('\t\t\t%s: %s (%s)' % (chn.id, chn.name or "", 'output' if chn.output else 'input')) |
| 73 | + if len(chn.attrs) != 0: |
| 74 | + print("\t\t\t%u channel-specific attributes found:" % len(chn.attrs)) |
64 | 75 |
|
65 | | - if len(chn.attrs) != 0: |
66 | | - print('\t\t\t%u channel-specific attributes found:' % len(chn.attrs)) |
| 76 | + for attr in chn.attrs: |
| 77 | + try: |
| 78 | + print("\t\t\t\t" + attr + ", value: " + chn.attrs[attr].value) |
| 79 | + except OSError as err: |
| 80 | + print("Unable to read " + attr + ": " + err.strerror) |
67 | 81 |
|
68 | | - for attr in chn.attrs: |
69 | | - try: |
70 | | - print('\t\t\t\t' + attr + ', value: ' + chn.attrs[attr].value) |
71 | | - except OSError as e: |
72 | | - print('Unable to read ' + attr + ': ' + e.strerror) |
| 82 | + if len(dev.attrs) != 0: |
| 83 | + print("\t\t%u device-specific attributes found:" % len(dev.attrs)) |
73 | 84 |
|
74 | | - if len(dev.attrs) != 0: |
75 | | - print('\t\t%u device-specific attributes found:' % len(dev.attrs)) |
| 85 | + for attr in dev.attrs: |
| 86 | + try: |
| 87 | + print("\t\t\t" + attr + ", value: " + dev.attrs[attr].value) |
| 88 | + except OSError as err: |
| 89 | + print("Unable to read " + attr + ": " + err.strerror) |
76 | 90 |
|
77 | | - for attr in dev.attrs: |
78 | | - try: |
79 | | - print('\t\t\t' + attr + ', value: ' + dev.attrs[attr].value) |
80 | | - except OSError as e: |
81 | | - print('Unable to read ' + attr + ': ' + e.strerror) |
| 91 | + if len(dev.debug_attrs) != 0: |
| 92 | + print("\t\t%u debug attributes found:" % len(dev.debug_attrs)) |
82 | 93 |
|
83 | | - if len(dev.debug_attrs) != 0: |
84 | | - print('\t\t%u debug attributes found:' % len(dev.debug_attrs)) |
| 94 | + for attr in dev.debug_attrs: |
| 95 | + try: |
| 96 | + print("\t\t\t" + attr + ", value: " + dev.debug_attrs[attr].value) |
| 97 | + except OSError as err: |
| 98 | + print("Unable to read " + attr + ": " + err.strerror) |
85 | 99 |
|
86 | | - for attr in dev.debug_attrs: |
87 | | - try: |
88 | | - print('\t\t\t' + attr + ', value: ' + dev.debug_attrs[attr].value) |
89 | | - except OSError as e: |
90 | | - print('Unable to read ' + attr + ': ' + e.strerror) |
91 | 100 |
|
92 | | -if __name__ == '__main__': |
93 | | - main() |
| 101 | +if __name__ == "__main__": |
| 102 | + main() |
0 commit comments