-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenscope.py
More file actions
57 lines (46 loc) · 1.69 KB
/
openscope.py
File metadata and controls
57 lines (46 loc) · 1.69 KB
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
# -*- coding: utf-8 -*-
import requests
import re
import json
import numpy
import pprint
url = 'http://localhost:42135'
#url = 'http://10.190.76.108'
pp = pprint.PrettyPrinter(indent=4)
payload = {"device": [{"command": "enumerate"}]}
r = requests.post(url, json=payload)
pp.pprint(r.json())
payload = {'osc': {'1': [{"command": "getCurrentState"}]}}
r = requests.post(url, json=payload)
pp.pprint(r.json())
'''
payload = {"awg":{"1":[{"command":"stop"},
{"command":"setRegularWaveform",
"signalType":"square",
"signalFreq":1000000,
"vpp":3000,
"vOffset":0},
{"command":"run"}]}}
r = requests.post(url, json=payload)
'''
payload = {"trigger":{"1":[{"command":"single"}]}}
r = requests.post(url, json=payload)
payload = {'osc': {'1': [{'command': 'read', 'acqCount': 1}]}}
r = requests.post(url, json=payload)
result = re.split(b'\r\n',r.content)
# Decode bytes, and convert single quotes to double quotes for valid JSON
str_json = result[1].decode('ASCII').replace("'", '"')
# Load the JSON to a Python list & pretty print formatted JSON
my_json = json.loads(str_json)
pp.pprint(my_json)
data = result[4]
if (False):
with open("filename.bin", "wb") as file:
for byte in data:
file.write(byte.to_bytes(1, byteorder='big'))
SampleFreq = my_json['osc']['1'][0]['actualSampleFreq']/1000
mvolts=numpy.zeros(len(data)//2)
for i in range(0, len(data)-2, 2):
mvolts[i//2] = int.from_bytes(data[i:i+2], byteorder='little', signed=True)
volts = mvolts / 1000
t = numpy.arange(len(volts)) / SampleFreq