예제 #1
0
        print "ERROR comedi_get_buffer_contents"
        c.comedi_cancel(device, subdevice)
        c.comedi_poll(device, subdevice)
        break
    if (front==back):
        print 'sleep'
        #~ time.sleep(.001)
        time.sleep(pause)
        continue

    if back%size>front%size:
        print '			back%size>front%size:'
        data = map[back%size:size]
        alldata[back/2:back/2+len(data)/2] = numpy.fromstring(data , dtype = 'i2')

        ret = c.comedi_mark_buffer_read(dev, subdevice, size - back%size)
        if ret<0:
            raise "error comedi_mark_buffer_read"
        back += (size - back%size)
	
    data = map[back%size:front%size]
    print 'data', len(data)
    #~ alldata += data
    print back,front
    print numpy.fromstring(data , dtype = 'i2').size
    alldata[back/2:back/2+len(data)/2] = numpy.fromstring(data , dtype = 'i2')
    print 'alldata',len(alldata)

    ret = c.comedi_mark_buffer_read(dev, subdevice, front-back)
    if ret<0:
        raise "error comedi_mark_buffer_read"
예제 #2
0
    def ls_collect_data(self):
        self.stop_event.clear()
        time_diff = datetime.timedelta(microseconds=200)
        front = 0
        back = 0
        bytes_per_reading = self.nchan_ls * 4 # 4 byte int for each reading
        while not self.stop_event.isSet():
            front += c.comedi_get_buffer_contents(self.dev,self.subdevice)
            if front < back:
                self.logger.error("front<back comedi buffer error")
                break
            if (front-back)%bytes_per_reading != 0:
                #print front,back
                front = front-(front-back)%bytes_per_reading
            if front == back:
                time.sleep(.01)
                continue
            
            self.adc_lock.acquire()
            #start = c.comedi_get_buffer_offset(self.dev,self.subdevice)
            #print start,n_count,(start+n_count)
            self.map.seek(back%self.buffer_size)
            data = []
            for i in range(back,front,4):
                if i%self.buffer_size == 0:
                    self.map.seek(0)
                data.append(struct.unpack("I",self.map.read(4))[0])
          
            dd = array(data)
            n_elements = len(dd)/self.nchan_ls
            dd = dd.reshape(n_elements, self.nchan_ls)
            c.comedi_mark_buffer_read(self.dev,self.subdevice,front-back)
            back = front
            self.adc_lock.release()

            #!!!RW247 FIX THIS!!!!!!
            temp_fb = self.convert_to_real(self.adc_gain,dd[:,0])
            temp_sa = self.convert_to_real(self.adc_gain,dd[:,1])
            temp_fb_nofilt = self.convert_to_real(self.adc_gain,dd[:,2])
            temp_sa_nofilt = self.convert_to_real(self.adc_gain,dd[:,3])
            temp_mon = self.convert_to_real(self.adc_gain,dd[:,4])
            temp_err = self.convert_to_real(self.adc_gain,dd[:,5])

            #Here we assume that the first value is first channel
            #self.data_lock.acquire()
            self.fb.extend(temp_fb)
            self.sa.extend(temp_sa)
            self.fb_nofilt.extend(temp_fb_nofilt)
            self.sa_nofilt.extend(temp_sa_nofilt)
            self.mon.extend(temp_mon)
            self.err.extend(temp_err)
            
            self.sa_logging.extend(temp_sa)
            self.fb_logging.extend(temp_fb)

            #self.data_lock.release()
            self.filter_lock.acquire()
            self.fb_temp.extend(temp_fb)
            self.sa_temp.extend(temp_sa)
                
            for i in xrange(n_elements):
                mjd = dt_to_mjd(self.adc_time)
                self.timestamps.append(mjd)
                self.ts_temp.append(mjd)
                self.mjd_logging.append(mjd)
                self.adc_time = self.adc_time + time_diff

            self.filter_lock.release()
            
        #OK so we got a stop call - Halt the command
        #Get the latest data and then reset
        n_count = c.comedi_poll(self.dev,self.subdevice)
        n_count = c.comedi_get_buffer_contents(self.dev,self.subdevice)
        print "END LS POLL", n_count
        #if n_count != 0:
        #    start = c.comedi_get_buffer_offset(self.dev,self.subdevice)
         #   data = self.map[start:(start+n_count)]
 
        self.comedi_reset()
예제 #3
0
    if (front == back):
        time.sleep(.01)
        continue
    DATA = array.array("H")  # reset array to empty
    ## 	nbytes = front - back
    ## 	chunk_limit = (nbytes / size) * size # count for "size" sized chunks
    ## 	remainder = nbytes%size # bytes left after chunk_limit chunks done
    ## 	for i in range(0,chunk_limit,size):
    ## 		DATA.fromstring(map.read(size)) # read chunks
    ## 	for i in range(0,remainder,2):
    ## 		DATA.fromstring(map.read(2)) # read remaining bytes
    map.seek(back % size)
    for i in range(back, front, 2):
        DATA.fromstring(map.read(2))
        if map.tell() == size:
            map.seek(0)
    DATA.tofile(of)  # append data to log file
    ## 	time.sleep(.01)
    ret = c.comedi_mark_buffer_read(dev, subdevice, front - back)
    if ret < 0:
        raise Exception("error comedi_mark_buffer_read")
    back = front
print("bytes read = ", front)
c.comedi_close(dev)
if ret < 0:
    raise Exception("ERROR executing comedi_close")
of.flush()
of.close()

print("Elapsed time = %d seconds" % (t1 - t0))
예제 #4
0
    def hs_collect_data(self):
        self.stop_event.clear()
        front = 0
        back = 0
        hs_data = []
        self.log_hs_data_start_time = datetime.datetime.utcnow()

        while not self.stop_event.isSet():
            time_now = datetime.datetime.utcnow()
            dt = time_now - self.log_hs_data_start_time
            self.ls_progress = (dt.seconds + dt.microseconds*1.0e-6)*100.0/self.ls_period
            front += c.comedi_get_buffer_contents(self.dev,self.subdevice)
            if front < back:
                self.logger.error("front<back comedi buffer error")
                break
            if (front-back)%8 != 0:
                #print front,back
                front = front-4
            if front == back:
                time.sleep(.01)
                continue
            
            print back,front,(front-back),(front%self.buffer_size)
            self.map.seek(back%self.buffer_size)
            for i in range(back,front,4):
                if i%self.buffer_size == 0:
                    self.map.seek(0)
                hs_data.append(self.map.read(4))

            c.comedi_mark_buffer_read(self.dev,self.subdevice,front-back)
            back = front

        #get remaining data
        front += c.comedi_get_buffer_contents(self.dev,self.subdevice)
        if (front-back)%8 != 0:
                #print front,back
                front = front-4
        if front > back:
            print "ending",back,front,(front-back),(front%self.buffer_size)
            self.map.seek(back%self.buffer_size)
            for i in range(back,front,4):
                if i%self.buffer_size == 0:
                    self.map.seek(0)
                hs_data.append(self.map.read(4))
        
        self.comedi_reset()

        #And process the high speed data
        temp_data = []
        for d in hs_data:
            temp_data.append(struct.unpack("I",d)[0])

        temp_data = array(temp_data)
        temp_data = temp_data.reshape(len(temp_data)/2,2)
        temp_fb = self.convert_to_real(self.adc_gain,temp_data[:,0])
        temp_sa = self.convert_to_real(self.adc_gain,temp_data[:,1])
        self.fb_uf.extend(temp_fb)
        self.sa_uf.extend(temp_sa)
        self.ls_progress = 100

        #And record the data
        if self.dlog.file_name is not None:
            self.dlog.add_hs_data(list(self.sa_uf),list(self.fb_uf),self.hs_freq,
                                  meta=self.hs_meta)

        #finally restart ls data
        self.take_ls_data()