How to introspect a PandA#

Using a combination of commands it is straightforward to query the PandA to list all blocks, and all fields inside each block, that exist.

Call the following script, with the address of the PandA as the first and only command line argument:

import asyncio
import pprint
import sys

from pandablocks.asyncio import AsyncioClient
from pandablocks.commands import GetBlockInfo, GetFieldInfo, GetPcapBitsLabels


async def introspect():
    # Create a client and connect the control and data ports
    async with AsyncioClient(sys.argv[1]) as client:
        # Get the list of all blocks in the PandA
        block_info = await client.send(GetBlockInfo())
        # Find and print all fields for each block
        for block in block_info:
            field_info = await client.send(GetFieldInfo(block))
            pprint.pprint({block: field_info})

        # Get the labels for every PCAP.BITS[n] fields
        labels = await client.send(GetPcapBitsLabels())
        pprint.pprint(labels)


if __name__ == "__main__":
    # One-shot run of a co-routine
    asyncio.run(introspect())

This script can be found in examples/introspect_panda.py.

By examining the BlockInfo structure returned from GetBlockInfo for each Block the number and description may be acquired for every block.

By examining the FieldInfo structure (which is fully printed in this example) the type, sub-type, description and label may all be found for every field.

Lastly the complete list of every BITS field in the PCAP block are gathered and printed. See the documentation in the Field Types section of the PandA Server documentation.