def get_record_time_info(h, record_id, tick_dt):
     trig_time = ffi.new("time_t *")
     frac_secs = ffi.new("double *")
     trigger_minus_rec_start = ffi.new("long *")
     result = lib.ADI_GetRecordTime(h[0], record_id - 1, trig_time,
                                    frac_secs, trigger_minus_rec_start)
     if result == 0:
         return RecordTime(tick_dt, trig_time[0], frac_secs[0],
                           trigger_minus_rec_start[0])
     else:
         #TODO: Improve message
         raise Exception('Error getting # of ticks in record')
 def get_n_channels(h):
     n_channels = ffi.new("long *")
     result = lib.ADI_GetNumberOfChannels(h[0], n_channels)
     if result == 0:
         return n_channels[0]
     else:
         raise Exception('Error getting # of channels')
 def get_n_records(h):
     n_records = ffi.new("long *")
     result = lib.ADI_GetNumberOfRecords(h[0], n_records)
     if result == 0:
         return n_records[0]
     else:
         raise Exception('Error getting # of records')
    def get_channel_name(h, channel_id):

        #TODO: Make length a variable
        text = ffi.new("wchar_t[1000]")
        max_chars = 999  #needs null termination???
        text_length = ffi.new("long *")
        result = lib.ADI_GetChannelName(h[0], channel_id - 1, text, max_chars,
                                        text_length)

        if not (result == 0 or result == 1):
            print(result)
            raise Exception('Error retrieving channel name')

        #I think the length includes null terminaton so we substract 1
        final_text = ffi.unpack(text, text_length[0] - 1)
        return final_text
    def get_comment(h2):
        tick_pos = ffi.new("long *")
        channel = ffi.new("long *")
        comment_id = ffi.new("long *")
        #TODO: Make length a variable
        text = ffi.new("wchar_t[1000]")
        max_chars = 999  #needs null termination????
        text_length = ffi.new("long *")
        result = lib.ADI_GetCommentInfo(h2[0], tick_pos, channel, comment_id,
                                        text, max_chars, text_length)

        if result != 0:
            raise Exception('Error retrieving comment')

        #I think the length includes null terminaton so we substract 1
        final_text = ffi.unpack(text, text_length[0] - 1)
        return Comment(final_text, tick_pos[0], channel[0], comment_id[0])
 def get_sample_period(h, record_id, channel_id):
     sample_period = ffi.new("double *")
     result = lib.ADI_GetRecordSamplePeriod(h[0], channel_id - 1,
                                            record_id - 1, sample_period)
     if result == 0 or result == 1:
         return sample_period[0]
     else:
         raise Exception('Error getting sample period')
 def get_tick_period(h, record_id, channel_id):
     tick_period = ffi.new("double *")
     result = lib.ADI_GetRecordTickPeriod(h[0], channel_id - 1,
                                          record_id - 1, tick_period)
     if result == 0:
         return tick_period[0]
     else:
         raise Exception('Error getting tick period')
 def get_n_ticks_in_record(h, record_id):
     n_ticks = ffi.new("long *")
     result = lib.ADI_GetNumTicksInRecord(h[0], record_id - 1, n_ticks)
     if result == 0:
         return n_ticks[0]
     else:
         #TODO: Improve message
         raise Exception('Error getting # of ticks in record')
    def get_n_samples_in_record(h, record_id, channel_id):
        n_samples = ffi.new("long *")
        result = lib.ADI_GetNumSamplesInRecord(h[0], channel_id - 1,
                                               record_id - 1, n_samples)

        if result == 0 or result == 1:
            return n_samples[0]
        else:
            raise Exception('Error getting # of samples in record')
Esempio n. 10
0
    def open_read_file(file_path):
        h = ffi.new("ADI_FileHandle *")
        result = lib.ADI_OpenFile(file_path, h, lib.kOpenFileForReadOnly)

        if result == 0:
            return h
        else:
            #TODO: Add more
            raise Exception('Error opening file for reading')
Esempio n. 11
0
    def get_units_name(h, record_id, channel_id):
        #TODO: Make length a variable

        #Different interfae ...
        #    N = 10
        #ptr = ffi.new( "float[]", N )

        text = ffi.new("wchar_t[1000]")
        max_chars = 999  #needs null termination???
        text_length = ffi.new("long *")
        result = lib.ADI_GetUnitsName(h[0], channel_id - 1, record_id - 1,
                                      text, max_chars, text_length)

        if not (result == 0 or result == 1):
            print(result)
            raise Exception('Error retrieving units')

        #I think the length includes null terminaton so we substract 1
        final_text = ffi.unpack(text, text_length[0] - 1)
        return final_text
Esempio n. 12
0
    def get_comment_accessor(h, record_id):
        """
        0 indicates no comments
        """
        h2 = ffi.new("ADI_CommentsHandle *")
        result = lib.ADI_CreateCommentsAccessor(h[0], record_id - 1, h2)

        #No comments - not sure why we don't have a flag for this ...
        if result == -1610313723:
            return 0
        elif result == 0:
            return h2
        else:
            raise Exception('Error opening comments accessor')
Esempio n. 13
0
    def get_channel_data(h, record_id, channel_id, start_sample, stop_sample):

        n_elements = stop_sample - start_sample + 1
        np_arr = np.empty(n_elements, dtype=np.float32)

        #Note, we might just be able to case to numpy after running
        #=> numpy.frombuffer => 0 copy?

        #https://ammous88.wordpress.com/2014/12/30/numpy-array-with-cffi-c-function/
        cffi_arr = ffi.cast('float*', np_arr.ctypes.data)

        returned = ffi.new("long *")
        result = lib.ADI_GetSamples(h[0], channel_id - 1, record_id - 1,
                                    start_sample - 1,
                                    lib.kADICDataAtSampleRate, n_elements,
                                    cffi_arr, returned)

        if result == 0:
            return np_arr
        else:
            raise Exception('Unable to retrieve requested data')