Esempio n. 1
0
def run(filename):
    """
    >>> run(filename='/dev/comedi0')  # doctest: +ELLIPSIS, +REPORT_UDIFF
    overall info
      comedi version: 0.7.76
      driver name: ni_pcimio
      board name: pci-6052e
      number of subdevices: 14
    subdevice 0:
      type: ai
      flags: cmd_read|readable|ground|common|diff|other|dither
    ...
    subdevice 13:
      type: counter
      flags: readable|writable
      number of channels: 1
      max data value: 15
      ranges: <Range unit:none min:0.0 max:1.0>
      command: (not supported)
    """
    try:
        display_modinfo('comedi')
    except ImportError as e:
        print('could not load module info (kmod not installed)')
        print('  {}'.format(e))
    except ModuleNotFound as e:
        print('could not load module info (module not found)')
        print('  {}'.format(e))
    device = _Device(filename=filename)
    device.open()
    try:
        display(device)
    finally:
        device.close()
Esempio n. 2
0
def run(filename):
    """
    >>> run(filename='/dev/comedi0')  # doctest: +ELLIPSIS, +REPORT_UDIFF
    overall info
      comedi version: 0.7.76
      driver name: ni_pcimio
      board name: pci-6052e
      number of subdevices: 14
    subdevice 0:
      type: ai
      flags: cmd_read|readable|ground|common|diff|other|dither
    ...
    subdevice 13:
      type: counter
      flags: readable|writable
      number of channels: 1
      max data value: 15
      ranges: <Range unit:none min:0.0 max:1.0>
      command: (not supported)
    """
    try:
        display_modinfo('comedi')
    except ImportError as e:
        print('could not load module info (kmod not installed)')
        print('  {}'.format(e))
    except ModuleNotFound as e:
        print('could not load module info (module not found)')
        print('  {}'.format(e))
    device = _Device(filename=filename)
    device.open()
    try:
        display(device)
    finally:
        device.close()
Esempio n. 3
0
def setup_device(filename, subdevice, channels, range, aref):
    """Open the Comedi device at filename and setup analog output channels.
    """
    device = _Device(filename=filename)
    device.open()
    if subdevice is None:
        ao_subdevice = device.find_subdevice_by_type(
            _constant.SUBDEVICE_TYPE.ao, factory=_StreamingSubdevice)
    else:
        ao_subdevice = device.subdevice(subdevice, factory=_StreamingSubdevice)
    ao_channels = [
        ao_subdevice.channel(i, factory=_AnalogChannel, range=range, aref=aref)
        for i in channels]
    return (device, ao_subdevice, ao_channels)
Esempio n. 4
0
def setup_device(filename, subdevice, channels, range, aref):
    """Open the Comedi device at filename and setup analog output channels.
    """
    device = _Device(filename=filename)
    device.open()
    if subdevice is None:
        ao_subdevice = device.find_subdevice_by_type(
            _constant.SUBDEVICE_TYPE.ao, factory=_StreamingSubdevice)
    else:
        ao_subdevice = device.subdevice(subdevice, factory=_StreamingSubdevice)
    ao_channels = [
        ao_subdevice.channel(i, factory=_AnalogChannel, range=range, aref=aref)
        for i in channels]
    return (device, ao_subdevice, ao_channels)
Esempio n. 5
0
def run_aad_thread():
	device = _Device(filename='/dev/comedi0')
	device.open()
	ai_subdevice, ai_channels = open_ai_channels(device=device, channels=[0])
	do_subdevice, do_channels = open_do_channels(device=device, subdevice=None, channels=[0,1,2,3,4,5,6,7])
	aich = ai_channels[0]
	aich.range=aich.find_range(unit=_constant.UNIT.volt,min=-10,max=10)
	# aich.apply_calibration()
	# t_aad = threading.Thread(target=aad_thread, args=(aich, do_subdevice))
	# t_aad.start()
	p_aad = multiprocessing.Process(target=aad_thread, args=(aich, do_subdevice))
	p_aad.start()

	pass
Esempio n. 6
0
def run_aad_thread():
    device = _Device(filename='/dev/comedi0')
    device.open()
    ai_subdevice, ai_channels = open_ai_channels(device=device, channels=[0])
    do_subdevice, do_channels = open_do_channels(
        device=device, subdevice=None, channels=[0, 1, 2, 3, 4, 5, 6, 7])
    aich = ai_channels[0]
    aich.range = aich.find_range(unit=_constant.UNIT.volt, min=-10, max=10)
    # aich.apply_calibration()
    # t_aad = threading.Thread(target=aad_thread, args=(aich, do_subdevice))
    # t_aad.start()
    p_aad = multiprocessing.Process(target=aad_thread,
                                    args=(aich, do_subdevice))
    p_aad.start()

    pass
Esempio n. 7
0
    def __init__(self,
                 dfname="/dev/comedi0",
                 chunk_size=4096,
                 n_ao_channels=4,
                 rate=40000):
        self.device = _Device(filename=dfname)
        self.device.open()
        self.rate = rate
        self.n_ao_channels = n_ao_channels
        self.ao_channel_list = range(n_ao_channels)
        self.chunk_size = chunk_size
        self.is_started = False

        # configure ao subdevice
        ao_subdevice, ao_channels = open_ao_channels(
            device=self.device,
            subdevice=None,
            channels=self.ao_channel_list,
            _range=0,
            aref=0)
        self.ao_subdevice = ao_subdevice
        self.ao_channels = ao_channels
        self.ao_subdevice.cmd = prepare_ao_command(subdevice=self.ao_subdevice,
                                                   channels=self.ao_channels,
                                                   frequency=self.rate)
        self.ao_dtype = ao_subdevice.get_dtype()
        self.ao_subdevice.command()
        self.ao_converter = self.ao_channels[0].get_converter()
        self.itemsize = np.zeros(1, self.ao_dtype).itemsize
        # # configure do subdevice
        # n_do_channels = len(do_channel_list)
        # do_subdevice,do_channels = open_do_channels(device=device, subdevice=do_subdevice, channels=do_channel_list)
        # import ipdb; ipdb.set_trace()
        # do_subdevice.cmd = prepare_do_command(subdevice=do_subdevice, channels=do_channels, frequency=fs)
        # do_dtype = do_subdevice.get_dtype()
        # import ipdb; ipdb.set_trace()
        # do_subdevice.command()
        self._file = self.ao_subdevice.device.file
        # setup buffers
        ao_preload0 = np.zeros((self.chunk_size * 5, self.n_ao_channels))
        ao_preload = np.zeros((ao_preload0.shape), self.ao_dtype)
        for kch in range(n_ao_channels):
            ao_preload[:, kch] = self.ao_converter.from_physical(
                ao_preload0[:, kch]).astype(self.ao_dtype)
        # import ipdb; ipdb.set_trace()
        # do_buffer = np.zeros(chunk_size*50, do_dtype)
        ao_preload.tofile(self._file)
Esempio n. 8
0
def run(filename, subdevice, channel, range, aref, num_scans):
    """
    >>> t1,data,t2 = run(filename='/dev/comedi0', subdevice=None,
    ...     channel=0, range=0, aref=_constant.AREF.ground, num_scans=10)
    >>> t1  # doctest: +SKIP
    1332242184.029691
    >>> t2  # doctest: +SKIP
    1332242184.3311629
    >>> data  # doctest: +ELLIPSIS
    array([...], dtype=uint32)
    >>> data.shape
    (10,)
    """
    _LOG.info(
        ('measuring device={} subdevice={} channel={} range={} '
         'analog-reference={} num-scans={}').format(filename, subdevice,
                                                    channel, range, aref,
                                                    num_scans))
    device = _Device(filename=filename)
    device.open()
    try:
        if subdevice is None:
            subdevice = device.find_subdevice_by_type(
                _constant.SUBDEVICE_TYPE.ai)
        else:
            subdevice = device.subdevice(subdevice)

        insns = [subdevice.insn(), subdevice.insn(), subdevice.insn()]
        insns[0].insn = insns[2].insn = _constant.INSN.gtod
        insns[0].data = insns[2].data = [0, 0]
        insns[1].insn = _constant.INSN.read
        insns[1].data = [0] * num_scans
        insns[1].chanspec = _ChanSpec(chan=channel, range=range, aref=aref)

        device.do_insnlist(insns)
    finally:
        device.close()

    t1 = insns[0].data[0] + insns[1].data[1] / 1e6
    t2 = insns[2].data[0] + insns[2].data[1] / 1e6
    return (t1, insns[1].data, t2)
Esempio n. 9
0
def run(filename, subdevice, channel, range, aref, num_scans):
    """
    >>> t1,data,t2 = run(filename='/dev/comedi0', subdevice=None,
    ...     channel=0, range=0, aref=_constant.AREF.ground, num_scans=10)
    >>> t1  # doctest: +SKIP
    1332242184.029691
    >>> t2  # doctest: +SKIP
    1332242184.3311629
    >>> data  # doctest: +ELLIPSIS
    array([...], dtype=uint32)
    >>> data.shape
    (10,)
    """
    _LOG.info(
        ("measuring device={} subdevice={} channel={} range={} " "analog-reference={} num-scans={}").format(
            filename, subdevice, channel, range, aref, num_scans
        )
    )
    device = _Device(filename=filename)
    device.open()
    try:
        if subdevice is None:
            subdevice = device.find_subdevice_by_type(_constant.SUBDEVICE_TYPE.ai)
        else:
            subdevice = device.subdevice(subdevice)

        insns = [subdevice.insn(), subdevice.insn(), subdevice.insn()]
        insns[0].insn = insns[2].insn = _constant.INSN.gtod
        insns[0].data = insns[2].data = [0, 0]
        insns[1].insn = _constant.INSN.read
        insns[1].data = [0] * num_scans
        insns[1].chanspec = _ChanSpec(chan=channel, range=range, aref=aref)

        device.do_insnlist(insns)
    finally:
        device.close()

    t1 = insns[0].data[0] + insns[1].data[1] / 1e6
    t2 = insns[2].data[0] + insns[2].data[1] / 1e6
    return (t1, insns[1].data, t2)
Esempio n. 10
0
def run(filename, **kwargs):
    """
    >>> import StringIO
    >>> stdout = StringIO.StringIO()
    >>> run(filename='/dev/comedi0', stream=stdout)
    >>> print(stdout.getvalue())  # doctest: +SKIP
    29694
    29693
    <BLANKLINE>
    >>> stdout.truncate(0)
    >>> run(filename='/dev/comedi0', reader=_utility.MMapReader, stream=stdout)
    >>> print(stdout.getvalue())  # doctest: +SKIP
    29691
    29691
    <BLANKLINE>
    """
    device = _Device(filename=filename)
    device.open()
    try:
        read(device=device, **kwargs)
    finally:
        device.close()
Esempio n. 11
0
	def __init__(self,dfname="/dev/comedi0", chunk_size = 4096, n_ao_channels=4, rate = 40000):
		self.device = _Device(filename=dfname)
		self.device.open()
		self.rate = rate
		self.n_ao_channels = n_ao_channels
		self.ao_channel_list = range(n_ao_channels)
		self.chunk_size = chunk_size
		self.is_started = False


		# configure ao subdevice
		ao_subdevice,ao_channels = open_ao_channels(device=self.device, subdevice=None, channels=self.ao_channel_list, _range=0, aref=0)
		self.ao_subdevice=ao_subdevice
		self.ao_channels = ao_channels
		self.ao_subdevice.cmd = prepare_ao_command(subdevice=self.ao_subdevice, channels=self.ao_channels, frequency=self.rate)
		self.ao_dtype = ao_subdevice.get_dtype()
		self.ao_subdevice.command()
		self.ao_converter = self.ao_channels[0].get_converter()
		self.itemsize=np.zeros(1,self.ao_dtype).itemsize
		# # configure do subdevice
		# n_do_channels = len(do_channel_list)
		# do_subdevice,do_channels = open_do_channels(device=device, subdevice=do_subdevice, channels=do_channel_list)
		# import ipdb; ipdb.set_trace()
		# do_subdevice.cmd = prepare_do_command(subdevice=do_subdevice, channels=do_channels, frequency=fs)
		# do_dtype = do_subdevice.get_dtype()
		# import ipdb; ipdb.set_trace()
		# do_subdevice.command()
		self._file = self.ao_subdevice.device.file
		# setup buffers
		ao_preload0 = np.zeros((self.chunk_size*5,self.n_ao_channels))
		ao_preload = np.zeros((ao_preload0.shape), self.ao_dtype)
		for kch in range(n_ao_channels):
			ao_preload[:,kch] = self.ao_converter.from_physical(ao_preload0[:,kch]).astype(self.ao_dtype)
		# import ipdb; ipdb.set_trace()
		# do_buffer = np.zeros(chunk_size*50, do_dtype)
		ao_preload.tofile(self._file)