AsyncIO¶
The Register File Python API is compatible with the Python asyncio library, allowing users to directly leverage asyncio to develop the readout software.
One of the reasons for this choice is that the CoCoTb simulation environment we are using relies on asyncio, which allows us to write Verification Testbenches that are using the software library directly.
It is not mandatory to use asyncio to its full capability to work with the readout, however any call to the hardware will have to run in an asyncio context.
Single Hardware Calls with AsyncIO¶
When writting simple test scripts, each hardware call can be called in asyncio in a block way using the asyncio.run()
method.
This method is convenient for quick tests, but it doesn't leverage asyncio, so it is not recommended to write scripts that use this method for actual data readout.
For example:
1 2 3 4 5 6 7 |
|
Using an AsyncIO main function¶
If a script performs more I/O operations for a measurement or a test, it is then recommended to write code in an asyncio context, meaning in an async definition.
To do this:
- Write an async function which will be the new "main"
- Run the new async main using
asyncio.run()
asyncio.run()
will block until your main function is done
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Example: Read FPGA Temperature for a couple seconds¶
This code example uses a Gecco Nexys Video with UART hardware
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|