spri

Members
  • Content Count

    33
  • Joined

  • Last visited

Everything posted by spri

  1. After spending more time digging around on this, I discovered that this is an issue with residual files in the pycache after a python version update, and has nothing to do with the WaveForms SDK. If anyone else encounters this error, clear the cache and see this post for more details: https://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error>
  2. I just updated Python from version 2.7.10.3 to 3.7.3 (a big jump, I know... but it was time). Now, when I try to run an application I created using the WaveForms SDK, I get the error, from dwfconstants import * ImportError: bad magic number in 'dwfconstants': b'\x03\xf3\r\n' I just updated WaveForms, and the error persists. What does it mean? How do I fix it?
  3. Thank you, that worked perfectly! But, I'm a little confused still as to why my solution didn't work. When using -1 to configure the master run time, does that override individual channel settings on the wait time?
  4. Thanks for that pointer, but I had already tried that - when I replace the AnalogOutWaitSet with these two lines of code, both channels trigger at the same time using whatever delay period is specified for channel 0. Is there some additional argument (node?) which is required to make this work when using the SDK and not the Waveforms software?
  5. I am trying to create two square wave signals on the AD2 Analog instrument. Both signals should start at 5v, one should drop to 0v at the trigger, and the other should go to 0v after a certain delay time after the trigger (delay time = self.d/1000). Both signals should return to 5v at the same time (end of RunSet). I think I have to do this using the 'funcCustom' output, at least for the delayed signal. However, I am not able to get the funcCustom signal to give me the desired output. It just outputs 5v constantly after the trigger signal. (The funcSquare signal does what is expected). Is there an easier way to create this delay between two analog channels without using funcCustom? Or is there something wrong in my syntax for getting the funcCustom signal to work? Thank you!
  6. Thanks @attila. I did not think to use funcSquare to create a DC offset for a specified duration.
  7. I am trying to do something similar, with an idle offset value and then switch to a different DC offset value after a trigger. However, with the code below, I am getting the FuncDC/NodeOffset value immediately when I configure the channel, instead of the idle value prior to the trigger. It only goes to the idle value after the RunSet duration. Could you please explain how to get it to idle at a low value prior to the trigger?
  8. For the analog discovery 2 SDK, when using the AnalogOutWaitSet command, is there a function which will tell me how long until the trigger/device start? I am looking for something similar to AnalogOutRunStatus, but which will tell me the remaining wait time. Thank you.
  9. Thanks, this helps a lot with the pulsed outputs. Is it possible to also do this with the Constant output-type also? For example, in the setup below I want DIO-2 to switch from idle to constant at t=30ms (20ms delay after the 10ms wait-set), but there are obviously not options for the counter-init and divider-init for this output type. I am ultimately interested in doing this within the python sdk, not in waveforms (but waveforms is a good place to start to visualize what I'm doing). In the SDK and dwf.h file it is also not clear how to set the output type to PP+constant or control the FSM/value -- how do I do that?
  10. On the Discovery2, is it possible to set a different trigger wait-set (Analog/ DigitalOutWaitSet) for each individual channel index, rather than one trigger delay for the whole instrument?
  11. Apologies for asking dumb questions, but that table is definitely not in the version of the SDK reference manual I have been using. I'm using the May 8 2017 version -- is there an update, or is this from an older version and somehow got cut? My version doesn't even have a section 11.3...
  12. Waveforms allows the user to turn the power supplies on and off, and set the voltage for the Analog Discovery 2. How do you do this with the SDK? Also, what is the default setting? I cannot find anything in the documentation. Thanks!
  13. I am using an external trigger pulse to start outputs on AnalogOut and DigitalOut pins using the python SDK. The Trigger Pins on the AD2 are so sensitive that they interpret slight jostles of the wire as a trigger pulse -- so my outputs start unexpectedly. There are functions to qualify the trigger on AnalogIn (hysterisis, lengthcondition, etc) to wait for the right signal -- how do I do something similar for the Analog and Digital Out Triggers (because they seem to only have SlopeSet functions)? Also, is it possible to have the same external trigger line act as both a 'Start' and 'Stop' for a pin?
  14. Hi @jpeyron, I've been struggling to get my alternate implementation to do everything it needs to do. So, I am revisiting this idea. An answer to the original question would be most helpful! Thanks!
  15. One more question, for clarification: why do you use (1<<5) and not (0<<5) to disable the pin?
  16. Thank you for that clarification -- your solution works. You may want to emphasize the D-Out and D-IO prioritization and function in future versions the SDK reference manual -- since many of those commands take a channel index as an argument, it seemed logical that they would only apply to the specified channel(s).
  17. I have built a fairly involved GUI which allows user control of multiple analog and digital output signals on the AD2 with various triggers, timers, and on/off toggles controlling multiple systems. When I try to turn off pulses on a SINGLE digital pin using the DigitalOutOutputSet command, ALL the digital pins switch to zero. But, I need the rest of them to keep running. This section of my code is trivial -- there's not a lot I can do to troubleshoot with something so minimal. What am I missing? def Stop(self): if (self.State == 1 or self.State == 2): ### do some unrelated stuff else: self.StopX() ###reset output on pin5 to 0 self.dwf.FDwfDigitalOutOutputSet(hdwf, c_int(5), c_int(0)) ###(hdwf, idxChannel, v) def StopX(self): try: ###turn off/reset x-ray pulses to zero self.dwf.FDwfAnalogOutReset(hdwf, c_int(-1)) ###ANY CHANCE THIS IS THE CULPRIT?
  18. The AnalogDiscovery2 has functions AnalogOutRunSet and DigitalOutRunSet which set the run length for the entire instrument. Is it possible to set run-times for individual pins, instead of for the instrument as a whole? For example, to have certain pins turn off after an exact duration specified while the other pins continue running uninterrupted?
  19. I configured my program slightly differently so I don't need to do this anymore. Thanks for checking!
  20. Sorry for my confusion, but I think I'm hearing two different things from you on synchronizing the start of the scan acquisition. Trigger or no trigger?
  21. Thanks. I have tried this and things look better (the pulses are occuring around the same time), but I am still having a hard time getting it to work perfectly (they aren't totally synchronized). Over the course of a single 20-second acquisition, the relative position of my data samples seems to shift around some -- see the two snips about 5sec apart during the same trial. The blue pulse should by synchronized with the rising edge of the black pulse. I have verified with an external oscilliscope that the pulses are occurring simultaneously, so it must be the synchronization of the acquisition/plotting which is failing. Is this a problem with how I am configuring the scopes, or is it an artifact of how I am reading from the buffers and updating the plot? Either way, thoughts on how to fix it? Code: #configure digital in cSamples = 200 # set number of sample to acquire rgwSamples = (c_uint16*cSamples)() rg1 = (c_double*cSamples)() #rg = pointer to allocated buffer to copy the acquisition data rg2 = (c_double*cSamples)() #rg = pointer to allocated buffer to copy the acquisition data sts = c_int() self.dwf.FDwfDigitalInAcquisitionModeSet(hdwf, c_int(1)) self.dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcAnalogIn) self.dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.xRate)))) #sample rate at same freq as X-Ray self.dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16)) # 16bit per sample format self.dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples)) self.dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(cSamples/2)) # trigger position in middle of buffer #configure analog in self.dwf.FDwfAnalogInAcquisitionModeSet(hdwf, c_int(1)) self.dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(hzSys.value/(100*self.xRate)))) self.dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(cSamples)) self.dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(0)) # trigger position in middle of buffer self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5)) # begin acquisition on both analog and digital self.dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) self.dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) while True: self.dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) self.dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value : break #read data self.dwf.FDwfAnalogInStatusData(hdwf, c_int(0), rg1, len(rg1)) # get Analog channel 1 data from buffer self.dwf.FDwfAnalogInStatusData(hdwf, c_int(1), rg2, len(rg2)) # get Analog channel 2 data from buffer self.dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, 2*cSamples) # get Digital data #set up plots self.canvasQ.figure.clear() myplt = self.canvasQ.figure.add_subplot(111) myplt.set_ylabel('signal') myplt.set_xlabel('samples') myplt.set_xlim(0,cSamples) myplt.set_ylim(-0.05,1.05) rgpy=[0.0]*len(rgwSamples) rgpy1=[0.0]*len(rg1) rgpy2=[0.0]*len(rg2) for i in range(0,len(rgpy)): rgpy= 1 & rgwSamples for i in range(0,len(rgpy1)): rgpy1=rg1 rgpy2=rg2 myplt.plot(rgpy, 'k') myplt.plot(rgpy1, 'r') myplt.plot(rgpy2, 'b') plt.pause(0.1) self.canvasQ.draw()
  22. I am writing a custom GUI to send and monitor pulses. One system sends a constant background pulse (black) to one piece of hardware, meanwhile the user specify inputs for the pulses for the other systems. When a button is pressed, the configurations are set up and the device is set to wait for a trigger to begin generating the analog pulses. However, I get a single first pulse from the analog waveform generators (blue&red) when the configuration button is clicked, before the PC trigger line pulse is sent. How do I eliminate these initial configuration pulses? This is the code for the configuration. When this method is called I get the single analog pulse outputs. Everything works properly after that ie- the analog pulses start on the correct trigger signal. def ArmTrigger(self): # analog pulse control setup self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(True)) self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_int(True)) self.dwf.FDwfAnalogOutMasterSet(hdwf, c_int(1), c_int(0)); # for second channel set master the first channel, slave channel is controlled by the master self.dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(-1), AnalogOutNodeCarrier, funcSquare) self.dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(self.xRate)) self.dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(1)) self.dwf.FDwfAnalogOutOffsetSet(hdwf, c_int(-1), c_double(0)) self.dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(symm)) #pulse width self.dwf.FDwfAnalogOutNodePhaseSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_double(self.x2Phase)) #phase shift for second channel self.dwf.FDwfAnalogOutRunSet(hdwf, c_int(-1), c_double(self.xDuration)) #set run duration on all channels self.dwf.FDwfAnalogOutIdleSet(hdwf,c_int(-1), c_int(0)) #set up PC trigger to start pulse output AND acquisition self.dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(0), trigsrcPC) self.dwf.FDwfAnalogOutTriggerSlopeSet(hdwf, c_int(0), c_int(0)) # set master channel to trigger on rising edge #configure everything to wait for trigger self.dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) # start master, slave will follow self.StartButton.setEnabled(True) #start button click sends trigger line pulse with dwf.FDwfDeviceTriggerPC(hdwf)
  23. Thanks, I got the TriggerConditionSet fixed. I understand the purpose/function of the loop you provided. However, before the trigger, I am now getting stuck with the analog status in prefill -- it never progresses to 'armed' (the digital status switches from prefill to armed in one iteration through the loop). I tried changing the TriggerPositionSet (based on other forum posts), but it hasn't changed the problem. Can you explain more how the prefill works? Thank you!