Skip to content

Commit 38c5a94

Browse files
author
neil.hamilton
committed
Create usbdrdaqExamples/usbdrdaqPhBlockExample.py
1 parent 164425f commit 38c5a94

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#
2+
# Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
# USBDRDAQ SCOPE BLOCK MODE EXAMPLE
5+
# This example opens a UsbDrDaq driver device, sets up the scope channel and a trigger then collects a single block of data.
6+
# This data is then plotted as mV against time in ns.
7+
8+
import ctypes
9+
import time
10+
from picosdk.usbDrDaq import usbDrDaq as drDaq
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
from picosdk.functions import adc2mV, assert_pico_ok
14+
15+
# Create chandle and status ready for use
16+
status = {}
17+
chandle = ctypes.c_int16()
18+
19+
# Opens the device
20+
status["openunit"] = drDaq.UsbDrDaqOpenUnit(ctypes.byref(chandle))
21+
assert_pico_ok(status["openunit"])
22+
23+
# Set sample interval
24+
us_for_block = ctypes.c_int32(1000)
25+
ideal_no_of_samples = 1000
26+
channels = ctypes.c_int32(drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_PH"])
27+
no_of_channels = 1
28+
status["setInterval"] = drDaq.UsbDrDaqSetInterval(chandle, ctypes.byref(us_for_block), ideal_no_of_samples, ctypes.byref(channels), no_of_channels)
29+
assert_pico_ok(status["setInterval"])
30+
31+
# Find scaling information
32+
channel = drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_PH"]
33+
nScales = ctypes.c_int16(0)
34+
currentScale = ctypes.c_int16(0)
35+
names = (ctypes.c_char*256)()
36+
namesSize = 256
37+
status["getscalings"] = drDaq.UsbDrDaqGetScalings(chandle, channel, ctypes.byref(nScales), ctypes.byref(currentScale), ctypes.byref(names), namesSize)
38+
assert_pico_ok(status["getscalings"])
39+
40+
print(nScales.value)
41+
print(currentScale.value)
42+
print(names.value)
43+
44+
# Set channel scaling
45+
scalingNumber = 0 # pH scaling
46+
status["setscaling"] = drDaq.UsbDrDaqSetScalings(chandle, channel, scalingNumber)
47+
assert_pico_ok(status["setscaling"])
48+
49+
# Set temperature compenstation
50+
enabled = 1
51+
status["phTemperatureCompensation"] = drDaq.UsbDrDaqPhTemperatureCompensation(chandle, enabled)
52+
assert_pico_ok(status["phTemperatureCompensation"])
53+
54+
# Run block capture
55+
method = drDaq.USB_DRDAQ_BLOCK_METHOD["BM_SINGLE"]
56+
status["run"] = drDaq.UsbDrDaqRun(chandle, ideal_no_of_samples, method)
57+
assert_pico_ok(status["run"])
58+
59+
ready = ctypes.c_int16(0)
60+
61+
while ready.value == 0:
62+
status["ready"] = drDaq.UsbDrDaqReady(chandle, ctypes.byref(ready))
63+
print(ready.value)
64+
time.sleep(0.1)
65+
66+
# Retrieve data from device
67+
values = (ctypes.c_float * ideal_no_of_samples)()
68+
noOfValues = ctypes.c_uint32(ideal_no_of_samples)
69+
overflow = ctypes.c_uint16(0)
70+
triggerIndex = ctypes.c_uint32(0)
71+
status["getvaluesF"] = drDaq.UsbDrDaqGetValuesF(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(overflow), ctypes.byref(triggerIndex))
72+
assert_pico_ok(status["getvaluesF"])
73+
74+
# generate time data
75+
time = np.linspace(0, us_for_block, ideal_no_of_samples)
76+
77+
# plot the data
78+
plt.plot(time, values[:])
79+
plt.xlabel('Time (ns)')
80+
plt.ylabel('pH')
81+
plt.show()
82+
83+
84+
# Disconnect the scope
85+
# handle = chandle
86+
status["close"] = drDaq.UsbDrDaqCloseUnit(chandle)
87+
assert_pico_ok(status["close"])
88+
89+
# Display status returns
90+
print(status)

0 commit comments

Comments
 (0)