1 Import required modules.
3 >>> from pycomedi.classes import Device, DataChannel
4 >>> from pycomedi.constants import SUBDEVICE_TYPE, AREF, UNIT
8 >>> device = Device('/dev/comedi0')
11 Get your I/O subdevice (alternatively, use `device.subdevice()` to
12 select the subdevice directly by index).
14 >>> subdevice = device.find_subdevice_by_type(SUBDEVICE_TYPE.ai)
16 Generate a list of channels you wish to control.
18 >>> channels = [subdevice.channel(i, factory=DataChannel, aref=AREF.diff)
19 ... for i in (0, 1, 2, 3)]
21 Configure the channels.
23 >>> for chan in channels:
24 ... chan.range = chan.find_range(unit=UNIT.volt, min=0, max=5)
26 Read/write sequentially.
28 >>> value = [c.data_read_delayed(nano_sec=1e3) for c in channels]
29 >>> value # doctest: +SKIP
32 TODO: convert to physical values.
34 Close the device when you're done.
40 As a more elaborate test, we can cable AO0 into AI0 and sweep the
43 >>> from numpy import linspace
44 >>> from scipy.stats import linregress
46 >>> ai_subdevice = device.find_subdevice_by_type(SUBDEVICE_TYPE.ai)
47 >>> ao_subdevice = device.find_subdevice_by_type(SUBDEVICE_TYPE.ao)
48 >>> ai_channel = ai_subdevice.channel(0, factory=DataChannel, aref=AREF.diff)
49 >>> ao_channel = ao_subdevice.channel(0, factory=DataChannel, aref=AREF.diff)
50 >>> ai_channel.range = ai_channel.find_range(unit=UNIT.volt, min=0, max=5)
51 >>> ao_channel.range = ao_channel.find_range(unit=UNIT.volt, min=0, max=5)
52 >>> ao_maxdata = ao_channel.get_maxdata()
53 >>> ai_maxdata = ai_channel.get_maxdata()
54 >>> ao_start = 0.3 * ao_maxdata
55 >>> ao_stop = 0.7 * ao_maxdata
57 >>> ao_data = linspace(ao_start, ao_stop, points)
59 >>> for i in range(points):
60 ... written = ao_channel.data_write(ao_data[i])
61 ... assert written == 1, written
62 ... ai_data.append(ai_channel.data_read_delayed(nano_sec=1e3))
65 >>> scaled_ao_data = [d/float(ao_maxdata) for d in ao_data]
66 >>> scaled_ai_data = [d/float(ai_maxdata) for d in ai_data]
67 >>> gradient,intercept,r_value,p_value,std_err = linregress(
68 ... scaled_ao_data, scaled_ai_data)