forked from Ratfink/ds1054z-screen-capture
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrigol.py
74 lines (54 loc) · 1.98 KB
/
rigol.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
72
73
74
import sys
import requests
RIGOL_OUI = "00:19:af"
def dm3058_screenshot(instrument_ip, output_filename):
try:
response = requests.head(
'http://%s/DM3058_WebControl.html' % (instrument_ip))
if response.status_code != 200:
return None
except requests.exceptions.ConnectionError as ex:
print(ex, file=sys.stderr)
return None
with open(output_filename, "wb") as f:
response = requests.get("http://%s/pictures/Display.bmp" % (instrument_ip), stream=True)
if response.status_code != 200:
return None
total_length = int(response.headers.get('content-length'))
f.write(response.content)
return total_length
def command(tn, scpi):
answer_wait_s = 1
response = ""
while response != b"1\n":
tn.write("*OPC?\n") # previous operation(s) has completed ?
response = tn.read_until(b"\n", 1) # wait max 1s for an answer
tn.write(scpi + "\n")
response = tn.read_until(b"\n", answer_wait_s)
return response
# first TMC byte is '#'
# second is '0'..'9', and tells how many of the next ASCII chars
# should be converted into an integer.
# The integer will be the length of the data stream (in bytes)
# after all the data bytes, the last char is '\n'
def tmc_header_bytes(buff):
return 2 + int(buff[1:2])
def expected_data_bytes(buff):
return int(buff[2:tmc_header_bytes(buff)])
def expected_buff_bytes(buff):
return tmc_header_bytes(buff) + expected_data_bytes(buff) + 1
def get_memory_depth(tn):
# Define number of horizontal grid divisions for DS1054Z
h_grid = 12
# ACQuire:MDEPth
mdep = command(tn, ":ACQ:MDEP?")
# if mdep is "AUTO"
if mdep == "AUTO\n":
# ACQuire:SRATe
srate = command(tn, ":ACQ:SRAT?")
# TIMebase[:MAIN]:SCALe
scal = command(tn, ":TIM:SCAL?")
# mdep = h_grid * scal * srate
mdep = h_grid * float(scal) * float(srate)
# return mdep
return int(mdep)