3 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
5 # This file is part of pycomedi.
7 # pycomedi is free software: you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation, either version 2 of the License, or (at your option) any later
12 # pycomedi is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # pycomedi. If not, see <http://www.gnu.org/licenses/>.
19 """Gather and display information about a comedi device.
22 from pycomedi import PyComediError as _PyComediError
23 import pycomedi.constant as _constant
24 from pycomedi.device import Device as _Device
25 from pycomedi.subdevice import StreamingSubdevice as _StreamingSubdevice
28 def display_maxdata(subdevice):
29 if subdevice.maxdata_is_chan_specific():
30 print(' max data value: (channel specific)')
31 for channel in subdevice.channels():
32 print(' chan{}: {}'.format(
33 channel.index, channel.get_maxdata()))
35 print(' max data value: {}'.format(
36 subdevice.channel(0).get_maxdata()))
38 def display_ranges(subdevice):
39 if subdevice.range_is_chan_specific():
40 print(' ranges: (channel specific)')
41 for channel in subdevice.channels():
42 print(' chan{}: {}'.format(
44 ', '.join(str(r) for r in channel.ranges())))
46 print(' ranges: {}'.format(
47 ', '.join(str(r) for r in subdevice.channel(0).ranges())))
49 def display_max_generic_timed(subdevice):
50 """Fastest supported single-channel command"""
52 command = subdevice.get_cmd_generic_timed(chanlist_len=1)
53 except _PyComediError, e:
54 if e.function_name != 'comedi_get_cmd_generic_timed':
56 print(' command fast 1chan: (not supported)')
58 print(' command fast 1chan:')
59 print(' start: {} {}'.format(command.start_src, command.start_arg))
60 print(' scan_begin: {} {}'.format(
61 command.scan_begin_src, command.scan_begin_arg))
62 print(' convert: {} {}'.format(
63 command.convert_src, command.convert_arg))
64 print(' scan_end: {} {}'.format(
65 command.scan_end_src, command.scan_end_arg))
66 print(' stop: {} {}'.format(command.stop_src, command.stop_arg))
68 def display_command(subdevice):
70 command = subdevice.get_cmd_src_mask()
71 except _PyComediError, e:
72 if e.function_name != 'comedi_get_cmd_src_mask':
74 print(' command: (not supported)')
77 print(' start: {}'.format(command.start_src))
78 print(' scan_begin: {}'.format(command.scan_begin_src))
79 print(' convert: {}'.format(command.convert_src))
80 print(' scan_end: {}'.format(command.scan_end_src))
81 print(' stop: {}'.format(command.stop_src))
82 display_max_generic_timed(subdevice=subdevice)
84 def display_subdevice(subdevice):
85 print('subdevice {}:'.format(subdevice.index))
86 subtype = subdevice.get_type()
87 print(' type: {}'.format(subtype))
88 if subtype == _constant.SUBDEVICE_TYPE.unused:
90 print(' flags: {}'.format(subdevice.get_flags()))
91 print(' number of channels: {}'.format(subdevice.get_n_channels()))
92 display_maxdata(subdevice=subdevice)
93 display_ranges(subdevice=subdevice)
94 # For testing commands, assume every device supports streaming and
96 streaming_subdevice = subdevice.device.subdevice(
97 index=subdevice.index, factory=_StreamingSubdevice)
98 display_command(subdevice=streaming_subdevice)
101 print('overall info')
102 print(' comedi version: {}'.format(
103 '.'.join(str(x) for x in device.get_version())))
104 print(' driver name: {}'.format(device.get_driver_name()))
105 print(' board name: {}'.format(device.get_board_name()))
106 print(' number of subdevices: {}'.format(device.get_n_subdevices()))
107 for subdevice in device.subdevices():
108 display_subdevice(subdevice=subdevice)
112 >>> run(filename='/dev/comedi0') # doctest: +ELLIPSIS, +REPORT_UDIFF
114 comedi version: 0.7.76
115 driver name: ni_pcimio
116 board name: pci-6052e
117 number of subdevices: 14
120 flags: cmd_read|readable|ground|common|diff|other|dither
124 flags: readable|writable
125 number of channels: 1
127 ranges: <Range unit:none min:0.0 max:1.0>
128 command: (not supported)
130 device = _Device(filename=filename)
138 if __name__ == '__main__':
139 import pycomedi_demo_args
141 args = pycomedi_demo_args.parse_args(
143 argnames=['filename', 'verbose'])
145 run(filename=args.filename)