コード例 #1
0
    def collect(self,
                num_samples,
                trigger,
                timeout=5,
                is_randomized=False,
                is_alternate_bit=False):
        self.controller.dc890_flush()
        num_samples *= self.num_channels
        funcs.start_collect(self, num_samples, trigger, timeout)
        self.vprint('Data collect done.')
        self.controller.dc890_flush()
        self.vprint('Reading data')
        if self.bytes_per_sample == 2:
            num_bytes, raw_data = self.controller.data_receive_uint16_values(
                end=num_samples)
            if num_bytes != num_samples * 2:
                raise errs.HardwareError("Didn't get all bytes")
        else:
            num_bytes, raw_data = self.controller.data_receive_uint32_values(
                end=num_samples)
            if num_bytes != num_samples * 4:
                raise errs.HardwareError("Didn't get all bytes")
        self.vprint('Data read done')

        data = self.fix_data(raw_data, is_randomized, is_alternate_bit)
        return funcs.scatter_data(data, self.num_channels)
コード例 #2
0
    def send_data(self, data):
        num_samples = len(data)
        num_samples_reg_value = Ltc2000._SIZE_DICTIONARY.get(num_samples)
        if num_samples > self.expected_max_val or num_samples_reg_value is None:
            raise (errs.NotSupportedError(
                "Data Length Not Supported (Must be a power of 2 between " +
                self.range_string))

        self.vprint("Reading PLL status")
        pll_status = self.controller.hs_fpga_read_data_at_address(
            Ltc2000._FPGA_STATUS_REG)
        if self.expected_pll_status != pll_status:
            raise (errs.HardwareError('FPGA PLL status was bad'))
        self.vprint("PLL status is okay")
        time.sleep(0.1)
        self.controller.hs_fpga_write_data_at_address(
            Ltc2000._FPGA_CONTROL_REG, num_samples_reg_value)
        if self.is_little_endian:
            self.controller.data_set_low_byte_first()
        else:
            self.controller.data_set_high_byte_first()

        self.controller.hs_set_bit_mode(consts.HS_BIT_MODE_FIFO)
        self.vprint("Sending data")
        num_bytes_sent = self.controller.data_send_uint16_values(data)
        self.controller.hs_set_bit_mode(consts.HS_BIT_MODE_MPSSE)
        if num_bytes_sent != num_samples * 2:
            raise (errs.HardwareError("Not all data was sent."))
        self.vprint("All data was sent (" + str(num_bytes_sent) + " bytes)")
コード例 #3
0
def get_controller_info_by_eeprom(controller_type, dc_number, eeprom_id_size,
                                  vprint):
    # find demo board with correct ID
    vprint('Looking for a controller board')
    info_list = comm.list_controllers(controller_type)
    if info_list is None:
        raise (err.HardwareError('No controller boards found'))
    for info in comm.list_controllers(controller_type):
        with comm.Controller(info) as controller:
            eeprom_id = controller.eeprom_read_string(eeprom_id_size)
            if dc_number in eeprom_id:
                vprint('Found the ' + dc_number + ' demoboard')
                return info
    raise (err.HardwareError('Could not find a compatible device'))
コード例 #4
0
 def _check_data(self, data):
     seq_len = len(self.spi_reg_values)
     if self.is_high_speed:
         for i in range(0, len(data), seq_len):
             if (data[i] & 0x100) == 0:
                 raise errs.HardwareError(
                     "Detected incorrect config in data")
     else:
         check_idx = 0
         for d in data:
             if (d >> 1) & 0x7F != self.spi_reg_values[check_idx] & 0x7F:
                 raise errs.HardwareError(
                     "Detected incorrect config in data")
             check_idx = (check_idx + 1) % seq_len
コード例 #5
0
    def _get_data_and_check_df(self, data):

        # figure out the expected metadata
        df_code = self.df_map[self.df]
        check = (((df_code * 2 + 8) << 4) | 0x05) << 24
        check_mask = 0xFF000000

        # figure out which is data and which is metadata
        data_0 = data[0::2]
        data_1 = data[1::2]
        data = data_0
        meta = data_1
        for d0, d1 in zip(data_0, data_1):
            if (d0 & check_mask) != check:
                # data_0 is the data
                break
            elif (d1 & check_mask) != check:
                data = data_1
                meta = data_0
                break

        # check metadata
        for m in meta:
            if (m & check_mask) != check:
                raise errs.HardwareError("Invalid metadata")

        return funcs.uint32_to_int32(data)
コード例 #6
0
    def _get_data_and_check_df(self, data):

        # figure out the expected metadata
        if self.filter_type == AVERAGING_FILTER:
            check = AVERAGING_FILTER << 24
            check |= (self.df - 1) << 10
            check_mask = 0xFFFFC00
        else:
            df_code = self.df_map[self.df]
            check = (df_code << 28) | (self.filter_type << 24)
            check_mask = 0xFF000000

        # figure out which is data and which is metadata
        data_0 = data[0::2]
        data_1 = data[1::2]
        data = data_0
        meta = data_1
        for d0, d1 in zip(data_0, data_1):
            if (d0 & check_mask) != check:
                # data_0 is the data
                break
            elif (d1 & check_mask) != check:
                data = data_1
                meta = data_0
                break

        # check metadata
        for m in meta:
            if (m & check_mask) != check:
                raise errs.HardwareError("Invalid metadata")

        return funcs.uint32_to_int32(data)
コード例 #7
0
def start_collect(controller_board, num_samples, trigger, timeout=5):
    controller_board.controller.data_start_collect(num_samples, trigger)
    SLEEP_TIME = 0.2
    for i in range(int(math.ceil(timeout / SLEEP_TIME))):
        if controller_board.controller.data_is_collect_done():
            return
        time.sleep(SLEEP_TIME)
    raise err.HardwareError('Data collect timed out (missing clock?)')
コード例 #8
0
 def _format_data(self, data, meta_data):
     osr_1 = self.osr - 1
     raw_data = [d & 0xFFFFFF for d in data]
     osr = [((d0 >> 24) & 0xFF) | ((d1 >> 16) & 0xFF00)
            for d0, d1 in zip(data, meta_data)]
     for o in osr:
         if o != osr_1:
             raise errs.HardwareError("Invalid OSR data")
     return raw_data
コード例 #9
0
def list_controllers(controller_type):
    """Returns a list of ControllerInfo structures
    Looks for all attached controllers matching controller_type and puts their info in the list
    controller_type can be a bitwise OR combination of TYPE_* values
    """
    num_controllers = ct.c_int()
    if _dll.LccGetNumControllers(ct.c_int(controller_type), ct.c_int(100),
                                 ct.byref(num_controllers)) != 0:
        raise errs.HardwareError("Could not create controller info list")
    num_controllers = num_controllers.value
    if num_controllers == 0:
        return None
    controller_info_list = (ControllerInfo * num_controllers)()
    if _dll.LccGetControllerList(ct.c_int(controller_type),
                                 controller_info_list, num_controllers) != 0:
        raise errs.HardwareError(
            "Could not get device info list, or no device found")
    return controller_info_list
コード例 #10
0
 def _connect(self):
     # Open communication to the demo board
     self.vprint("Looking for Controller")
     for info in comm.list_controllers(consts.TYPE_HIGH_SPEED):
         description = info.get_description()
         if self.expected_description in description:
             self.vprint("Found a possible setup")
             self.controller = comm.Controller(info)
             return
     raise (errs.HardwareError('Could not find a compatible device'))
コード例 #11
0
 def _get_data(self, data):
     num_samples = len(data) / 2
     start_sample = self._get_start_sample(data[0])
     data = data[start_sample:num_samples + start_sample]
     for i in range(len(data)):
         if data[i] & 0x7 != i % self.num_channels:
             raise errs.HardwareError(
                 "Unexpected channel number in metadata")
         data[i] = data[i] >> 16
     return data
コード例 #12
0
 def _init_controller(self, spi_reg_values):
     self.controller.hs_set_bit_mode(consts.HS_BIT_MODE_MPSSE)
     self.controller.hs_fpga_toggle_reset()
     # Read FPGA ID register
     id = self.controller.hs_fpga_read_data_at_address(Ltc2000._FPGA_ID_REG)
     self.vprint("FPGA Load ID: 0x{:04X}".format(id))
     if self.expected_id != id:
         raise (errs.HardwareError('Wrong FPGA Load'))
     self.controller.hs_fpga_write_data_at_address(Ltc2000._FPGA_DAC_PD,
                                                   0x01)
     self.set_spi_registers(spi_reg_values)
コード例 #13
0
 def read_3_byte_values(self, num_samples):
     num_bytes, raw_data = self.controller.data_receive_bytes(
         end=num_samples * 3)
     if num_bytes != num_samples * 3:
         raise errs.HardwareError("Didn't get all bytes")
     data = []
     for i in range(num_samples):
         d = raw_data[3 * i] << 16
         d |= raw_data[3 * i + 1] << 8
         d |= raw_data[3 * i + 2]
         data.append(d)
     return data
コード例 #14
0
 def __init__(self, controller_info):
     """Initialize the controller described by controller_info
     """
     self._handle = ct.c_void_p(None)
     self._c_error_buffer = ct.create_string_buffer(
         consts.ERROR_BUFFER_SIZE)
     self._c_array = None
     self._c_array_type = "none"
     self._dll = _dll
     if self._dll.LccInitController(ct.byref(self._handle),
                                    ct.byref(controller_info)) != 0:
         raise errs.HardwareError("Error initializing the device")
コード例 #15
0
 def _get_data_and_check_df(self, data):
     
     # figure out the expected metadata
     df_code = self.df_map[self.df]
     check = ((df_code + 2) << 4) | 0x06
     check_mask = 0x000000FF
     
     # check metadata
     for d in data:
         if (d & check_mask) != check:
             raise errs.HardwareError("Invalid metadata")
             
     return funcs.fix_data([d >> 8 for d in data], 24, 24, True) 
コード例 #16
0
 def _call(self, func_name, *args):
     func = getattr(self._dll, 'Lcc' + func_name)
     error_code = func(self._handle, *args)
     if error_code != 0:
         self._dll.LccGetErrorInfo(self._handle, self._c_error_buffer,
                                   consts.ERROR_BUFFER_SIZE)
         if error_code == -1:
             raise errs.HardwareError(self._c_error_buffer.value)
         elif error_code == -2:
             raise ValueError(self._c_error_buffer.value)
         elif error_code == -3:
             raise errs.LogicError(self._c_error_buffer.value)
         elif error_code == -4:
             raise errs.NotSupportedError(self._c_error_buffer.value)
         else:
             raise RuntimeError(self._c_error_buffer.value)
コード例 #17
0
    def collect(
        self,
        num_samples,
        trigger,
        timeout=5,
        is_randomized=False,
        is_alternate_bit=False,
    ):
        num_samples = num_samples * self.num_channels
        funcs.start_collect(self, num_samples, trigger, timeout)
        self.vprint('Data collect done.')
        self.vprint('Reading data')

        num_bytes, raw_data = self.controller.data_receive_uint16_values(
            end=num_samples)
        if num_bytes != num_samples * 2:
            raise errs.HardwareError("Didn't get all bytes")
        self.vprint('Data read done')

        data = funcs.fix_data(raw_data, self.num_bits, self.alignment,
                              self.is_bipolar, is_randomized, is_alternate_bit)
        return funcs.scatter_data(data, self.num_channels)
コード例 #18
0
if verbose:
    print "Basic LTC2123 DC1974 Interface Program"

# Open communication to the demo board
descriptions = [
    'LTC UFO Board', 'LTC Communication Interface', 'LTC2000 Demoboard',
    'LTC2000, DC2085A-A'
]
device_info = None
for info in comm.list_controllers(consts.TYPE_HIGH_SPEED):
    if info.get_description() in descriptions:
        device_info = info
        break
if device_info is None:
    raise (errs.HardwareError('Could not find a compatible device'))

while ((runs < 1 or continuous == True) and runs_with_errors < 100000):
    runs += 1
    #    if(verbose != 0):
    print "LTC2123 Interface Program"
    print "Run number: " + str(runs)
    print "\nRuns with errors: " + str(runs_with_errors) + "\n"
    if (runs_with_uncaught_errors > 0):
        print "***\n***\n***\n*** UNCAUGHT error count: " + str(runs_with_uncaught_errors) + \
        "!\n***\n***\n***\n"

    ################################################
    # Configuration Flow Step 6: Issue Reset Pulse
    ################################################
コード例 #19
0
 def _get_data_subset(self, data):
     seq_len = len(self.spi_reg_values)
     for i in range(seq_len):
         if (data[i] & 0x100) != 0:
             return data[i:(len(data) / 2 + i)]
     raise errs.HardwareError("Could not find correct config from data")