-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_TDS3054B.py
64 lines (57 loc) · 1.99 KB
/
read_TDS3054B.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
import requests
import numpy as np
import matplotlib.pyplot as plt
import time
import datetime
import os
import h5py
from pi_stage import PI_stage
response = requests.post(
'http://129.27.156.205/Comm.html', data={'COMMAND': 'DATA:SOURCE?'})
dataSource = response.text[634:-93]
if dataSource == 'CH1':
print('The data source is <' + dataSource +'>.')
pass
else:
response = requests.post(
'http://129.27.156.205/Comm.html', data={'COMMAND': 'DATA:SOURCE CH1'})
print('The data source is modified to <' + dataSource +'>.')
sweepTime = 100 #seconds
numCycle = 1 # number of cycle after initiation of the wave generator
numSweeps = 30 # number of sweeps
stage = PI_stage('COM23')
stage.setSweepTime(100)
stage.setCycleNum(numCycle)#number of the cycle after initiate the wave generator
now = datetime.datetime.now()
os.makedirs(
now.strftime('%Y-%m') + '/'
+ now.strftime('%Y-%m-%d'), exist_ok=True)
fname = (now.strftime('%Y-%m') + '/'
+ now.strftime('%Y-%m-%d')
+ '/scan_osc_'
+ now.strftime('%Y-%m-%d-%H-%M-%S'))
with h5py.File(fname + '.hdf5', 'w') as f:
for i in range(numSweeps):
stage.move_absolute_um(0)
time.sleep(0.5)
stage.initWaveGen()
print('This is the No.' + str(i) + ' sweep.')
time.sleep(sweepTime+1)
stage.stopWaveGen()
response = requests.post(
'http://129.27.156.205/Comm.html', data={'COMMAND': 'CURVe?'})
r = response.text
endOfHeader = r.find("NAME=\"name\""+">")+len("NAME=\"name\""+">")
endOfData = r.find("</TEXTAREA>")
data = r[endOfHeader:endOfData] # remove the header info from the response
data = np.fromstring(data, sep=',') # 10k points
#print(data.shape)
#plt.plot(data)
#plt.show(block=False)
try:
# save data hdf5
f.create_dataset('scan'+str(i), data=data)
f.flush()
except Exception as e:
print('save error')
print(e)