@@ -380,45 +380,60 @@ def get(self):
380380 meas_time = segs * (params ['scope_duration' ].get ()+ deadtime )+ 1
381381 npts = params ['scope_length' ].get ()
382382
383- # Create a new scopeModule instance (TODO: Why a new instance?)
384- scope = self ._instrument .daq .scopeModule ()
385-
386- # Subscribe to the relevant... publisher?
387- scope .subscribe ('/{}/scopes/0/wave' .format (self ._instrument .device ))
388-
389- # Start the scope triggering/acquiring
390- params ['scope_runstop' ].set ('run' )
391-
392- log .info ('[*] Starting ZI scope acquisition.' )
393- # Start something... hauling data from the scopeModule?
394- scope .execute ()
395-
396- starttime = time .time ()
383+ zi_error = True
384+ error_counter = 0
385+ num_retries = 10
397386 timedout = False
398-
399- while scope .progress () < 1 :
400- time .sleep (0.1 ) # This while+sleep is how ZI engineers do it
401- if (time .time ()- starttime ) > meas_time :
402- scope .finish () # Force break the acquisition
403- timedout = True
404- log .warning ('[-] ZI Scope acquisition did not finish correctly' )
405- break
406-
407- # Stop the scope from running
408- params ['scope_runstop' ].set ('stop' )
409-
410- if not timedout :
411- log .info ('[+] ZI scope acquisition completed OK' )
412- rawdata = scope .read ()
413- data = self ._scopedataparser (rawdata , self ._instrument .device ,
414- npts , segs , channels )
415- else :
416- rawdata = None
417- data = (None , None )
418-
419- # kill the scope instance
420- scope .clear ()
421-
387+ while (zi_error or timedout ) and error_counter < num_retries :
388+ # one shot per trigger. This needs to be set every time
389+ # a the scope is enabled as below using scope_runstop
390+ self ._instrument .daq .setInt ('/{}/scopes/0/single' .format (self ._instrument .device ), 1 )
391+ self ._instrument .daq .sync ()
392+
393+ scope = self ._instrument .scope # There are issues reusing the scope.
394+
395+ # Subscribe to the relevant... publisher?
396+ scope .subscribe ('/{}/scopes/0/wave' .format (self ._instrument .device ))
397+
398+ # Start the scope triggering/acquiring
399+ params ['scope_runstop' ].set ('run' ) # set /dev/scopes/0/enable to 1
400+
401+ log .info ('[*] Starting ZI scope acquisition.' )
402+ # Start something... hauling data from the scopeModule?
403+ scope .execute ()
404+ starttime = time .time ()
405+ timedout = False
406+
407+ while scope .progress () < 1 :
408+ time .sleep (0.1 ) # This while+sleep is how ZI engineers do it
409+ if (time .time ()- starttime ) > 2 * meas_time :
410+ timedout = True
411+ break
412+ metadata = scope .get ("scopeModule/*" )
413+ zi_error = bool (metadata ['error' ][0 ])
414+
415+ # Stop the scope from running
416+ params ['scope_runstop' ].set ('stop' )
417+
418+ if not (timedout or zi_error ):
419+ log .info ('[+] ZI scope acquisition completed OK' )
420+ rawdata = scope .read ()
421+ data = self ._scopedataparser (rawdata , self ._instrument .device ,
422+ npts , segs , channels )
423+ else :
424+ log .warning ('[-] ZI scope acquisition attempt {} '
425+ 'failed, Timeout: {}, Error: {}, '
426+ 'retrying' .format (error_counter , timedout , zi_error ))
427+ rawdata = None
428+ data = (None , None )
429+ error_counter += 1
430+
431+ # cleanup and make ready for next scope acquisition
432+ scope .finish ()
433+ scope .unsubscribe ('/{}/scopes/0/wave' .format (self ._instrument .device ))
434+ if error_counter >= num_retries :
435+ log .warning ('[+] ZI scope acquisition failed, maximum number'
436+ 'of retries performed. No data returned' )
422437 return data
423438
424439 @staticmethod
@@ -1071,7 +1086,7 @@ def __init__(self, name, device_ID, **kwargs):
10711086 vals = vals .Enum (1 , 2 , 3 )
10721087 )
10731088
1074- self ._samplingrate_codes = {'1.80 Ghz ' : 0 ,
1089+ self ._samplingrate_codes = {'1.80 GHz ' : 0 ,
10751090 '900 MHz' : 1 ,
10761091 '450 MHz' : 2 ,
10771092 '225 MHz' : 3 ,
@@ -1926,5 +1941,7 @@ def close(self):
19261941 """
19271942 Override of the base class' close function
19281943 """
1944+ self .scope .clear ()
1945+ self .sweeper .clear ()
19291946 self .daq .disconnect ()
19301947 super ().close ()
0 commit comments