Example #1
0
 def read(self, context):
     device, subdevice, channel = _phys_channel(context)
     c.comedi_dio_config(device, subdevice, channel, c.COMEDI_OUTPUT)
     chk, value = c.comedi_dio_read()
     if chk < 0:
         raise ComediError("Failed to read on %s" % context.node)
     return value
Example #2
0
 def open(self):
     """Starts commmunication with the device, must be called before any
 set_cmd or get_data"""
     self.device = c.comedi_open(self.device_name)
     for chan in self.channels:
         chan['maxdata'] = c.comedi_get_maxdata(self.device, self.subdevice,
                                                chan['num'])
         chan['range_ds'] = c.comedi_get_range(self.device, self.subdevice,
                                               chan['num'],
                                               chan['range_num'])
     for chan in self.out_channels:
         chan['maxdata'] = c.comedi_get_maxdata(self.device,
                                                self.out_subdevice,
                                                chan['num'])
         chan['range_ds'] = c.comedi_get_range(self.device,
                                               self.out_subdevice,
                                               chan['num'],
                                               chan['range_num'])
         c.comedi_dio_config(self.device, 2, chan['num'], 1)
         c.comedi_dio_write(self.device, 2, chan['num'], 1)
     if any([i['make_zero'] for i in self.channels]):
         off = self.eval_offset()
         for i, chan in enumerate(self.channels):
             if chan['make_zero']:
                 chan['offset'] += off[i]
Example #3
0
    def __init__(self, device="/dev/comedi0", subdevice=1, channel=0, range_num=0, gain=1, offset=0):
        """Convert wanted tension value into digital values and send it to the 
		output of some Comedi-controlled card.
		
		Output is (command * gain) + offset.
		
		Parameters
		----------
		device : str, default = '/dev/comedi0'
			Path to the device.
		subdevice : int, default = 1
			Subdevice 1 is the output.
		channel : int, default = 0
			The desired output channel.
		range_num : int, default = 0
			See the comedi documentation for different values.
		gain : float, default = 1
			Multiplication gain for the output.
		offset : float, default = 0
			Add this value to your output.
		"""
        self.subdevice = 1  # delete as argument
        self.channel = channel
        self.range_num = range_num
        self.gain = gain
        self.offset = offset
        self.device = c.comedi_open(device)
        self.maxdata = c.comedi_get_maxdata(self.device, self.subdevice, self.channel)
        self.range_ds = c.comedi_get_range(self.device, self.subdevice, self.channel, self.range_num)
        c.comedi_dio_config(self.device, 2, self.channel, 1)
Example #4
0
 def read(self, context):
     device, subdevice, channel = _phys_channel(context)
     c.comedi_dio_config(device, subdevice, channel, c.COMEDI_OUTPUT)
     chk, value = c.comedi_dio_read()
     if chk < 0:
         raise ComediError("Failed to read on %s" % context.node)
     return value
Example #5
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.")
 def initialize(self):
     # configures channels for output
     for channel in [CHANNEL_RELAY, CHANNEL_A0, CHANNEL_A1]:
         ret = comedi.comedi_dio_config(self.device,
             DIGITAL_OUTPUT_SUBDEVICE, channel,
             comedi.COMEDI_OUTPUT)
         print "attempted to set output channel %i, return value:\t%i" %(
             channel, ret)
Example #7
0
def set_dig_io(ch, mode):
    if mode=='out':
        io = c.COMEDI_OUTPUT
    else:
        io = c.COMEDI_INPUT

    ret = c.comedi_dio_config(ch.dev, ch.subdev, ch.no, io)
    if ret == -1:
        comedi_errcheck()
Example #8
0
 def _config_write(self, subdevice, channel):
     s = comedi.comedi_dio_config(self.device, subdevice, channel,
                                  comedi.COMEDI_OUTPUT)
     if s < 0:
         raise InterfaceError(
             'could not configure comedi device "%s", subdevice %s, channel %s'
             % (self.device, subdevice, channel))
     else:
         return True
Example #9
0
def set_dig_io(ch, mode):
    if mode == 'out':
        io = c.COMEDI_OUTPUT
    else:
        io = c.COMEDI_INPUT

    ret = c.comedi_dio_config(ch.dev, ch.subdev, ch.no, io)
    if ret == -1:
        comedi_errcheck()
Example #10
0
def diowrite(subdevice, channel, data):
	dev = comedi.comedi_open("/dev/comedi0")
	ret1 = comedi.comedi_dio_config(dev, subdevice, channel, comedi.COMEDI_OUTPUT)

	if ret1 == 1:
		pass
	else:
		print "initialisation failed"
		
	ret=comedi.comedi_dio_write(dev, subdevice, channel, data)

	if ret == 1:
		pass
	else:
		print "setting failed"
	comedi.comedi_close(dev)
Example #11
0
def timedbeamunblank(delay):
    dev = comedi.comedi_open("/dev/comedi0")

    subdevice = 2
    channel = 0
    data = 0
    ret1 = comedi.comedi_dio_config(dev, subdevice, channel, comedi.COMEDI_OUTPUT)

    if ret1 == 1:
        pass
    else:
        print "initialisation failed"

    start_time = datetime.datetime.now()   
    ret=comedi.comedi_dio_write(dev, subdevice, channel, data)
    blanked_time = datetime.datetime.now()
    
    if ret == 1:
        pass
    else:
        print "setting failed"

    time.sleep(delay)
        
    data = 1
    ret=comedi.comedi_dio_write(dev, subdevice, channel, data)
    end_time = datetime.datetime.now()

    print "blanked_time =", blanked_time  - start_time
    print "end_time =", end_time  - start_time
    
    if ret == 1:
        pass
    else:
        print "setting failed"

    comedi.comedi_close(dev)
Example #12
0
 def write(self, context):
     device, subdevice, channel = _phys_channel(context)
     chk = c.comedi_dio_config(device, subdevice, channel, c.COMEDI_OUTPUT)
     if chk < 0:
         raise ComediError("Failed to write on %s" % context.node)
Example #13
0
 def write(self, context):
     device, subdevice, channel = _phys_channel(context)
     chk = c.comedi_dio_config(device, subdevice, channel, c.COMEDI_OUTPUT)
     if chk < 0:
         raise ComediError("Failed to write on %s" % context.node)
Example #14
0
 def _config_write(self,subdevice,channel):
     s = comedi.comedi_dio_config(self.device,subdevice,channel,comedi.COMEDI_OUTPUT)
     if s < 0:
         raise InterfaceError('could not configure comedi device "%s", subdevice %s, channel %s' % (self.device,subdevice,channel))
     else:
         return True
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)
    def __init__(self,reload_state = True):
        self.subdev = 2
        self.fsync_chan = 2
        self.sclk_chan  = 1
        self.din_chan = 0
       
        #Set the dac pa mapping for the 3 dac
        #0b10000, 0b10001, 0b10010
        self.dac_pa = [2**4, (2**4 + 1), (2**4 + 2**1)]
        #Switches required to get the requested gain
        self.pgains = {}
        self.pgains[5] = [0]
        self.pgains[10] = [1]
        self.pgains[15] = [0,1]
        self.pgains[20] = [2]
        self.pgains[25] = [0,2]
        self.pgains[30] = [1,2]
        self.pgains[35] = [0,1,2]
        self.pgains[40] = [3]
        self.pgains[45] = [0,3]
        self.pgains[50] = [1,3]
        self.pgains[55] = [0,1,3]
        self.pgains[60] = [2,3]
        self.pgains[65] = [0,2,3]
        self.pgains[70] = [1,2,3]
        self.pgains[75] = [0,1,2,3]

        #Switches required for time constant
        self.tcon = {}
        self.tcon[184] = [4]
        self.tcon[94] = [5]
        self.tcon[62] = [4,5]
        self.tcon[47] = [6]
        self.tcon[37] = [4,6]
        self.tcon[31] = [5,6]
        self.tcon[27] = [4,5,6]

        #Set some common indexs [mux,switch]

        self.rs_32 = [2,0] #Extra RS
        self.s2_bias = [2,1]
        self.s2_fb = [2,2]
        self.htr_e = [2,3]
        self.htr = [2,4]
        self.tes_bias_external = [2,5]
        self.tes_bias = [2,6]
        self.ssa_fb = [3,0]
        self.ssa_bias = [3,1]
        self.ssa_bias_external = [3,2]
        self.s1_fb = [3,3]
        self.s1_fb_m = [3,4]
        self.short_int = [3,15]
        self.aux = [3,5]
        self.gains = [3,8]

        #And the voltages
        self.rs_v = [0,0]
        self.s2b_v = [0,1]
        self.s2fb_v = [0,2]
        self.htr_v = [0,3]
        self.tes_v = [1,0]
        self.s1fb_v = [1,1]
        self.ssafb_v = [2,0]
        self.ssab_v = [2,1]
        self.pid_v = [2,2]
        self.aux_v = [2,3]
        
        #Dummy dict to mape voltage to names:
        self.volt_lookup = {"ssa_bias" : self.ssab_v,
                          "ssa_fb" : self.ssafb_v,
                          "s2_bias" : self.s2b_v,
                          "s2_fb" : self.s2fb_v,
                          "s1_bias" : self.rs_v,
                          "s1_fb" : self.s1fb_v,
                          "pid_fb" : self.pid_v,
                          "tes_bias" : self.tes_v,
                          "heater" : self.htr_v,
                          "AUX" : self.aux_v}

        self.registers = {} #Dict to store common information
        self.con = lite.connect('bolo_board.db') #database for registers
        self.cur = self.con.cursor()

        self.data = 0
        #Just set switches to zero and then add to what is needed
        #We have four so just use array
        self.switch_state = [0,0,0,0]
        self.sweep_ts_data = collections.deque()
        self.sweep_v_data = collections.deque()
        self.sweep_progress = 0 

        self.cf = cm.comedi_open("/dev/comedi0")
        #Setup dio config
        cm.comedi_dio_config(self.cf,self.subdev,self.fsync_chan,cm.COMEDI_OUTPUT)
        cm.comedi_dio_config(self.cf,self.subdev,self.sclk_chan,cm.COMEDI_OUTPUT)
        cm.comedi_dio_config(self.cf,self.subdev,self.din_chan,cm.COMEDI_OUTPUT)

        #And set them all low
        cm.comedi_dio_write(self.cf,self.subdev,self.fsync_chan,0)
        cm.comedi_dio_write(self.cf,self.subdev,self.sclk_chan,0)
        cm.comedi_dio_write(self.cf,self.subdev,self.din_chan,0)
        self.data_lock = threading.Lock() 

        #Zero voltages
        self.zero_voltages()

        if reload_state is True:
            self.reload_db()