lasp/examples/test_input.ipynb

198 lines
3.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "740b4091",
"metadata": {},
"source": [
"# Test DAQ input on a device"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac06df04",
"metadata": {},
"outputs": [],
"source": [
"!make -j -C ~/wip/mycode/lasp"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce0dd691",
"metadata": {},
"outputs": [],
"source": [
"import lasp\n",
"# Get handle to stream manager\n",
"mgr = lasp.StreamMgr.getInstance()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ad46772-a969-4693-b4e6-d78a67183787",
"metadata": {},
"outputs": [],
"source": [
"mgr.rescanDAQDevices()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cd242a8",
"metadata": {},
"outputs": [],
"source": [
"ds = mgr.getDeviceInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5d878e9",
"metadata": {},
"outputs": [],
"source": [
"# Search for a device\n",
"for i, d in enumerate(ds):\n",
" print(f'{i}: ' + d.device_name)\n",
"d = ds[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a456054e",
"metadata": {},
"outputs": [],
"source": [
"# Check the available block sizes\n",
"d.availableFramesPerBlock"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d5b281e",
"metadata": {},
"outputs": [],
"source": [
"# Create a configuration and enable some input channels\n",
"config = lasp.DaqConfiguration(d)\n",
"config.inchannel_config[0].enabled = True\n",
"config.inchannel_config[1].enabled = True\n",
"# Choose a different number of frames per block\n",
"config.framesPerBlockIndex = 4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ead3995",
"metadata": {},
"outputs": [],
"source": [
"print('Out channels:',d.noutchannels)\n",
"print('In channels:',d.ninchannels)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12db8306",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Start a stream with a configuration\n",
"mgr.startStream(config)\n",
"\n",
"def reset_cb():\n",
" print('Reset called')\n",
"\n",
"def cb(data):\n",
" # Print something on callback\n",
" print(data.shape)\n",
"\n",
"import time\n",
"#time.sleep(4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc751e51-3d09-41c8-a2dd-02d9568181da",
"metadata": {},
"outputs": [],
"source": [
"# Attach the indata handler to the stream\n",
"i = lasp.InDataHandler(mgr, cb, reset_cb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d9f0103",
"metadata": {},
"outputs": [],
"source": [
"mgr.stopStream(lasp.StreamMgr.StreamType.input)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61b7282f",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"del i"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99342a4d-16ff-4b0c-8994-4c7e6b3f97b8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bd21b65-5bfd-4f83-b420-8491ca3ade57",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}