1#!/usr/bin/env python 2# 3# Copyright (C) 2015 Analog Devices, Inc. 4# Author: Paul Cercueil <paul.cercueil@analog.com> 5# 6# This library is free software; you can redistribute it and/or 7# modify it under the terms of the GNU Lesser General Public 8# License as published by the Free Software Foundation; either 9# version 2.1 of the License, or (at your option) any later version. 10# 11# This library 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 GNU 14# Lesser General Public License for more details. 15 16import iio 17from sys import argv 18 19def main(): 20 print('Library version: %u.%u (git tag: %s)' % iio.version) 21 22 if len(argv) == 3 and argv[1] == '--uri': 23 uri = argv[2] 24 else: 25 contexts = iio.scan_contexts() 26 if len(contexts) > 1: 27 print('Multiple contexts found. Please select one using --uri:') 28 for index, each in enumerate(contexts): 29 print('\t%d: %s [%s]' % (index, contexts[each], each)) 30 return 31 32 uri = next(iter(contexts), None) 33 34 ctx = iio.Context(uri) 35 36 if uri is not None: 37 print('Using auto-detected IIO context at URI \"%s\"' % uri) 38 39 print('IIO context created: ' + ctx.name) 40 print('Backend version: %u.%u (git tag: %s)' % ctx.version) 41 print('Backend description string: ' + ctx.description) 42 43 if len(ctx.attrs) > 0: 44 print('IIO context has %u attributes:' % len(ctx.attrs)) 45 for attr, value in ctx.attrs.items(): 46 print('\t' + attr + ': ' + value) 47 48 print('IIO context has %u devices:' % len(ctx.devices)) 49 50 for dev in ctx.devices: 51 print('\t' + dev.id + ': ' + dev.name) 52 53 if dev is iio.Trigger: 54 print('Found trigger! Rate: %u Hz' % dev.frequency) 55 56 print('\t\t%u channels found:' % len(dev.channels)) 57 58 for chn in dev.channels: 59 print('\t\t\t%s: %s (%s)' % (chn.id, chn.name or "", 'output' if chn.output else 'input')) 60 61 if len(chn.attrs) != 0: 62 print('\t\t\t%u channel-specific attributes found:' % len(chn.attrs)) 63 64 for attr in chn.attrs: 65 try: 66 print('\t\t\t\t' + attr + ', value: ' + chn.attrs[attr].value) 67 except OSError as e: 68 print('Unable to read ' + attr + ': ' + e.strerror) 69 70 if len(dev.attrs) != 0: 71 print('\t\t%u device-specific attributes found:' % len(dev.attrs)) 72 73 for attr in dev.attrs: 74 try: 75 print('\t\t\t' + attr + ', value: ' + dev.attrs[attr].value) 76 except OSError as e: 77 print('Unable to read ' + attr + ': ' + e.strerror) 78 79 if len(dev.debug_attrs) != 0: 80 print('\t\t%u debug attributes found:' % len(dev.debug_attrs)) 81 82 for attr in dev.debug_attrs: 83 try: 84 print('\t\t\t' + attr + ', value: ' + dev.debug_attrs[attr].value) 85 except OSError as e: 86 print('Unable to read ' + attr + ': ' + e.strerror) 87 88if __name__ == '__main__': 89 main() 90