Skip to content

Commit f8648f5

Browse files
committed
Add simple testing notebook that demonstrates functionality of PrawnDO
using an oscilloscope to measure channels 0-3.
1 parent 6fdaf32 commit f8648f5

File tree

3 files changed

+628
-1
lines changed

3 files changed

+628
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build*/*
22
.vscode
33
.DS_Store
44
cmake-*
5-
pico_sdk_import.cmake
5+
pico_sdk_import.cmake
6+
*.pyc

testing/KeysightScope.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import pyvisa
2+
3+
class KeysightScope:
4+
"""
5+
Helper class using pyvisa for a USB connected Keysight Oscilloscope
6+
"""
7+
def __init__(self,
8+
addr='USB?*::INSTR',
9+
timeout=1,
10+
termination='\n'
11+
):
12+
rm = pyvisa.ResourceManager()
13+
devs = rm.list_resources(addr)
14+
assert len(devs), "pyvisa didn't find any connected devices matching " + addr
15+
self.dev = rm.open_resource(devs[0])
16+
self.dev.timeout = 15_000 * timeout
17+
self.dev.read_termination = termination
18+
self.idn = self.dev.query('*IDN?')
19+
self.read = self.dev.read
20+
self.write = self.dev.write
21+
self.query = self.dev.query
22+
23+
def _get_screenshot(self, verbose=False):
24+
if verbose == True:
25+
print('Acquiring screen image...')
26+
return(self.dev.query_binary_values(':DISPlay:DATA? PNG, COLor', datatype='s'))
27+
28+
def get_screenshot(self):
29+
30+
result = self._get_screenshot()
31+
32+
return bytes(result)
33+
34+
def save_screenshot(self, filepath: str, verbose=False, inksaver=False):
35+
if verbose == True:
36+
print('Saving screen image...')
37+
result = self._get_screenshot()
38+
39+
# Keysight scope defaults to inksaving for image save
40+
if inksaver == True:
41+
self.dev.write(':HARDcopy:INKSaver 1')
42+
else:
43+
self.dev.write(':HARDcopy:INKSaver OFF')
44+
45+
with open(f'{filepath}', 'wb+') as ofile:
46+
ofile.write(bytes(result))
47+
48+
def set_time_delay(self, time: float):
49+
50+
self.write(f':TIMebase:DELay {time}')
51+
52+
def set_time_scale(self, time: float):
53+
self.write(f':TIMebase:SCALe {time}')
54+
55+
def annotate_screen(self, message: str):
56+
self.write(f':DISPlay:ANNotation:TEXT "{message}"')
57+
58+
def set_math_scale(self, scale: float):
59+
self.write(f'FUNCtion:SCALe {scale}')
60+
61+
def set_math_offset(self, offset: float):
62+
self.write(f'FUNCtion:OFFSet {offset}')
63+
64+
def channel_state(self, channel: int, state: int):
65+
"""
66+
Turn on or off a channel
67+
state: int (ON: 1 or OFF: 0)
68+
"""
69+
self.write(f':CHANnel{channel}:DISPlay {state}')
70+
71+
def set_channel_offset(self, channel: int, y_offset: float):
72+
self.write(f':CHANnel{channel}:OFFSet {y_offset}')
73+
74+
def set_channel_scale(self, channel: int, y_scale: float):
75+
self.write(f':CHANnel{channel}:SCALe {y_scale}')

testing/basic_tests.ipynb

Lines changed: 551 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)