当前位置: 首页>>代码示例>>Python>>正文


Python array.array类代码示例

本文整理汇总了Python中array.array的典型用法代码示例。如果您正苦于以下问题:Python array类的具体用法?Python array怎么用?Python array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

    def read(self, address, length = 1, disable_auto_inc = False):
        """read

        Generic read command used to read data from a Nysa image

        Args:
            length (int): Number of 32 bit words to read from the FPGA
            address (int):  Address of the register/memory to read
            disable_auto_inc (bool): if true, auto increment feature will be disabled

        Returns:
            (Array of unsigned bytes): A byte array containtin the raw data
                                     returned from Nysa

        Raises:
            NysaCommError: When a failure of communication is detected
        """
        read_cmd = "L%07X00000002%08X00000000"
        read_cmd = (read_cmd) % (length, address)
        self.ser.flushInput()
        self.ser.write(read_cmd)
        read_resp = self.ser.read(24 + ((length) * 8))
        response = Array('B')
        d = read_resp[24:]

        for i in range (0, len(d), 2):
            v = int(d[i], 16) << 4
            v |= int(d[i + 1], 16)
            response.append(v)

        return response
开发者ID:CospanDesign,项目名称:nysa-uart-platform,代码行数:31,代码来源:uart.py

示例2: get_capture_data

  def get_capture_data(self):
    """get_capture_data

    returns an array of the captured data

    Args:
      Nothing

    Return:
      Array of 32-bit unsigned values

    Raises:
      OlympusCommError: Error in communication
      LAError: Capture was not finished
    """
    if not self.is_capture_finished():
      raise LAError("Capture is not finished")


    #get the number of 32-bits to read
    count = self.get_data_count()
    
    print "Reading %d Vaues" % count

    data_in = self.o.read(self.dev_id, DATA, count)
    #change this to 32-bit value
    data_out = Array('L')
    print "Data in Lenght: %d" % len(data_in)
    print "Data length: %d" % len(data_out)

    for i in range(0, len(data_in), 4):
      data_out.append (data_in[i] << 24 | data_in[i + 1] << 16 | data_in[i + 2] << 8 | data_in[i + 3])

    return data_out
开发者ID:CospanDesign,项目名称:olympus,代码行数:34,代码来源:logic_analyzer.py

示例3: dword_to_array

def dword_to_array(value):
    out = Array('B')
    out.append((value >> 24) & 0xFF)
    out.append((value >> 16) & 0xFF)
    out.append((value >>  8) & 0xFF)
    out.append((value >>  0) & 0xFF)
    return out
开发者ID:CospanDesign,项目名称:nysa-tx1-pcie-platform,代码行数:7,代码来源:nysa_pcie.py

示例4: create_byte_array_from_dword

def create_byte_array_from_dword(dword):
    d = Array('B')
    d.append((dword >> 24) & 0xFF)
    d.append((dword >> 16) & 0xFF)
    d.append((dword >>  8) & 0xFF)
    d.append((dword >>  0) & 0xFF)
    return d
开发者ID:CospanDesign,项目名称:nysa-verilog,代码行数:7,代码来源:ppfifo_bus.py

示例5: read_dma_data

 def read_dma_data(self, count):
     d = Array('B')
     self.write_command(CMD_DMA_READ, count, 0x00)
     print "Send Peripheral Read Command"
     data = Array('B')
     data.fromstring(os.read(self.f, count * 4))
     print "Data: %s" % str(data)
     print_32bit_hex_array(d)
开发者ID:CospanDesign,项目名称:nysa-tx1-pcie-platform,代码行数:8,代码来源:nysa_pcie.py

示例6: fill_memory_with_pattern

    def fill_memory_with_pattern(self):
        position = 0
        #self.clear_memory()
        total_size = self.n.get_device_size(self.memory_urn)

        size = 0
        if total_size > MAX_LONG_SIZE:
            self.s.Verbose("Memory Size: 0x%08X is larger than write size" % total_size)
            self.s.Verbose("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        #Write Data Out
        data_out = Array('B')
        for i in range (0, size):
            data_out.append((i % 0x100))


        while position < total_size:
            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
            self.s.Verbose("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))
开发者ID:CospanDesign,项目名称:nysa,代码行数:29,代码来源:test_dma_sata.py

示例7: read_sdb

    def read_sdb(self, n = None):
        """
        Reads the SDB of the device, this is used to initialize the SDB Object
        Model with the content of the SDB on the host

        Args:
            n (Nysa Instance): A reference to nysa that the controller will
                use to extrapolate the SDB from the device

        Returns:
            Array of bytes consisting of SDB

        Raises:
            NysaCommError: Errors associated with communication
        """
        if n is None:
            n = self.n
        sdb_data = Array('B')
        #self.s.Important("Parsing Top Interconnect Buffer")
        #Because Nysa works with many different platforms we need to get the
        #platform specific location of where the SDB actually is
        sdb_base_address = n.get_sdb_base_address()
        self.som = som.SOM()
        self.som.initialize_root()
        bus = self.som.get_root()
        sdb_data.extend(_parse_bus(n, self.som, bus, sdb_base_address, sdb_base_address, self.s))
        sdb_data = n.read(sdb_base_address, len(sdb_data) / 4)
        return sdb_data
开发者ID:CospanDesign,项目名称:nysa,代码行数:28,代码来源:nysa_sdb_manager.py

示例8: memory_read_write_test

def memory_read_write_test(dut):

    dut.test_id <= 1

    print "module path: %s" % MODULE_PATH
    nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH])
    setup_dut(dut)
    yield(nysa.reset())
    nysa.read_sdb()
    yield (nysa.wait_clocks(10))
    nysa.pretty_print_sdb()
    driver = wb_master_testDriver(nysa, nysa.find_device(wb_master_testDriver)[0])
    yield (nysa.wait_clocks(10))
    dut.log.info("Ready")
    LENGTH = 100
    DATA = Array('B')
    for i in range (LENGTH):
        DATA.append(i % 256)

    while len(DATA) % 4 != 0:
        DATA.append(0)

    yield cocotb.external(nysa.write_memory)(0x00000, DATA)
    data = yield cocotb.external(nysa.read_memory)(0x00000, (len(DATA) / 4))
    for i in range (len(DATA)):
        if DATA[i] != data[i]:
            log.error("Failed at Address: %04d: 0x%02X != 0x%02X" % (i, DATA[i], data[i]))
开发者ID:CospanDesign,项目名称:nysa-verilog,代码行数:27,代码来源:test_dut.py

示例9: write

 def write(self, address, data):
     """SST25 uses a very specific implementation to write data. It offers
        very poor performances, because the device lacks an internal buffer
        which translates into an ultra-heavy load on SPI bus. However, the
        device offers lightning-speed for flash data erasure"""
     if address+len(data) > len(self):
         raise SerialFlashValueError('Cannot fit in flash area')
     if not isinstance(data, Array):
         data = Array('B', data)
     length = len(data)
     if (address&0x1) or (length&0x1) or (length==0):
         raise AssertionError("Alignement/size not supported")
     self._unprotect()
     self._enable_write()
     aai_cmd = Array('B', [Sst25FlashDevice.CMD_PROGRAM_WORD,
                           (address>>16)&0xff,
                           (address>>8)&0xff,
                           address&0xff,
                           data.pop(0), data.pop(0)])
     offset = 0
     percent = 0.0
     while True:
         percent = (1000.0*offset/length)
         offset += 2
         self._spi.exchange(aai_cmd)
         while self.is_busy():
             time.sleep(0.01) # 10 ms
         if not data:
             break
         aai_cmd = Array('B', [Sst25FlashDevice.CMD_PROGRAM_WORD,
                               data.pop(0), data.pop(0)])
     self._disable_write()
开发者ID:etihwnad,项目名称:pyftdi,代码行数:32,代码来源:serialflash.py

示例10: UARTCommReader

class UARTCommReader(BusDriver):

    _signals = ["rd_data", "rd_stb"]

    def __init__(self, entity, name, clock):
        BusDriver.__init__(self, entity, name, clock)
        self.read_data_busy = Lock("%s_wbusy" % name)
        self.data = Array('B')

    @cocotb.coroutine
    def read(self, size):
        yield self.read_data_busy.acquire()
        self.data = Array('B')
        count = 0
        while count < size:
            yield ReadOnly()
            yield RisingEdge(self.clock)
            if self.bus.rd_stb.value == 1:
                self.data.append(self.bus.rd_data.value)
                count += 1

        yield RisingEdge(self.clock)
        self.read_data_busy.release()

    def get_data(self):
        return self.data
开发者ID:CospanDesign,项目名称:nysa-verilog,代码行数:26,代码来源:cocotb_uart_if.py

示例11: stream_read_write_bram

def stream_read_write_bram(dut):
    """
    Description:
        Read and write data to the block ram

    Test ID: 2

    Expected Results:
        Write Data the Block RAM through Wishbone interface
        Read Same data from the block RAM through wishbone interface
    """
    dut.test_id = 2
    nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH])
    setup_dut(dut)
    yield(nysa.reset())
    nysa.read_sdb()
    yield(nysa.wait_clocks(10))
    driver = wb_hs_demoDriver(nysa, nysa.find_device(wb_hs_demoDriver)[0])
    data = Array('B')
    SIZE =1024
    for i in range(SIZE):
        data.append(i % 256)

    yield cocotb.external(driver.write_data)(0x00, data)
    yield (nysa.wait_clocks(100))
    v = yield cocotb.external(driver.read_data)(0x00, (SIZE / 4))

    if len(v) != len(data):
        raise cocotb.result.TestFailure("Test %d: Length of incomming data and outgoing data is equal %d = %d" % (dut.test_id, len(v), len(data)))

    for i in range(len(data)):
        if v[i] != data[i]:
            raise cocotb.result.TestFailure("Test %d: Address 0x%02X 0x%02X != 0x%02X" % (dut.test_id, i, v[i], data[i]))

    dut.log.info("Success")
开发者ID:CospanDesign,项目名称:nysa-verilog,代码行数:35,代码来源:test_dut.py

示例12: _set_frequency

 def _set_frequency(self, frequency):
     """Convert a frequency value into a TCK divisor setting"""
     if frequency > self.frequency_max:
         raise FtdiError("Unsupported frequency: %f" % frequency)
     if frequency <= Ftdi.BUS_CLOCK_BASE:
         divcode = Ftdi.ENABLE_CLK_DIV5
         divisor = int(Ftdi.BUS_CLOCK_BASE/frequency)-1
         actual_freq = Ftdi.BUS_CLOCK_BASE/(divisor+1)
     elif frequency <= Ftdi.BUS_CLOCK_HIGH:
         # not supported on non-H device, however it seems that 2232D
         # devices simply ignore the settings. Could be improved though
         divcode = Ftdi.DISABLE_CLK_DIV5
         divisor = int(Ftdi.BUS_CLOCK_HIGH/frequency)-1
         actual_freq = Ftdi.BUS_CLOCK_HIGH/(divisor+1)
     else:
         raise FtdiError("Unsupported frequency: %f" % frequency)
     # FTDI expects little endian
     if self.ic_name in self.HISPEED_DEVICES:
         cmd = Array('B', (divcode,))
     else:
         cmd = Array('B')
     cmd.extend((Ftdi.TCK_DIVISOR, divisor & 0xff, (divisor >> 8) & 0xff))
     self.write_data(cmd)
     self.validate_mpsse()
     # Drain input buffer
     self.purge_rx_buffer()
     return actual_freq
开发者ID:kery-chen,项目名称:pyftdi,代码行数:27,代码来源:ftdi.py

示例13: clear_memory

    def clear_memory(self):
        total_size = self.n.get_device_size(self.urn)
        offset = self.n.get_device_address(self.urn)
        position = 0
        size = 0
        if self.status.is_command_line():
            self.status.Verbose( "Clearing Memory")
            self.status.Verbose( "Memory Size: 0x%08X" % size)

        if total_size > MAX_LONG_SIZE:
            self.status.Info("Memory Size: 0x%08X is larger than read/write size" % total_size)
            self.status.Info("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while position < total_size:
            data_out = Array('B')
            for i in range(0, ((size / 4) - 1)):
                num = 0x00
                data_out.append(num)

            self.n.write_memory(offset + position, data_out)

            #Increment the position
            prev_pos = position
            position += size

            if position + size > total_size:
                size = total_size - position

            if self.status:
                self.status.Verbose("Cleared: 0x%08X - 0x%08X" % (prev_pos, position))
开发者ID:CospanDesign,项目名称:nysa-gui,代码行数:33,代码来源:controller.py

示例14: clear_memory

    def clear_memory(self):
        total_size = self.n.get_device_size(self.urn)
        position = 0
        size = 0
        print ( "Clearing Memory")
        print ( "Memory Size: 0x%08X" % size)

        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" % total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while position < total_size:
            data_out = Array('B')
            for i in range (0, size):
                data_out.append(0x00)

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
开发者ID:CospanDesign,项目名称:nysa,代码行数:27,代码来源:test_memory.py

示例15: read_command

    def read_command(self, address, length):
        """
        read data or status from the MCU, the length specifies how much
        data to read from the MCU after the address is written

        Args:
            address (integer): register address to write to
            length (integer): number of bytes to read from the register

        Returns:
            (Array of bytes) 8-bit value of the register

        Raises:
            NysaCommError: Error in communication
        """
        output = Array('B')
        #Get the control register
        self.set_register_bit(CONTROL, CONTROL_COMMAND_MODE)
        #Tell the lcd command controller we are sending the command
        self.clear_register_bit(CONTROL, CONTROL_COMMAND_PARAMETER)
        #Put the data in the register
        self.write_register(COMMAND_DATA, address)
        #We are going to be writing
        self.set_register_bit(CONTROL, CONTROL_COMMAND_WRITE)
        for i in range (length):
            #Tell the lcd command controller we are sending parameters
            self.set_register_bit(CONTROL, CONTROL_COMMAND_PARAMETER)
            #We are going to be reading
            self.set_register_bit(CONTROL, CONTROL_COMMAND_READ)

            #Read the data from the data register
            output.append(self.read_register(COMMAND_DATA))

        self.clear_register_bit(CONTROL, CONTROL_COMMAND_MODE)
        return output
开发者ID:CospanDesign,项目名称:nysa,代码行数:35,代码来源:lcd_SSD1963.py


注:本文中的array.array类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。