Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. # Needed packages
  2. import visa
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import time
  6. import math
  7.  
  8. # Identify and open connection to oscilloscope
  9. rm = visa.ResourceManager()
  10. # Check the position of USB address using the command rm.list_resources(). Below it is at 0.
  11. keysight=rm.list_resources()[0]
  12. inst = rm.open_resource(keysight)
  13.  
  14. # Setup oscilloscope
  15. scale=50E-6
  16. timewindow=10*scale
  17. inst.write(':TIMebase:SCALe '+str(scale)) # 10xscale=time range
  18. #inst.write(':TIMebase:RANGe 0.001') # Instead of time scale, one can use time range as shown here
  19. inst.write(':TIMebase:DELay 0') # Center oscilloscope window around 0
  20. inst.write(':WAVeform:POINts:MODE RAW') # Aquires raw data - not sure if this is needed
  21.  
  22. N=20000
  23. SR=2.50e9
  24. dt=1/SR
  25. step=math.ceil(40e-9/dt)
  26.  
  27. timer=time.time()
  28. file1=open('DATA/N10000_0.00005_trace1_Htest.txt','w') #BS1
  29. file2=open('DATA/N10000_0.00005_trace2_Htest.txt','w') #BS2
  30. file3=open('DATA/N10000_0.00005_trace3_Htest.txt','w') #Trigger
  31.  
  32. for i in range(N):
  33.     inst.write(':SINGle') # Runs a single trace
  34.     inst.write(':STOP') # Stop is needed, else it will keep running after single run
  35.     inst.write(':WAVeform:SOURce CHANnel1') # Focus on channel 1
  36.     trace=inst.query_binary_values(':WAVeform:DATA?', container=np.array, datatype='B')
  37.     tmp=np.where(trace>(max(trace)+min(trace))/2)[0]
  38.     file1.write(str((tmp[1]*dt+i*timewindow)*1E6)+'\n')
  39.     for j in range(len(tmp)-1):
  40.         if tmp[j+1]>(tmp[j]+step):
  41.             file1.write(str((tmp[j+1]*dt+i*timewindow)*1E6)+'\n')
  42.  
  43.     inst.write(':WAVeform:SOURce CHANnel2') # Focus on channel 2
  44.     trace=inst.query_binary_values(':WAVeform:DATA?', container=np.array, datatype='B')
  45.     tmp=np.where(trace>(max(trace)+min(trace))/2)[0]
  46.     file2.write(str((tmp[1]*dt+i*timewindow)*1E6)+'\n')
  47.     for j in range(len(tmp)-1):
  48.         if tmp[j+1]>(tmp[j]+step):
  49.             file2.write(str((tmp[j+1]*dt+i*timewindow)*1E6)+'\n')
  50.            
  51.     inst.write(':WAVeform:SOURce CHANnel3') # Focus on channel 3
  52.     trace=inst.query_binary_values(':WAVeform:DATA?', container=np.array, datatype='B')
  53.     tmp=np.where(trace>(max(trace)+min(trace))/2)[0]
  54.     file3.write(str((tmp[1]*dt+i*timewindow)*1E6)+'\n')
  55.     for j in range(len(tmp)-1):
  56.         if tmp[j+1]>(tmp[j]+step):
  57.             file3.write(str((tmp[j+1]*dt+i*timewindow)*1E6)+'\n')
  58.    
  59.     print(str(i+1))
  60.  
  61. file1.close()
  62. file2.close()
  63. file3.close()
  64. elapse1=time.time()-timer
  65. print(str(elapse1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement