Ejemplo n.º 1
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]
Ejemplo n.º 2
0
 def _write_bool(self,subdevice,channel,value):
     """Write to comedi port
     """
     value = not value #invert the value for comedi
     s = comedi.comedi_dio_write(self.device,subdevice,channel,value)
     if s:
         return True
     else:
         raise InterfaceError('could not write to comedi device "%s", subdevice %s, channel %s' % (self.device,subdevice,channel))
Ejemplo n.º 3
0
    def _write_bool(self, subdevice, channel, value):
        """Write to comedi port
        """
        value = not value  #invert the value for comedi

        s = comedi.comedi_dio_write(self.device, subdevice, channel, value)
        if s:
            return True
        else:
            raise InterfaceError(
                'could not write to comedi device "%s", subdevice %s, channel %s'
                % (self.device, subdevice, channel))
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def set_trig(ch, state):
    ret = c.comedi_dio_write(ch.dev, ch.subdev, ch.no, state)
    if ret != 1:
        sys.stderr.write("NICOMEDI: Couldn't send trigger signal\n")
        comedi_errcheck()
Ejemplo n.º 7
0
    def send_data(self,data):
        #So first make sure that sclk and fsync are 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)
        #print "Sending Bits :", gmpy.digits(self.data,2).zfill(24)

        #Then set bit and clock it by taking sclk from low to high to low
        #This seems like a waste of one instruction but the DAC reads
        #data on the falling edge, the switch on the rising edge
        #Should write two functions really

        for i in arange(23,-1,-1):
            dbit = ((data >> i) & 0x01)
            cm.comedi_dio_write(self.cf,self.subdev,self.din_chan,int(dbit))
            cm.comedi_dio_write(self.cf,self.subdev,self.sclk_chan,0)
            cm.comedi_dio_write(self.cf,self.subdev,self.sclk_chan,1)
            cm.comedi_dio_write(self.cf,self.subdev,self.sclk_chan,0)

        #And set Fsync high to set the switch then low
        # Also make sure clk is low too
        cm.comedi_dio_write(self.cf,self.subdev,self.sclk_chan,0)
        cm.comedi_dio_write(self.cf,self.subdev,self.fsync_chan,1)
        cm.comedi_dio_write(self.cf,self.subdev,self.fsync_chan,0)
Ejemplo n.º 8
0
    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()
Ejemplo n.º 9
0
 def Off(self):
     c.comedi_dio_write(self.device, 2, self.channel, 0)
Ejemplo n.º 10
0
def set_trig(ch, state):
    ret = c.comedi_dio_write(ch.dev, ch.subdev, ch.no, state)
    if ret != 1:
        sys.stderr.write("NICOMEDI: Couldn't send trigger signal\n")
        comedi_errcheck()