|
| 1 | +# |
| 2 | +# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. |
| 3 | +# |
| 4 | +# PL1000 SINGLE MODE EXAMPLE |
| 5 | +# This example opens a pl1000 device, sets up the device for capturing data from channel 1. |
| 6 | +# Then this example collect a sample from channel 1 and displays it on the console. |
| 7 | + |
| 8 | +import ctypes |
| 9 | +import numpy as np |
| 10 | +from picosdk.pl1000 import pl1000 as pl |
| 11 | +import matplotlib.pyplot as plt |
| 12 | +from picosdk.functions import adc2mVpl1000, assert_pico_ok |
| 13 | +from time import sleep |
| 14 | + |
| 15 | +# Create chandle and status ready for use |
| 16 | +chandle = ctypes.c_int16() |
| 17 | +status = {} |
| 18 | + |
| 19 | +# open PicoLog 1000 device |
| 20 | +status["openUnit"] = pl.pl1000OpenUnit(ctypes.byref(chandle)) |
| 21 | +assert_pico_ok(status["openUnit"]) |
| 22 | + |
| 23 | +# set sampling interval |
| 24 | +usForBlock = ctypes.c_uint32(10000000) |
| 25 | +noOfValues = ctypes.c_uint32(1000000) |
| 26 | +channels = ctypes.c_int16(1) |
| 27 | + |
| 28 | +status["setInterval"] = pl.pl1000SetInterval(chandle, ctypes.byref(usForBlock), noOfValues, ctypes.byref(channels), 1) |
| 29 | +assert_pico_ok(status["setInterval"]) |
| 30 | + |
| 31 | +# start streaming |
| 32 | +mode = pl.PL1000_BLOCK_METHOD["BM_STREAM"] |
| 33 | +status["run"] = pl.pl1000Run(chandle, 1000000, mode) |
| 34 | +assert_pico_ok(status["run"]) |
| 35 | + |
| 36 | +sleep(usForBlock.value / 1000000) |
| 37 | + |
| 38 | +values = (ctypes.c_uint16 * noOfValues.value)() |
| 39 | +oveflow = ctypes.c_uint16() |
| 40 | + |
| 41 | +status["getValues"] = pl.pl1000GetValues(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(oveflow), None) |
| 42 | +assert_pico_ok(status["getValues"]) |
| 43 | + |
| 44 | +# convert ADC counts data to mV |
| 45 | +maxADC = ctypes.c_uint16() |
| 46 | +status["maxValue"] = pl.pl1000MaxValue(chandle, ctypes.byref(maxADC)) |
| 47 | +assert_pico_ok(status["maxValue"]) |
| 48 | +inputRange = 2500 |
| 49 | +mVValues = adc2mVpl1000(values, inputRange, maxADC) |
| 50 | + |
| 51 | +# create time data |
| 52 | +interval = (0.01 * usForBlock.value)/(noOfValues.value * 1) |
| 53 | + |
| 54 | +timeMs = np.linspace(0, (len(mVValues)) * interval, len(mVValues)) |
| 55 | + |
| 56 | +# plot data |
| 57 | + |
| 58 | +plt.plot(timeMs, mVValues[:]) |
| 59 | +plt.xlabel('Time (ms)') |
| 60 | +plt.ylabel('Voltage (mV)') |
| 61 | +plt.show() |
| 62 | + |
| 63 | +# close PicoLog 1000 device |
| 64 | +status["closeUnit"] = pl.pl1000CloseUnit(chandle) |
| 65 | +assert_pico_ok(status["closeUnit"]) |
| 66 | + |
| 67 | +# display status returns |
| 68 | +print(status) |
0 commit comments