Skip to content

Commit

Permalink
example: use and load data
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-palacio committed May 16, 2024
1 parent c83192f commit d9dbe2b
Showing 1 changed file with 206 additions and 0 deletions.
206 changes: 206 additions & 0 deletions examples/ppg3204_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test para cargar una secuencia predefinida al PPG3204"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"from opticomlib.devices import PRBS\n",
"from opticomlib.ppm import PPM_ENCODER\n",
"from opticomlib.lab import PPG3204, search_inst\n",
"\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creamos la secuencia binaria, en este caso PPM"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"M = 4\n",
"\n",
"N_slots = 2**16\n",
"N_bits = int(N_slots // M * np.log2(M))\n",
"\n",
"bits = PRBS(order=31, len=N_bits)\n",
"slots = PPM_ENCODER(bits, M).data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Buscamos el ID del dispositivo y establecemos conexión"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('ASRL3::INSTR', 'ASRL4::INSTR', 'USB::0x0699::0x3130::9211219::INSTR')\n"
]
}
],
"source": [
"search_inst()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tektronix Inc., 12592,9211219,1.7.8.5_3.4_3.4\n",
"\n"
]
}
],
"source": [
"ppg = PPG3204(addr_ID=\"USB::0x0699::0x3130::9211219::INSTR\") # if addr_ID is None, it will print commands instead of sending them"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuramos el PPG y cargamos los datos\n",
"\n",
"documentación: https://opticomlib.readthedocs.io/en/latest/lab.html#opticomlib.lab.PPG3204"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Done'"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ppg(\n",
" patt_len=N_slots, \n",
" Vout=0.3, \n",
" offset=0,\n",
" mode=\"DATA\",\n",
" data=slots,\n",
" CHs=1,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Done'"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ppg(\n",
" Vout=0.3, \n",
" offset=0,\n",
" mode=\"PRBS\",\n",
" CHs=1,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Verificamos que los datos se hayan cargado correctamente"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
" 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,\n",
" 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,\n",
" 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,\n",
" 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,\n",
" 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,\n",
" 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
" 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]], dtype=uint8)"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ppg.get_data(size=200, start_addrs=1, CHs=1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ppm_simulator",
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit d9dbe2b

Please sign in to comment.