|
| 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 adc2mV, 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(100000000) |
| 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, noOfValues, mode) |
| 34 | +assert_pico_ok(status["run"]) |
| 35 | + |
| 36 | +sleep(5) |
| 37 | + |
| 38 | +values = (ctypes.c_uint16 * noOfValues)() |
| 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 | + |
| 45 | +# close PicoLog 1000 device |
| 46 | +status["closeUnit"] = pl.pl1000CloseUnit(chandle) |
| 47 | +assert_pico_ok(status["closeUnit"]) |
| 48 | + |
| 49 | +# display status returns |
| 50 | +print(status) |
0 commit comments