Last active
September 19, 2015 20:41
-
-
Save pklaus/d16fcffe335ce520a0eb to your computer and use it in GitHub Desktop.
Displaying waveforms of the DS1054Z oscilloscope with Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A processing script to display waveforms | |
https://gist.github.com/pklaus/d16fcffe335ce520a0eb | |
*/ | |
byte data[]; | |
int a, b; | |
void setup() | |
{ | |
size(1200, 768, P3D); | |
background(0); | |
frameRate(30); | |
} | |
void draw() | |
{ | |
data = loadBytes("/dev/shm/wfm.dat"); | |
fill(0, 32, 0, 32); | |
rect(0, 0, width, height); | |
stroke(32); | |
for (int i = 0; i < 13 ; i++){ | |
line(i*100, 0, i*100, height); | |
} | |
for (int i = 0; i < 9 ; i++){ | |
line(0, i*96, width, i*96); | |
} | |
stroke(0); | |
line(width/2, 0, width/2, height); | |
line(0, height/2, width, height/2); | |
stroke (128,255,128); | |
if (data.length < 1) return; | |
b = data[0] & 0xff; | |
b = 128 - b; | |
for(int i = 0; i < data.length - 1; i++) | |
{ | |
a = b; | |
b = data[i+1] & 0xff; | |
b = 128 - b; | |
line(i, height/2 + a*3, i+1, height/2 + b*3); | |
} | |
println(frameRate); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import re | |
import ds1054z # https://pypi.python.org/pypi/ds1054z | |
from universal_usbtmc.exceptions import * | |
ds = ds1054z.DS1054Z('TCPIP::192.168.178.74::INSTR') | |
#ds = ds1054z.DS1054Z('TCPIP::192.168.178.74::5555::SOCKET') | |
#ds = ds1054z.DS1054Z('USB::0x1ab1::0x04ce::INSTR') | |
#ds = ds1054z.DS1054Z('/dev/usbtmc0', 'linux_kernel') | |
print("IDN:", ds.idn) | |
class ConnectionProblem(Exception): pass | |
ds.write(':WAVEFORM:SOURCE CHAN2') | |
start = time.perf_counter() | |
i = 0 | |
ntimeout = 0 | |
try: | |
while True: | |
if ntimeout > 10: raise ConnectionProblem() | |
print('getting waveform {}'.format(i)) | |
try: | |
ret = ds.query_raw(':WAVEFORM:DATA?') | |
ntimeout = 0 | |
except UsbtmcReadTimeoutError: | |
ntimeout += 1 | |
continue | |
i += 1 | |
try: | |
assert ret.startswith(b'#9000001200') | |
vals = [int(val) for val in ret[11:-1]] | |
with open('/dev/shm/wfm.dat', 'wb') as f: | |
f.write(bytes(vals)) | |
except: | |
print("Data invalid? - " + str(ret)) | |
except KeyboardInterrupt: | |
pass | |
except ConnectionProblem: | |
print('Could not reach the device repeatedly') | |
end = time.perf_counter() | |
fmt = "Received {} waveforms in {:.3f} seconds (= {:.2f} wfm/s)" | |
print(fmt.format(i, end-start, i/(end-start))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment