{"action":"created","issue":{"url":"https://api.github.com/repos/rheslip/PyDSA/issues/1","labels_url":"https://api.github.com/repos/rheslip/PyDSA/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/rheslip/PyDSA/issues/1/comments","events_url":"https://api.github.com/repos/rheslip/PyDSA/issues/1/events","html_url":"https://github.com/rheslip/PyDSA/issues/1","id":130127926,"number":1,"title":"Getting code working for DS1054Z on Windows 7 64bit","user":{"login":"kerrsmith","id":12290040,"avatar_url":"https://avatars.githubusercontent.com/u/12290040?v=3","gravatar_id":"","url":"https://api.github.com/users/kerrsmith","html_url":"https://github.com/kerrsmith","followers_url":"https://api.github.com/users/kerrsmith/followers","following_url":"https://api.github.com/users/kerrsmith/following{/other_user}","gists_url":"https://api.github.com/users/kerrsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/kerrsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerrsmith/subscriptions","organizations_url":"https://api.github.com/users/kerrsmith/orgs","repos_url":"https://api.github.com/users/kerrsmith/repos","events_url":"https://api.github.com/users/kerrsmith/events{/privacy}","received_events_url":"https://api.github.com/users/kerrsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-31T13:34:56Z","updated_at":"2016-01-31T17:55:36Z","closed_at":null,"body":"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.\r\n\r\nBelow is what I have done to get it this far on Windows 7 64bit:\r\n\r\nI first installed the latest National Instruments VISA runtime:\r\n\r\nhttp://www.ni.com/download/ni-visa-run-time-engine-15.0/5379/en/\r\nNIVISA1500runtime.exe\r\n\r\nNext 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):\r\n\r\nhttps://www.python.org/downloads/release/python-2711/\r\npython-2.7.11.amd64.msi\r\n\r\nNext I updated pip and setuptools as well as installing wheel as recommend on:\r\nhttp://python-packaging-user-guide.readthedocs.org/en/latest/installing/#install-pip-setuptools-and-wheel\r\npython -m pip install -U pip setuptools\r\npip install wheel\r\n\r\nI 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:\r\n\r\npip install mock\r\n\r\nNext I installed pyvisa version 1.4 as recommend (the mock update above made this work):\r\n\r\npip install pyvisa==1.4\r\n\r\nNext 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:\r\n\r\nhttps://www.microsoft.com/en-gb/download/details.aspx?id=44266\r\nVCForPython27.msi\r\n\r\nNow 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.\r\n\r\npip install numpy\r\n\r\nNext I downloaded the PyDSA code from Github:\r\n\r\nhttps://github.com/rheslip/PyDSA\r\n\r\nThe file to run is in the PyDSA directory and is called PyDSA.py\r\n\r\nNow 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:\r\n\r\nBelow is my working code so far, the changes occur in the 'Main Routine' function after line 612, run the code as follows:\r\n\r\npython PyDSA.py\r\n\r\nIn 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.\r\n\r\n# ============================================ Main routine ====================================================\r\n\r\ndef Sweep():   # Read samples and store the data into the arrays\r\n    global X0L          # Left top X value\r\n    global Y0T          # Left top Y value\r\n    global GRW          # Screenwidth\r\n    global GRH          # Screenheight\r\n    global SIGNAL1\r\n    global RUNstatus\r\n    global SWEEPsingle\r\n    global SMPfftlist\r\n    global SMPfftindex\r\n    global SAMPLErate\r\n    global SAMPLEsize\r\n    global SAMPLEdepth\r\n    global UPDATEspeed\r\n    global STARTfrequency\r\n    global STOPfrequency\r\n    global COLORred\r\n    global COLORcanvas\r\n    global COLORyellow\r\n    global COLORgreen\r\n    global COLORmagenta\r\n\r\n    while (True):                                           # Main loop\r\n\r\n\r\n        # RUNstatus = 1 : Open Stream\r\n        if (RUNstatus == 1):\r\n            if UPDATEspeed < 1:\r\n                UPDATEspeed = 1.0\r\n\r\n            TRACESopened = 1\r\n\r\n            try:\r\n# Get the USB device, e.g. 'USB0::0x1AB1::0x0588::DS1ED141904883'\r\n                instruments = visa.get_instruments_list()\r\n                usb = filter(lambda x: 'USB' in x, instruments)\r\n                if len(usb) != 1:\r\n                    print 'Bad instrument list', instruments\r\n                    sys.exit(-1)\r\n                scope = visa.instrument(usb[0], timeout=20, chunk_size=1024000) # bigger timeout for long mem\r\n\r\n                RUNstatus = 2\r\n            except:                                         # If error in opening audio stream, show error\r\n                RUNstatus = 0\r\n                #txt = \"Sample rate: \" + str(SAMPLErate) + \", try a lower sample rate.\\nOr another audio device.\"\r\n                showerror(\"VISA Error\",\"Cannot open scope\")\r\n\r\n# get metadata\r\n            #sample_rate = float(scope.ask(':ACQ:SAMP?'))\r\n            #timescale = float(scope.ask(\":TIM:SCAL?\"))\r\n            #timeoffset = float(scope.ask(\":TIM:OFFS?\"))\r\n            #voltscale = float(scope.ask(':CHAN1:SCAL?'))\r\n            #voltoffset = float(scope.ask(\":CHAN1:OFFS?\"))\r\n\r\n            UpdateScreen()                                  # UpdateScreen() call\r\n\r\n\r\n        # RUNstatus = 2: Reading audio data from soundcard\r\n        if (RUNstatus == 2):\r\n        # Grab the raw data from channel 1\r\n            #try:\r\n# Set the scope the way we want it\r\n            if SAMPLEdepth == 0:\r\n                scope.write(':ACQ:MDEP 12000') # normal memory type\r\n            else:\r\n                scope.write(':ACQ:MDEP 120000') # long memory type\r\n            #scope.write(':CHAN1:COUP DC') # DC coupling\r\n            #scope.write(':CHAN1:DISP ON') # Channel 1 on\r\n            #scope.write(':CHAN2:DISP ON') # Channel 2 off\r\n            #scope.write(':CHAN1:SCAL 1') # Channel 1 vertical scale 1 volts\r\n            #scope.write(':CHAN1:OFFS -2') # Channel 1 vertical offset 2 volts\r\n            #scope.write(':TIM:SCAL 0.001') # time interval\r\n            #scope.write(':TIM:OFFS .05') # Offset time 50 ms\r\n\r\n            #scope.write(':TRIG:EDGE:SOUR CHAN1') # Edge-trigger from channel 1\r\n            #scope.write(':TRIG:EDGE:SWE SING') # Single trigger\r\n            #scope.write(':TRIG:EDGE:COUP AC') # trigger coupling\r\n            #scope.write(':TRIG:EDGE:SLOP NEG') # Trigger on negative edge\r\n            #scope.write(':TRIG:EDGE:LEV 0.01') # Trigger  volts\r\n            scope.write(\":RUN\")\r\n\r\n            #txt = \"Trig\"\r\n            #x = X0L + 250\r\n            #y = Y0T+GRH+32\r\n            #IDtxt  = ca.create_text (x, y, text=txt, anchor=W, fill=COLORyellow)\r\n            #root.update()       # update screen\r\n\r\n            while scope.ask(':TRIG:STAT?') != 'STOP':\r\n                sleep(0.1)\r\n            #sleep(0.1)\r\n    # Grab the raw data from channel 1, which will take a few seconds for long buffer mode\r\n\r\n            scope.write(\":STOP\")\r\n            scope.write(\":WAV:SOUR CHAN1\")\r\n            scope.write(\":WAV:MODE RAW\")\r\n            scope.write(\":WAV:FORM BYTE\")\r\n            scope.write(\":WAV:STAR 1\")\r\n            if SAMPLEdepth == 0:\r\n                scope.write(\":WAV:STOP 12000\")\r\n            else:\r\n                scope.write(\":WAV:STOP 120000\")\r\n\r\n            txt = \"->Acquire\"\r\n            x = X0L + 275\r\n            y = Y0T+GRH+32\r\n            IDtxt  = ca.create_text (x, y, text=txt, anchor=W, fill=COLORgreen)\r\n            root.update()       # update screen\r\n\r\n\r\n            signals= scope.ask(\":WAV:DATA?\")  #do this first\r\n            data_size = len(signals)\r\n\r\n            SAMPLErate = scope.ask_for_values(':ACQ:SRAT?')[0] #do this second\r\n            #print 'Data size:', SAMPLEsize, \"Sample rate:\", SAMPLErate\r\n\r\n\r\n\r\n            sleep(0.1)\r\n\r\n# convert data from (inverted) bytes to an array of scaled floats\r\n# this magic from Matthew Mets\r\n            SIGNAL1 = numpy.frombuffer(signals, 'B')\r\n            #print SIGNAL1\r\n            SIGNAL1 = (SIGNAL1 * -1 + 255) -130  # invert\r\n            #print SIGNAL1\r\n            SIGNAL1 = SIGNAL1/127.0 # scale 10 +-1, has a slight DC offset\r\n            #print SIGNAL1\r\n\r\n            UpdateAll()                                     # Update Data, trace and screen\r\n\r\n            if SWEEPsingle == True:  # single sweep mode, sweep once then stop\r\n                SWEEPsingle = False\r\n                RUNstatus = 3\r\n\r\n        # RUNstatus = 3: Stop\r\n        # RUNstatus = 4: Stop and restart\r\n        if (RUNstatus == 3) or (RUNstatus == 4):\r\n            scope.write(\":KEY:FOR\")\r\n            scope.close()\r\n            if RUNstatus == 3:\r\n                RUNstatus = 0                               # Status is stopped\r\n            if RUNstatus == 4:\r\n                RUNstatus = 1                               # Status is (re)start\r\n            UpdateScreen()                                  # UpdateScreen() call\r\n\r\n\r\n        # Update tasks and screens by TKinter\r\n        root.update_idletasks()\r\n        root.update()                                       # update screens"},"comment":{"url":"https://api.github.com/repos/rheslip/PyDSA/issues/comments/177564083","html_url":"https://github.com/rheslip/PyDSA/issues/1#issuecomment-177564083","issue_url":"https://api.github.com/repos/rheslip/PyDSA/issues/1","id":177564083,"user":{"login":"kerrsmith","id":12290040,"avatar_url":"https://avatars.githubusercontent.com/u/12290040?v=3","gravatar_id":"","url":"https://api.github.com/users/kerrsmith","html_url":"https://github.com/kerrsmith","followers_url":"https://api.github.com/users/kerrsmith/followers","following_url":"https://api.github.com/users/kerrsmith/following{/other_user}","gists_url":"https://api.github.com/users/kerrsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/kerrsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerrsmith/subscriptions","organizations_url":"https://api.github.com/users/kerrsmith/orgs","repos_url":"https://api.github.com/users/kerrsmith/repos","events_url":"https://api.github.com/users/kerrsmith/events{/privacy}","received_events_url":"https://api.github.com/users/kerrsmith/received_events","type":"User","site_admin":false},"created_at":"2016-01-31T17:55:36Z","updated_at":"2016-01-31T17:55:36Z","body":"That's great, thanks.\n\nI am not sure why I am not able to post properly.\n\nI will have a look at the code and see if I can figure anything out - I\nwill keep you updated.\n\nThanks again,\n\nKerr\n\nOn 31 January 2016 at 17:52, rheslip <notifications@github.com> wrote:\n\n> Kerr - I posted your code on the blog. Once you get it sweeping could you\n> send me a zip of it ? I can put in in github as a 1054Z version which will\n> make it a lot easier for other people to use it. Just send it to me\n> directly rheslip@hotmail.com\n> Thanks, Rich\n>\n> Date: Sun, 31 Jan 2016 08:35:51 -0800\n> From: notifications@github.com\n> To: PyDSA@noreply.github.com\n> CC: rheslip@hotmail.com\n> Subject: Re: [PyDSA] Getting code working for DS1054Z on Windows 7 64bit\n> (#1)\n>\n> Hi,\n>\n>\n>\n> Thank you very much for getting back to me, it is much appreciated.\n>\n>\n>\n> I don't suppose you could also post the code under the post you just added\n>\n> for me on your blog - it is a slight modification of the code by\n>\n> policeman0077 (further up the page) as that version had a few missing\n>\n> commands where it does the actual data retrieval from the scope\n>\n> (specifically the 'Grab the raw data from channel 1' part).\n>\n>\n>\n> I did try to get the code looking neat on Github but it kept insisting on\n>\n> formatting it and highlighting all the comments - after a while fiddling\n>\n> with it I decided to just leave it as it was, copied straight out my\n>\n> working code. The main parts are quite clear even if the comments are a\n>\n> bit on the large side.\n>\n>\n>\n> I will try adjusting the timing as suggested and let you know how it goes -\n>\n> it is very close to working I think. I have not used Python before\n>\n> yesterday but it is not so different from C++ and PHP which I am used to\n>\n> working with. It is also my first time trying to talk to my scope from my\n>\n> computer...\n>\n>\n>\n> Anyway, as mentioned above, if you could add the code just after my post I\n>\n> think it would help others get to the same point as me - which is almost\n>\n> working I think. I will paste the code below this email so you have an\n>\n> easy to copy version:\n>\n>\n>\n> Thanks again for your suggestions and I will let you know how I get on,\n>\n>\n>\n> Kerr\n>\n>\n>\n> # ============================================ Main routine\n>\n> ====================================================\n>\n>\n>\n> def Sweep(): # Read samples and store the data into the arrays\n>\n> global X0L # Left top X value\n>\n> global Y0T # Left top Y value\n>\n> global GRW # Screenwidth\n>\n> global GRH # Screenheight\n>\n> global SIGNAL1\n>\n> global RUNstatus\n>\n> global SWEEPsingle\n>\n> global SMPfftlist\n>\n> global SMPfftindex\n>\n> global SAMPLErate\n>\n> global SAMPLEsize\n>\n> global SAMPLEdepth\n>\n> global UPDATEspeed\n>\n> global STARTfrequency\n>\n> global STOPfrequency\n>\n> global COLORred\n>\n> global COLORcanvas\n>\n> global COLORyellow\n>\n> global COLORgreen\n>\n> global COLORmagenta\n>\n>\n>\n> while (True): # Main loop\n>\n>\n>\n>\n>\n> # RUNstatus = 1 : Open Stream\n>\n> if (RUNstatus == 1):\n>\n> if UPDATEspeed < 1:\n>\n> UPDATEspeed = 1.0\n>\n>\n>\n> TRACESopened = 1\n>\n>\n>\n> try:\n>\n> # Get the USB device, e.g. 'USB0::0x1AB1::0x0588::DS1ED141904883'\n>\n> instruments = visa.get_instruments_list()\n>\n> usb = filter(lambda x: 'USB' in x, instruments)\n>\n> if len(usb) != 1:\n>\n> print 'Bad instrument list', instruments\n>\n> sys.exit(-1)\n>\n> scope = visa.instrument(usb[0], timeout=20,\n>\n> chunk_size=1024000) # bigger timeout for long mem\n>\n>\n>\n> RUNstatus = 2\n>\n> except: # If error in\n>\n> opening audio stream, show error\n>\n> RUNstatus = 0\n>\n> #txt = \"Sample rate: \" + str(SAMPLErate) + \", try a lower\n>\n> sample rate.\\nOr another audio device.\"\n>\n> showerror(\"VISA Error\",\"Cannot open scope\")\n>\n>\n>\n> # get metadata\n>\n> #sample_rate = float(scope.ask(':ACQ:SAMP?'))\n>\n> #timescale = float(scope.ask(\":TIM:SCAL?\"))\n>\n> #timeoffset = float(scope.ask(\":TIM:OFFS?\"))\n>\n> #voltscale = float(scope.ask(':CHAN1:SCAL?'))\n>\n> #voltoffset = float(scope.ask(\":CHAN1:OFFS?\"))\n>\n>\n>\n> UpdateScreen() #\n>\n> UpdateScreen() call\n>\n>\n>\n>\n>\n> # RUNstatus = 2: Reading audio data from soundcard\n>\n> if (RUNstatus == 2):\n>\n> # Grab the raw data from channel 1\n>\n> #try:\n>\n> # Set the scope the way we want it\n>\n> if SAMPLEdepth == 0:\n>\n> scope.write(':ACQ:MDEP 12000') # normal memory type\n>\n> else:\n>\n> scope.write(':ACQ:MDEP 120000') # long memory type\n>\n> #scope.write(':CHAN1:COUP DC') # DC coupling\n>\n> #scope.write(':CHAN1:DISP ON') # Channel 1 on\n>\n> #scope.write(':CHAN2:DISP ON') # Channel 2 off\n>\n> #scope.write(':CHAN1:SCAL 1') # Channel 1 vertical scale 1 volts\n>\n> #scope.write(':CHAN1:OFFS -2') # Channel 1 vertical offset 2\n>\n> volts\n>\n> #scope.write(':TIM:SCAL 0.001') # time interval\n>\n> #scope.write(':TIM:OFFS .05') # Offset time 50 ms\n>\n>\n>\n> #scope.write(':TRIG:EDGE:SOUR CHAN1') # Edge-trigger from\n>\n> channel 1\n>\n> #scope.write(':TRIG:EDGE:SWE SING') # Single trigger\n>\n> #scope.write(':TRIG:EDGE:COUP AC') # trigger coupling\n>\n> #scope.write(':TRIG:EDGE:SLOP NEG') # Trigger on negative edge\n>\n> #scope.write(':TRIG:EDGE:LEV 0.01') # Trigger volts\n>\n> scope.write(\":RUN\")\n>\n>\n>\n> #txt = \"Trig\"\n>\n> #x = X0L + 250\n>\n> #y = Y0T+GRH+32\n>\n> #IDtxt = ca.create_text (x, y, text=txt, anchor=W,\n>\n> fill=COLORyellow)\n>\n> #root.update() # update screen\n>\n>\n>\n> while scope.ask(':TRIG:STAT?') != 'STOP':\n>\n> sleep(0.1)\n>\n> #sleep(0.1)\n>\n> # Grab the raw data from channel 1, which will take a few seconds for\n>\n> long buffer mode\n>\n>\n>\n> scope.write(\":STOP\")\n>\n> scope.write(\":WAV:SOUR CHAN1\")\n>\n> scope.write(\":WAV:MODE RAW\")\n>\n> scope.write(\":WAV:FORM BYTE\")\n>\n> scope.write(\":WAV:STAR 1\")\n>\n> if SAMPLEdepth == 0:\n>\n> scope.write(\":WAV:STOP 12000\")\n>\n> else:\n>\n> scope.write(\":WAV:STOP 120000\")\n>\n>\n>\n> txt = \"->Acquire\"\n>\n> x = X0L + 275\n>\n> y = Y0T+GRH+32\n>\n> IDtxt = ca.create_text (x, y, text=txt, anchor=W,\n>\n> fill=COLORgreen)\n>\n> root.update() # update screen\n>\n>\n>\n>\n>\n> signals= scope.ask(\":WAV:DATA?\") #do this first\n>\n> data_size = len(signals)\n>\n>\n>\n> SAMPLErate = scope.ask_for_values(':ACQ:SRAT?')[0] #do this\n>\n> second\n>\n> #print 'Data size:', SAMPLEsize, \"Sample rate:\", SAMPLErate\n>\n>\n>\n>\n>\n>\n>\n> sleep(0.1)\n>\n>\n>\n> # convert data from (inverted) bytes to an array of scaled floats\n>\n> # this magic from Matthew Mets\n>\n> SIGNAL1 = numpy.frombuffer(signals, 'B')\n>\n> #print SIGNAL1\n>\n> SIGNAL1 = (SIGNAL1 * -1 + 255) -130 # invert\n>\n> #print SIGNAL1\n>\n> SIGNAL1 = SIGNAL1/127.0 # scale 10 +-1, has a slight DC offset\n>\n> #print SIGNAL1\n>\n>\n>\n> UpdateAll() # Update Data,\n>\n> trace and screen\n>\n>\n>\n> if SWEEPsingle == True: # single sweep mode, sweep once then\n>\n> stop\n>\n> SWEEPsingle = False\n>\n> RUNstatus = 3\n>\n>\n>\n> # RUNstatus = 3: Stop\n>\n> # RUNstatus = 4: Stop and restart\n>\n> if (RUNstatus == 3) or (RUNstatus == 4):\n>\n> scope.write(\":KEY:FOR\")\n>\n> scope.close()\n>\n> if RUNstatus == 3:\n>\n> RUNstatus = 0 # Status is\n>\n> stopped\n>\n> if RUNstatus == 4:\n>\n> RUNstatus = 1 # Status is\n>\n> (re)start\n>\n> UpdateScreen() #\n>\n> UpdateScreen() call\n>\n>\n>\n>\n>\n> # Update tasks and screens by TKinter\n>\n> root.update_idletasks()\n>\n> root.update() # update screens\n>\n>\n>\n> —\n> Reply to this email directly or view it on GitHub.\n>\n>\n>\n>\n>\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/rheslip/PyDSA/issues/1#issuecomment-177563896>.\n>\n"}}