Example #1
0
    def read(self, addr, length=None, burst="incr"):
        length_int = 1 if length is None else length
        # prepare packet
        record = EtherboneRecord()
        incr = (burst == "incr")
        record.reads = EtherboneReads(addrs=[
            self.base_address + addr + 4 * incr * j for j in range(length_int)
        ])
        record.rcount = len(record.reads)

        # send packet
        packet = EtherbonePacket()
        packet.records = [record]
        packet.encode()
        self.send_packet(self.socket, packet[:])

        # receive response
        packet = EtherbonePacket(self.receive_packet(self.socket))
        packet.decode()
        datas = packet.records.pop().writes.get_datas()
        if self.debug:
            for i, data in enumerate(datas):
                print("read {:08x} @ {:08x}".format(
                    data, self.base_address + addr + 4 * i))
        return datas[0] if length is None else datas
Example #2
0
    def read(self, addr, length=None, burst="incr"):
        """
        addr = start address in [bytes], should be 32 bit aligned
        length = number of 32 bit words to read. Maximum is 255.
        """
        length_int = 1 if length is None else length
        # Prepare packet
        record = EtherboneRecord()
        incr = (burst == "incr")
        record.reads = EtherboneReads(addrs=[
            self.base_address + addr + 4 * incr * j for j in range(length_int)
        ])
        record.rcount = len(record.reads)

        # Send packet
        packet = EtherbonePacket()
        packet.records = [record]
        packet.encode()
        self.send_packet(self.socket, packet)

        # Receive response
        packet = EtherbonePacket(self.receive_packet(self.socket))
        packet.decode()
        datas = packet.records.pop().writes.get_datas()
        if self.debug:
            for i, data in enumerate(datas):
                print("read 0x{:08x} @ 0x{:08x}".format(
                    data, self.base_address + addr + 4 * i))
        return datas[0] if length is None else datas
Example #3
0
    def read(self, addr, length=None):
        length_int = 1 if length is None else length
        record = EtherboneRecord()
        record.reads = EtherboneReads(
            addrs=[addr + 4 * j for j in range(length_int)])
        record.rcount = len(record.reads)

        packet = EtherbonePacket()
        packet.records = [record]
        packet.encode()
        self.socket.sendto(bytes(packet), (self.server, self.port))

        datas, dummy = self.socket.recvfrom(8192)
        packet = EtherbonePacket(datas)
        packet.decode()
        datas = packet.records.pop().writes.get_datas()
        if self.debug:
            for i, value in enumerate(datas):
                print("read {:08x} @ {:08x}".format(value, addr + 4 * i))
        return datas[0] if length is None else datas