|
@@ -1,14 +1,22 @@
|
1
|
1
|
#!/usr/bin/env python
|
2
|
2
|
__author__ = 'RoGeorge'
|
3
|
3
|
#
|
|
4
|
+"""
|
|
5
|
+# TODO: Use "waveform:data?" multiple times to extract the whole 12M points
|
|
6
|
+ in order to overcome the "Memory lack in waveform reading!" screen message
|
|
7
|
+"""
|
|
8
|
+# TODO: Detect if the osc is in RUN or in STOP mode (looking at the length of data extracted)
|
|
9
|
+# TODO: Investigate scaling. Sometimes 3.0e-008 instead of expected 3.0e-000
|
4
|
10
|
# TODO: Add timestamp and mark the trigger point as t0
|
5
|
11
|
# TODO: Use channels label instead of chan1, chan2, chan3, chan4, math
|
6
|
12
|
# TODO: Add command line parameters file path
|
|
13
|
+# TODO: Speed-up the transfer, try to replace Telnet with direct TCP
|
7
|
14
|
# TODO: Add GUI
|
8
|
15
|
# TODO: Add browse and custom filename selection
|
9
|
16
|
# TODO: Create executable distributions
|
10
|
17
|
#
|
11
|
|
-import telnetlib_receive_all
|
|
18
|
+from telnetlib_receive_all import Telnet
|
|
19
|
+from Rigol_functions import *
|
12
|
20
|
import time
|
13
|
21
|
import Image
|
14
|
22
|
import StringIO
|
|
@@ -95,7 +103,7 @@ if response != 0:
|
95
|
103
|
# Open a modified telnet session
|
96
|
104
|
# The default telnetlib drops 0x00 characters,
|
97
|
105
|
# so a modified library 'telnetlib_receive_all' is used instead
|
98
|
|
-tn = telnetlib_receive_all.Telnet(IP_DS1104Z, port)
|
|
106
|
+tn = Telnet(IP_DS1104Z, port)
|
99
|
107
|
tn.write("*idn?") # ask for instrument ID
|
100
|
108
|
instrument_id = tn.read_until("\n", 1)
|
101
|
109
|
|
|
@@ -161,42 +169,76 @@ elif file_format == "csv":
|
161
|
169
|
print "Active channels on the display:", channel_list
|
162
|
170
|
|
163
|
171
|
csv_buff = ""
|
|
172
|
+ depth = get_memory_depth(tn)
|
164
|
173
|
|
165
|
174
|
# for each active channel
|
166
|
175
|
for channel in channel_list:
|
167
|
|
- # Read WAVE parameters
|
|
176
|
+ print
|
168
|
177
|
|
169
|
178
|
# Set WAVE parameters
|
170
|
179
|
tn.write("waveform:source " + channel)
|
171
|
180
|
time.sleep(0.2)
|
172
|
181
|
|
173
|
|
- # Maximum - only displayed data when osc. in RUN mode, or full memory data when STOPed
|
174
|
|
- tn.write("waveform:mode normal")
|
|
182
|
+ tn.write("waveform:form asc")
|
175
|
183
|
time.sleep(0.2)
|
176
|
184
|
|
177
|
|
- tn.write("waveform:format ASCII")
|
|
185
|
+ # Maximum - only displayed data when osc. in RUN mode, or full memory data when STOPed
|
|
186
|
+ tn.write("waveform:mode max")
|
178
|
187
|
time.sleep(0.2)
|
179
|
188
|
|
180
|
|
- # Get data
|
181
|
|
- tn.write("waveform:data?")
|
|
189
|
+ # Get all possible data
|
|
190
|
+ buff = ""
|
|
191
|
+ data_available = True
|
|
192
|
+
|
|
193
|
+ # max_chunk is dependent of the wav:mode and the oscilloscope type
|
|
194
|
+ # if you get on the oscilloscope screen the error message
|
|
195
|
+ # "Memory lack in waveform reading!", then decrease max_chunk value
|
|
196
|
+ max_chunk = 100000.0 # tested for DS1104Z
|
|
197
|
+ if max_chunk > depth:
|
|
198
|
+ max_chunk = depth
|
|
199
|
+
|
|
200
|
+ n1 = 1.0
|
|
201
|
+ n2 = max_chunk
|
|
202
|
+ data_available = True
|
|
203
|
+
|
|
204
|
+ while data_available:
|
|
205
|
+ display_n1 = n1
|
|
206
|
+ stop_point = is_waveform_from_to(tn, n1, n2)
|
|
207
|
+ if stop_point == 0:
|
|
208
|
+ data_available = False
|
|
209
|
+ print "ERROR: Stop data point index lower then start data point index"
|
|
210
|
+ sys.exit("ERROR")
|
|
211
|
+ elif stop_point < n1:
|
|
212
|
+ break
|
|
213
|
+ elif stop_point < n2:
|
|
214
|
+ n2 = stop_point
|
|
215
|
+ is_waveform_from_to(tn, n1, n2)
|
|
216
|
+ data_available = False
|
|
217
|
+ else:
|
|
218
|
+ data_available = True
|
|
219
|
+ n1 = n2 + 1
|
|
220
|
+ n2 += max_chunk
|
182
|
221
|
|
183
|
|
- print "Receiving data for channel " + str(channel) + "..."
|
184
|
|
- buff = tn.read_until("\n", big_wait)
|
|
222
|
+ tn.write("waveform:data?")
|
185
|
223
|
|
186
|
|
- # Just in case the transfer did not complete in the expected time
|
187
|
|
- while buff[-1] != "\n":
|
188
|
|
- tmp = tn.read_until("\n", small_wait)
|
189
|
|
- if len(tmp) == 0:
|
190
|
|
- break
|
191
|
|
- buff += tmp
|
|
224
|
+ print "Data from channel " + str(channel) + ", points " +\
|
|
225
|
+ str(int(display_n1)) + "-" + str(int(stop_point)) + ": Receiving..."
|
|
226
|
+ buff_chunks = tn.read_until("\n", big_wait)
|
192
|
227
|
|
193
|
|
- # Append each value to csv_buff
|
|
228
|
+ # Just in case the transfer did not complete in the expected time
|
|
229
|
+ while buff_chunks[-1] != "\n":
|
|
230
|
+ tmp = tn.read_until("\n", small_wait)
|
|
231
|
+ if len(tmp) == 0:
|
|
232
|
+ break
|
|
233
|
+ buff_chunks += tmp
|
|
234
|
+
|
|
235
|
+ # Append data chunks
|
|
236
|
+ # Strip TMC Blockheader and terminator bytes
|
|
237
|
+ buff += buff_chunks[TMC_header_len:-1] + ","
|
194
|
238
|
|
195
|
|
- # Strip headers (TMC and points number)
|
196
|
|
- TMC_header = buff[:TMC_header_len]
|
197
|
|
- data_points = float(TMC_header[2:])
|
198
|
|
- # Strip TMC Blockheader and terminator bytes
|
199
|
|
- buff = buff[TMC_header_len:-1]
|
|
239
|
+ buff = buff[:-1]
|
|
240
|
+
|
|
241
|
+ # Append each value to csv_buff
|
200
|
242
|
|
201
|
243
|
# Process data
|
202
|
244
|
|