Пример #1
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)
Пример #2
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)
Пример #3
0
 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.")
Пример #4
0
def get_dio_channels(path):
    device = c.comedi_open(path)
    n_subdevices = c.comedi_get_n_subdevices(device)
    dio_list = []
    for n_subdevice in range(n_subdevices):
        if (c.comedi_get_subdevice_type(
                device, n_subdevice) == comedi_subdevice_type("dio")):
            n_channel = c.comedi_get_n_channels(device, n_subdevice)
            #dio_list.extend([DioSocket(path, n_subdevice, chan)
            #                for chan in range(n_channel)])
    return dio_list
Пример #5
0
def get_dio_channels(path):
    device = c.comedi_open(path)
    n_subdevices = c.comedi_get_n_subdevices(device)
    dio_list = []
    for n_subdevice in range(n_subdevices):
        if (c.comedi_get_subdevice_type(device, n_subdevice)
            == comedi_subdevice_type("dio")):
            n_channel = c.comedi_get_n_channels(device, n_subdevice)
            #dio_list.extend([DioSocket(path, n_subdevice, chan)
            #                for chan in range(n_channel)])
    return dio_list
Пример #6
0
        print "\tstart: %s" % (cmd_src(cmd.start_src, buf))
        print "\tscan_begin: %s" % (cmd_src(cmd.scan_begin_src, buf))
        print "\tconvert begin: %s" % (cmd_src(cmd.convert_src, buf))
        print "\tscan_end: %s" % (cmd_src(cmd.scan_end_src, buf))
        print "\tstop: %s" % (cmd_src(cmd.stop_src, buf))
        probe_max_1chan(dev, s)


print "-----subdevice characteristics-----"
for i in range(n_subdevices):
    print "subdevice %d:" % (i)
    type = c.comedi_get_subdevice_type(dev, i)
    print "\ttype: %d (%s)" % (type, subdevice_types[type])
    if (type == c.COMEDI_SUBD_UNUSED):
        continue
    n_chans = c.comedi_get_n_channels(dev, i)
    print "\tnumber of channels: %d" % (n_chans)
    if not (c.comedi_maxdata_is_chan_specific(dev, i)):
        print "\tmax data value: %d" % (c.comedi_get_maxdata(dev, i, 0))
    else:
        print "max data value is channel specific"
        for j in range(n_chans):
            print "\tchan: %d: %d" % (j, c.comedi_get_maxdata(dev, i, j))
    print "\tranges: "
    if not (c.comedi_range_is_chan_specific(dev, i)):
        n_ranges = c.comedi_get_n_ranges(dev, i, 0)
        print "\t\tall chans:"
        for j in range(n_ranges):
            rng = c.comedi_get_range(dev, i, 0, j)
            print "\t\t[%g,%g]" % (rng.min, rng.max)
    else:
Пример #7
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':
Пример #8
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':
Пример #9
0
	else:
		print("\tstart: %s" % (cmd_src(cmd.start_src,buf)))
		print("\tscan_begin: %s" % (cmd_src(cmd.scan_begin_src,buf)))
		print("\tconvert begin: %s" % (cmd_src(cmd.convert_src,buf)))
		print("\tscan_end: %s" % (cmd_src(cmd.scan_end_src,buf)))
		print("\tstop: %s" % (cmd_src(cmd.stop_src,buf)))
		probe_max_1chan(dev,s)

print("-----subdevice characteristics-----")
for i in range(n_subdevices):
	print("subdevice %d:" % (i))
	type = c.comedi_get_subdevice_type(dev,i)
	print("\ttype: %d (%s)" % (type,subdevice_types[type]))
	if (type == c.COMEDI_SUBD_UNUSED):
		continue
	n_chans = c.comedi_get_n_channels(dev,i)
	print("\tnumber of channels: %d" % ( n_chans))
	if not(c.comedi_maxdata_is_chan_specific(dev,i)):
	    print("\tmax data value: %d" % (c.comedi_get_maxdata(dev,i,0)))
	else:
		print("max data value is channel specific")
		for j in range(n_chans):
			print("\tchan: %d: %d" % (j,c.comedi_get_maxdata(dev,i,j)))
	print("\tranges: ")
	if not(c.comedi_range_is_chan_specific(dev,i)):
		n_ranges = c.comedi_get_n_ranges(dev,i,0)
		print("\t\tall chans:")
		for j in range(n_ranges):
			rng = c.comedi_get_range(dev,i,0,j)
			print("\t\t[%g,%g]" % (rng.min, rng.max))
	else:
import comedi
import time

com = comedi.comedi_open("/dev/comedi0")

nchan = comedi.comedi_get_n_channels(com, 0)
print "found comedi system with %d channels" % nchan

for i in range(nchan):
	comedi.comedi_dio_config(com, 0, i, comedi.COMEDI_OUTPUT)

for i in range(4):
	comedi.comedi_dio_bitfield2(com, 0, 1, 1, 0)
	time.sleep(1)

	comedi.comedi_dio_bitfield2(com, 0, 1, 0, 0)
	time.sleep(1)
Пример #11
0
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) *****"

outputSubdev = c.comedi_find_subdevice_by_type(comediDevice, c.COMEDI_SUBD_AO, 0)
print "output subdevice: %d" % outputSubdev