-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPS9400PythonExample.py
71 lines (59 loc) · 2.28 KB
/
PS9400PythonExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright © 2020-2022 Pico Technology Ltd. See LICENSE file for terms.
#
"""
This is a Python script for controlling a PicoScope 9400 Series Sampling Oscilloscope using the PicoSample4 COM object.
This will also work using the demo device in PicoSample4.
"""
import win32com.client
import numpy as np
import matplotlib.pyplot as plt
import time
COMRCW = win32com.client.Dispatch("PicoSample4.COMRC") # create COM object
COMRCW.ExecCommand("Gui:Control:Invisible")
# Set up measurements
COMRCW.ExecCommand("Meas:Display:Param")
COMRCW.ExecCommand("Meas:DisplSrc:Ch1")
COMRCW.ExecCommand("Meas:Mode:Single")
COMRCW.ExecCommand("Meas:Ch1:XParam:Freq 1")
COMRCW.ExecCommand("Meas:Ch1:XParam:Rise 1")
COMRCW.ExecCommand("Meas:Ch1:YParam:Max 1")
COMRCW.ExecCommand("Meas:Ch1:YParam:Min 1")
COMRCW.ExecCommand("Meas:Ch1:YParam:PP 1")
COMRCW.ExecCommand("*RunControl:Single") # Set running mode of scope
time.sleep(2)
COMRCW.ExecCommand("Header Off") # Turn off headers for returned values
strdata = COMRCW.ExecCommand("Wfm:Data?") # Get wfm data for ch1
YU = COMRCW.ExecCommand("Wfm:Preamb:YU?") # Get y scale units
XU = COMRCW.ExecCommand("Wfm:Preamb:XU?") # Get x scale units
XInc = COMRCW.ExecCommand("Wfm:Preamb:XInc?") # Get time sample interval
XOrg = COMRCW.ExecCommand("Wfm:Preamb:XOrg?") # Get y axis origin
# Measurements
freq = COMRCW.ExecCommand("Meas:Res:1?")
print("Frequency = " + str(freq))
riseTime = COMRCW.ExecCommand("Meas:Res:2?")
print("Rise Time = " + str(riseTime))
maximum = COMRCW.ExecCommand("Meas:Res:3?")
print("Maximum = " + str(maximum))
minimum = COMRCW.ExecCommand("Meas:Res:4?")
print("Minimum = " + str(minimum))
Pp = COMRCW.ExecCommand("Meas:Res:5?")
print("Peak-to-Peak = " + str(Pp))
# Convert data to array of floats
strdata = str(strdata)
strdata = strdata.split(',')
strdata = np.asarray(strdata)
data = strdata.astype(float)
# Create time data array
totaltime = len(data) * float(XInc)
totaltime = float(totaltime)
datatime = np.linspace(0, totaltime, len(data))
# Plot data
plt.plot(datatime, data)
plt.title('PicoScope 9400 Series Single Acquisition Example')
plt.xlabel('Time (' + XU +')')
plt.ylabel('Voltage (' + YU +')')
plt.show()
COMRCW = 1