def add_channel(self,channel): if not isinstance(channel,ComediChannel): raise ValueError("ComediDevice only has ComediChannel.") VisionEgg.Daq.Device.add_channel(self,channel) first_channel = channel.constant_parameters.first_channel num_channels = channel.constant_parameters.num_channels n_subdevs = comedi.comedi_get_n_subdevices(self.dev) nchannels = 0 for subdevind in range(n_subdevs): subdevchans = comedi.comedi_get_n_channels(self.dev, subdevind) nchannels += subdevchans if first_channel + num_channels <= nchannels: subdevice = subdevind base_channel = first_channel - (nchannels - subdevchans) if base_channel < 0: raise RuntimeError("All channels are not in one port. " "You may need to try another first channel in the configuration file.") channel_io_dir = channel.constant_parameters.functionality.io_direction if comedi.comedi_find_subdevice_by_type(self.dev, channel_io_dir, subdevice) != subdevice: raise RuntimeError("The port is not capable of the functionality as you request.") for channel in range(base_channel+num_channels): comedi.comedi_dio_config(self.dev,subdevice,channel,channel_io_dir) channel.constant_parameters.functionality.device = self.dev channel.constant_parameters.functionality.subdevice = subdevice channel.constant_parameters.functionality.write_mask = 2**num_channels - 1 channel.constant_parameters.functionality.base_channel = base_channel return raise RuntimeError("Cannot allocate a port as you request.")
def __init__(self, subdevice = c.COMEDI_SUBD_AI): self.device = c.comedi_open('/dev/comedi0') self.subdevice = c.comedi_find_subdevice_by_type(self.device, subdevice, 0) self.numChannels = c.comedi_get_n_channels(self.device, self.subdevice) self.numRanges = c.comedi_get_n_channels(self.device, self.subdevice) self.channelRange = c.comedi_get_range(self.device, self.subdevice, 0, 0) self.maxdata = c.comedi_get_maxdata(self.device, 0, 0)
def __init__(self, subdevice=c.COMEDI_SUBD_AI): self.device = c.comedi_open('/dev/comedi0') self.subdevice = c.comedi_find_subdevice_by_type( self.device, subdevice, 0) self.numChannels = c.comedi_get_n_channels(self.device, self.subdevice) self.numRanges = c.comedi_get_n_channels(self.device, self.subdevice) self.channelRange = c.comedi_get_range(self.device, self.subdevice, 0, 0) self.maxdata = c.comedi_get_maxdata(self.device, 0, 0)
import comedi as c dev = c.comedi_open('/dev/comedi0') print dev maxdata = c.comedi_get_maxdata(dev, 0, 0) print "Max Data: %d" % maxdata subdev = c.comedi_find_subdevice_by_type(dev, c.COMEDI_SUBD_AO, 0) print "Subdevice: %d" % subdev print "Locked? %d" % c.comedi_lock(dev, subdev) nChannels = c.comedi_get_n_channels(dev, subdev) print "Num Channels: %d" % nChannels crange = c.comedi_get_range(dev, 0, 0, 0) print "Range: %s" % str(crange) data = maxdata/2 # start with no speed c.comedi_data_write(dev, subdev, 0, 0, 0, data) while True: usrin = raw_input("Enter a char: ") if usrin is 'q': break elif usrin is 'o': data = data + 10 elif usrin is 'l':
import comedi as c dev = c.comedi_open('/dev/comedi0') print dev maxdata = c.comedi_get_maxdata(dev, 0, 0) print "Max Data: %d" % maxdata subdev = c.comedi_find_subdevice_by_type(dev, c.COMEDI_SUBD_AO, 0) print "Subdevice: %d" % subdev print "Locked? %d" % c.comedi_lock(dev, subdev) nChannels = c.comedi_get_n_channels(dev, subdev) print "Num Channels: %d" % nChannels crange = c.comedi_get_range(dev, 0, 0, 0) print "Range: %s" % str(crange) data = maxdata / 2 # start with no speed c.comedi_data_write(dev, subdev, 0, 0, 0, data) while True: usrin = raw_input("Enter a char: ") if usrin is 'q': break elif usrin is 'o': data = data + 10 elif usrin is 'l':
def _get_subdevice(self, device): if self.subdevice is None: return _comedi.comedi_find_subdevice_by_type( device, _comedi.COMEDI_SUBD_AI, 0) return self.subdevice
import comedi as c import sys, time dev = c.comedi_open('/dev/comedi0') print dev maxdata = c.comedi_get_maxdata(dev, 0, 0) print "Max Data: %d" % maxdata subdev = c.comedi_find_subdevice_by_type(dev, c.COMEDI_SUBD_COUNTER, 0) print "Subdevice: %d" % subdev print "Locked? %d" % c.comedi_lock(dev, subdev) nChannels = c.comedi_get_n_channels(dev, subdev) print "Num Channels: %d" % nChannels crange = c.comedi_get_range(dev, 0, 0, 0) print "Range: %s" % str(crange) params = c.chanlist(1) params[0] = 0 # configure the encoder instr = c.comedi_insn_struct() instr.insn = c.INSN_CONFIG instr.n = 1 instr.data = params instr.subdev = 5 # instr.chanspec = c.cr_pack(0,0,c.AREF_OTHER) instr.chanspec = c.cr_pack(0,0,0)
# comedi_combo_test.py import comedi as c import time channel = 0 comediDevice = c.comedi_open('/dev/comedi0') print comediDevice print "***** HANDLING INPUT DEVICE(S) *****" inputSubdev = c.comedi_find_subdevice_by_type(comediDevice, c.COMEDI_SUBD_AI, 0) print "input subdevice: %d" % inputSubdev inputMaxdata = c.comedi_get_maxdata(comediDevice, inputSubdev, channel) print "Input max Data: %d" % inputMaxdata nInputChannels = c.comedi_get_n_channels(comediDevice, inputSubdev) print "Num input Channels: %d" % nInputChannels nInputRanges = c.comedi_get_n_ranges(comediDevice, inputSubdev, channel) print "number Input Ranges: %d" % nInputRanges inputRange = c.comedi_get_range(comediDevice, inputSubdev, channel, 0) print "input range: : %s" % str(inputRange) print "Input locked? %d" % c.comedi_lock(comediDevice, inputSubdev) print "***** HANDLING OUTPUT DEVICE(S) *****"