-
Notifications
You must be signed in to change notification settings - Fork 37
Description
I have got the code partially working on my DS1054Z. I can see the waveform displayed on the screen but it does not continually update, it only updates when I push the run/stop button on the scope.
Below is what I have done to get it this far on Windows 7 64bit:
I first installed the latest National Instruments VISA runtime:
http://www.ni.com/download/ni-visa-run-time-engine-15.0/5379/en/
NIVISA1500runtime.exe
Next I installed Python 2.7 making sure Python was added to the path (this is so you can run python from the command line from any directory):
https://www.python.org/downloads/release/python-2711/
python-2.7.11.amd64.msi
Next I updated pip and setuptools as well as installing wheel as recommend on:
http://python-packaging-user-guide.readthedocs.org/en/latest/installing/#install-pip-setuptools-and-wheel
python -m pip install -U pip setuptools
pip install wheel
I now updated mock as I could not get any further due to an error (on next step) saying 'Requires setuptools >=17.1 to install properly', the following fixed this issue and seemed to update a couple of other things as well:
pip install mock
Next I installed pyvisa version 1.4 as recommend (the mock update above made this work):
pip install pyvisa==1.4
Next I installed numpy, this initially did not work and showed this 'error: Unable to find vcvarsall.bat', so I installed the Microsoft Visual C++ Compiler for Python 2.7:
https://www.microsoft.com/en-gb/download/details.aspx?id=44266
VCForPython27.msi
Now numpy installed, it took a while as it needed to compile and there was no real progress update so I just left it and after a few minutes it finished and said it had installed.
pip install numpy
Next I downloaded the PyDSA code from Github:
https://github.com/rheslip/PyDSA
The file to run is in the PyDSA directory and is called PyDSA.py
Now the code needed to be altered, I used policeman0077's code to get started (see above comments) and made a few changes as this initially would not work for me:
Below is my working code so far, the changes occur in the 'Main Routine' function after line 612, run the code as follows:
python PyDSA.py
In order for it to work for me I set the trigger on the scope to AC, with the scope stopped I start the program and then after a second or two I press the run/stop button (even though it is now green and scope says triggered), now a wave form appears on the program's display. It does not automatically update but does update once if I press the run/stop button again.
============================================ Main routine ====================================================
def Sweep(): # Read samples and store the data into the arrays
global X0L # Left top X value
global Y0T # Left top Y value
global GRW # Screenwidth
global GRH # Screenheight
global SIGNAL1
global RUNstatus
global SWEEPsingle
global SMPfftlist
global SMPfftindex
global SAMPLErate
global SAMPLEsize
global SAMPLEdepth
global UPDATEspeed
global STARTfrequency
global STOPfrequency
global COLORred
global COLORcanvas
global COLORyellow
global COLORgreen
global COLORmagenta
while (True): # Main loop
# RUNstatus = 1 : Open Stream
if (RUNstatus == 1):
if UPDATEspeed < 1:
UPDATEspeed = 1.0
TRACESopened = 1
try:
Get the USB device, e.g. 'USB0::0x1AB1::0x0588::DS1ED141904883'
instruments = visa.get_instruments_list()
usb = filter(lambda x: 'USB' in x, instruments)
if len(usb) != 1:
print 'Bad instrument list', instruments
sys.exit(-1)
scope = visa.instrument(usb[0], timeout=20, chunk_size=1024000) # bigger timeout for long mem
RUNstatus = 2
except: # If error in opening audio stream, show error
RUNstatus = 0
#txt = "Sample rate: " + str(SAMPLErate) + ", try a lower sample rate.\nOr another audio device."
showerror("VISA Error","Cannot open scope")
get metadata
#sample_rate = float(scope.ask(':ACQ:SAMP?'))
#timescale = float(scope.ask(":TIM:SCAL?"))
#timeoffset = float(scope.ask(":TIM:OFFS?"))
#voltscale = float(scope.ask(':CHAN1:SCAL?'))
#voltoffset = float(scope.ask(":CHAN1:OFFS?"))
UpdateScreen() # UpdateScreen() call
# RUNstatus = 2: Reading audio data from soundcard
if (RUNstatus == 2):
# Grab the raw data from channel 1
#try:
Set the scope the way we want it
if SAMPLEdepth == 0:
scope.write(':ACQ:MDEP 12000') # normal memory type
else:
scope.write(':ACQ:MDEP 120000') # long memory type
#scope.write(':CHAN1:COUP DC') # DC coupling
#scope.write(':CHAN1:DISP ON') # Channel 1 on
#scope.write(':CHAN2:DISP ON') # Channel 2 off
#scope.write(':CHAN1:SCAL 1') # Channel 1 vertical scale 1 volts
#scope.write(':CHAN1:OFFS -2') # Channel 1 vertical offset 2 volts
#scope.write(':TIM:SCAL 0.001') # time interval
#scope.write(':TIM:OFFS .05') # Offset time 50 ms
#scope.write(':TRIG:EDGE:SOUR CHAN1') # Edge-trigger from channel 1
#scope.write(':TRIG:EDGE:SWE SING') # Single trigger
#scope.write(':TRIG:EDGE:COUP AC') # trigger coupling
#scope.write(':TRIG:EDGE:SLOP NEG') # Trigger on negative edge
#scope.write(':TRIG:EDGE:LEV 0.01') # Trigger volts
scope.write(":RUN")
#txt = "Trig"
#x = X0L + 250
#y = Y0T+GRH+32
#IDtxt = ca.create_text (x, y, text=txt, anchor=W, fill=COLORyellow)
#root.update() # update screen
while scope.ask(':TRIG:STAT?') != 'STOP':
sleep(0.1)
#sleep(0.1)
# Grab the raw data from channel 1, which will take a few seconds for long buffer mode
scope.write(":STOP")
scope.write(":WAV:SOUR CHAN1")
scope.write(":WAV:MODE RAW")
scope.write(":WAV:FORM BYTE")
scope.write(":WAV:STAR 1")
if SAMPLEdepth == 0:
scope.write(":WAV:STOP 12000")
else:
scope.write(":WAV:STOP 120000")
txt = "->Acquire"
x = X0L + 275
y = Y0T+GRH+32
IDtxt = ca.create_text (x, y, text=txt, anchor=W, fill=COLORgreen)
root.update() # update screen
signals= scope.ask(":WAV:DATA?") #do this first
data_size = len(signals)
SAMPLErate = scope.ask_for_values(':ACQ:SRAT?')[0] #do this second
#print 'Data size:', SAMPLEsize, "Sample rate:", SAMPLErate
sleep(0.1)
convert data from (inverted) bytes to an array of scaled floats
this magic from Matthew Mets
SIGNAL1 = numpy.frombuffer(signals, 'B')
#print SIGNAL1
SIGNAL1 = (SIGNAL1 * -1 + 255) -130 # invert
#print SIGNAL1
SIGNAL1 = SIGNAL1/127.0 # scale 10 +-1, has a slight DC offset
#print SIGNAL1
UpdateAll() # Update Data, trace and screen
if SWEEPsingle == True: # single sweep mode, sweep once then stop
SWEEPsingle = False
RUNstatus = 3
# RUNstatus = 3: Stop
# RUNstatus = 4: Stop and restart
if (RUNstatus == 3) or (RUNstatus == 4):
scope.write(":KEY:FOR")
scope.close()
if RUNstatus == 3:
RUNstatus = 0 # Status is stopped
if RUNstatus == 4:
RUNstatus = 1 # Status is (re)start
UpdateScreen() # UpdateScreen() call
# Update tasks and screens by TKinter
root.update_idletasks()
root.update() # update screens