Skip to content

Commit 4eeab99

Browse files
author
neil.hamilton
committed
Complete pl1000Examples/pl1000StreamingModeExample.py
1 parent e08a217 commit 4eeab99

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pl1000Examples/pl1000StreamingModeExample.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
from picosdk.pl1000 import pl1000 as pl
1111
import matplotlib.pyplot as plt
12-
from picosdk.functions import adc2mV, assert_pico_ok
12+
from picosdk.functions import adc2mVpl1000, assert_pico_ok
1313
from time import sleep
1414

1515
# Create chandle and status ready for use
@@ -22,25 +22,43 @@
2222

2323
# set sampling interval
2424
usForBlock = ctypes.c_uint32(10000000)
25-
noOfValues = ctypes.c_uint32(100000000)
25+
noOfValues = ctypes.c_uint32(1000000)
2626
channels = ctypes.c_int16(1)
2727

2828
status["setInterval"] = pl.pl1000SetInterval(chandle, ctypes.byref(usForBlock), noOfValues, ctypes.byref(channels), 1)
2929
assert_pico_ok(status["setInterval"])
3030

3131
# start streaming
3232
mode = pl.PL1000_BLOCK_METHOD["BM_STREAM"]
33-
status["run"] = pl.pl1000Run(chandle, noOfValues, mode)
33+
status["run"] = pl.pl1000Run(chandle, 1000000, mode)
3434
assert_pico_ok(status["run"])
3535

36-
sleep(5)
36+
sleep(usForBlock.value / 1000000)
3737

38-
values = (ctypes.c_uint16 * noOfValues)()
38+
values = (ctypes.c_uint16 * noOfValues.value)()
3939
oveflow = ctypes.c_uint16()
4040

4141
status["getValues"] = pl.pl1000GetValues(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(oveflow), None)
4242
assert_pico_ok(status["getValues"])
4343

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()
4462

4563
# close PicoLog 1000 device
4664
status["closeUnit"] = pl.pl1000CloseUnit(chandle)

0 commit comments

Comments
 (0)