Search the Community

Showing results for tags 'ad2'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News
    • New Users Introduction
    • Announcements
  • Digilent Technical Forums
    • FPGA
    • Test and Measurement
    • Measurement Computing (MCC)
    • Add-on Boards
    • Digilent Microcontroller Boards
    • Non-Digilent Microcontrollers
    • LabVIEW
    • FRC
    • Other
  • General Discussion
    • Project Vault
    • Learn
    • Suggestions & Feedback
    • Buy, Sell, Trade
    • Sales Questions
    • Off Topic
    • Educators
    • Technical Based Off-Topic Discussions
    • Archived

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hello, I got Device opening failed window, shown below. Is there a troubleshooting I could do to get it working? Thanks, Adonay
  2. Dear experts, May I know how the AD2 waveform 15 calculates the phase difference in the bode plot of network analyser? And how does the averaging/average function works? Does it help decrease my signal noise or is there anyway/functions to have a more accurate phase difference reading? I attached a picture, and I would like to ask if the AD2 is able to capture the phase difference between this 2 signal or is it too noisy? Thanks a lot for reading!
  3. Hi experts, I wanted to control spectrum analyser of AD2 using labview, but it seems like there is no vi for it, hence I used bode analyser. I was wondering from the bode analyser labview, how/is there a way for me to control all the controls that is shown in this image? Also, I encounter a problem in which when I change the amplitude lower than 3V for the bode analyser vi, it will hang. Is there something wrong that I did? The reason why I want to control the spectrum analyser is because I want 'for a step increase in W2, a fast frequency sweep (using W1) is done to get the phase difference between scope 1 and 2, which setting the values for min periods etc will allow me to get a more accurate reading. And for each sweep, I want to export the data to excel. Is there a way to do this via labview/python or any other ways to automate this process? Thanks! Digilent_WaveForms_Bode Analyzer (FGEN and MSO).vi
  4. I've searched past content and I've been unable to find a complete answer on how to handle a "Device is busy" error message on an Analog Discover 2's. Setup: Raspberry Pi 4B 8GB RAM Raspberry Pi OS 32-bit (full version -- not headless, but without monitor) 128 GB fast SD-Card AD2 with USB connection to Raspberry Pi USB port (USB 3) AD2 powered separately There are three of these setups (Pi+AD2+Power+Network) operating remotely on the same network, with all communicating back to a central monitoring PC Hardware runs 24 hours/day, 7 days a week. AD2 is being used for: Waveform generation for an RF emitter ADC for incoming signals.Real-time operation. Real-time operation 100% Python3 script running AD2, network, and processing tasks Autostart (.desktop) launches script on bootup (due to chmod -x) The remote locations will occasionally and unexpectedly power cycle. There is no graceful closing of software or any devices when this happens. When this occurs, the application script will autostart when power is restored and the program tries to reconnect to all devices. (This includes re-establishing network connection back at the central command station PC.) The AD2 gives the device is busy error message on all 3 setups every time -- without exception. The script that launches the AD2 is the only script initiated at startup. I tried the attached script segment to capture errors and to attempt to timeout the condition. But it doesn't work. It will just keep looping and supply a continuous device is busy message. My patience only permitted me to watch this for 5 minutes, but I would assume it will be indefinite. You can see that much of this code comes straight out of the sample scripts that comes with installation of of the Waveform API. Currently the fix is to just restart the program. Doing so will automatically free up the device and the script will run properly Having the customer to kill the application and restart it is not ideal. Is there a solution for this? I suspect that perhaps this might be a previous state that is somehow stored or that the device is busy still booting itself while the script is launched. Unsure as to what may actually be happening, can someone help me? My apologizes for the novella, but I wanted to supply as much detail as possible. AD2 Startup Python Script
  5. Hello there, I need to log the 2 analog Channels simultaniously with a high Samplerate of ~6MS, everything triggered off the falling edge of DIO pin 6. (IQ channels of FMCW radar, triggered of the PLLs Chirp Start signal) I already managed to log Data on one channel using the 16k Buffer. Also Triggering on the second Channel as well as on the external Trigger worked. But I can not manage to trigger of an specific DIO pin. Everything in Python. 1. If I got the SDK right, I only need one hdwf device handle for the AD2, not one for the analog and one for the digital instrument? 2. Also with the Trigger Bus I should be able to trigger the Analog Instrument off the DigitalTriggerDetector? 3. So my understandig is that I set the AnalogIn Trigger Source to DetectorDigitalIn (Trigger Bus connection). All the settings for the Trigger itself condition/pin/PositionShift/... have then to be done under: FDwfDigitalInTrigger...() in the DigitalDtriggerDetectior, right? 4. If so I can not really see from the SDK and the Examples, what Fuctions I have to call to arm the DigitalTriggerDetector in Order to Trigger on the Falling Edge of DIO6. Please tell me the necessary functionsto do so!:) 5. And one more additional question: Does every Analog Channel have its own 16k buffer or is the buffer shared for both or even the Digial pins as well? And is there a more in depth documentation then the SDK and examples? Thanks in advance! I added the code below: from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy ####### Load the DWF, which forms the API between Python ond the C based Waveforms SDK ####### if sys.platform.startswith("win"): dwf = cdll.dwf elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") ######################################################################################### ########################## user definable parameters #################################### ######################################################################################### AcqHz = 100e6 # acquisitionHz / samplerate of ADC, max. 100MHz Samples = 2**14 # samples to collect after triggering, max. 2^14 samples ChlRange = 3.3 # set the +- Voltage range of AnalogIN Channel TrgPin = 6 # set the DIO Pin for the Trigger TrgLvl = 1.1 # set the voltage for the Trigger ######################################################################################### ######################################################################################### hdwf = c_int() # create datatype for hardware handle of AD2 sts = c_byte() # create datatype for later status request of acquisition nSamples = (c_double * Samples)() # create array for samples to be stored in ####### get the DWF Version provided by Digilent as an API between Python and the C based Waveforms SDK ####### version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("Digilent DWF (API) Version: " + str(version.value)) ####### opening the device ####### print("Opening first device") #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # 2nd configuration for Analog Discovery with 16k analog-in buffer dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1), byref(hdwf)) # open the AD2 and retrieve the handle if hdwf.value == hdwfNone.value: # if no device is found or the device is already in use szError = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szError); print("failed to open device\n" + str(szError.value)) quit() ####### set up acquisition ####### dwf.FDwfAnalogInFrequencySet(hdwf, c_double(AcqHz)) # set acquisition frequency dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(len(nSamples))) # set the buffer size for AnalogIn dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(ChlRange)) # set the Voltage range of AnalogIN Channel ####### set up trigger for the analog channel to be the DigitalInDetector ####### dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) # disable auto trigger at analog channel dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn) # set the triggger source for the analog channels to be the DigitalInTriggerDetector #dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcExternal1) # ExtTrg1 as Trigger Source ### settings for analogIn Trigger Detector ### ''' dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge) dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondFallingNegative) # <----------------- warum geht das nicht?? dwf.FDwfAnalogInTriggerChannelSet(hdwf, c_int(0)) # first channel dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(TrgLvl)) # trigger level 0.5V dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) # move trigger to left boundary, otherwise the signal will start in the middle #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(Samples/(2*AcqHz)))# Configures the horizontal trigger position in seconds. #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(4000/(2*AcqHz)))# Configures the horizontal trigger position in seconds. print("Trigger horizontal Position Set to: " +str(-Samples/(2*AcqHz)) + "sec. Left boundary of Buffer.") ''' ####### settings for the trigger on digital channel ####### #dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn - Sets the trigger source for the instrument. #dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(int(cSamples/2-1))) # Sets the number of samples to acquire after trigger. ## Configures the digital in trigger detector. ## #The logic for the trigger bits is: Low and High and (Rise or Fall). Setting a bit in both rise and fall will trigger on any #edge, any transition. For instance FDwfDigitalInTriggerInfo(hdwf, 0b0001, 2, 4, 8) will generate trigger when DIO-0 is low #and DIO-1 is high and DIO-2 is rising or DIO-3 is falling. The bits of the arguments represent pins. # FDwfDigitalInTriggerSet(HDWF hdwf, uint fsLevelLow, uint fsLevelHigh, uint fsEdgeRise, uint fsEdgeFall) dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<6)) # DIO6 falling edge - The bits of the arguments represent pins. ####### set up power supply ####### dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(3.3)) # set voltage to ... V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(-3.3)) # set voltage to -... V dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable ###### wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change ##### time.sleep(2) ####### get AnalogIN instrument in Ready state ####### print("Starting AnalogIN instrument. Waiting for trigger...") # FDwfAnalogInConfigure(hdwf, int fReconfigure, int fStart) dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, setfReconfigure to TRUE. ####### repeatedly check if acquisition has been made ####### while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value: # if so: acquisition completed, break while loop break time.sleep(0.001) # else: wait 1ms and check again ####### get the nSamples from the desired channel ####### dwf.FDwfAnalogInStatusData(hdwf, 0, nSamples, len(nSamples)) # get channel 1 data from buffer # dwf.FDwfAnalogInStatusData(hdwf, 1, nSamples, len(nSamples)) # get channel 2 data print("Data collected from AnalogIN buffer.") ####### close device and free handle ####### dwf.FDwfDeviceCloseAll() print("Device released.") ####### store data to .csv file ####### f = open("TriggeredRecord.csv", "w+") for value in nSamples: f.write("%s\n" % value) f.close() print("Data saved to .csv file.") ####### display data ####### plt.plot(numpy.fromiter(nSamples, dtype=numpy.double), 'bo-') # plot(x,y,style) plt.show()
  6. Hi folks - I have a Mac running 10.10.5 and another with 10.11 both not connecting to the Analog Discovery 2 hardware over USB. What I know: Hardware works fine from a Windows VM on the Mac Plugging in the AD2 loads kext com.digilent.driver.DigilentFtdiDriver AND com.apple.driver.AppleUSBFTDI Neither removing com.apple.driver.AppleUSBFTDI via kextunload nor deleting the kext file helps Following the *awesome* steps at this post didn't help - WaveForms sees and loads the driver (no logs spit out normally; logs spit out when I rename driver) but still no dice Keeping AD2 unplugged while restarting: no dice Reinstalling WafeForms and DigilentFtdiDriver-1.0.3.pkg - no dice Any ideas? Eager to get working on Macs.
  7. Hello all, I need to use the AD2 / AD Pro for some analog/digital signal measurements. I have a few questions before I make the purchase. Can I acquire both the Analog as well as Digital input channels simultaneously with MATLAB? Can I change the Gain of an Analog Channel from MATLAB? If so, how? After changing the gain, does the resolution of 14bit apply to this amplified value? i.e. if with 1X gain the input range is +-25V, and the 14 bits are mapped to this voltage range, Does making the gain 10X, make the 14bits map to the new range? i.e. +-2.5V? Thus increasing the precision of the system to low voltages? In my test setup I need to probe (2 analog) signals which will vary in terms of mV (lets say 1-2mVs) and 2 Digital signals simultaneously. Will I be able to measure these small signals with AD2 or AD Pro, If so, which one will be better?
  8. We are using AD2 on custom design imx6 based microcontroller. The controller has only 2 USB ports & we are using a USB switching IC to switch between multiple devices. The device performs well as long as we are not switching the USB port, but when switching is performed the device stops collecting data. The USB switching action is equivalent of disconnecting & reconnecting USB cable. We are using Python for our application. Here's the code. What can be the possible error.
  9. I'm calculating and recording power through a load based on voltage and current measured on C1 and C2 of my Analog Discovery 2 scope, at 4kHz, for about an hour. Next to this I would like to log the temperature of the same load, or which the data is supplied through a UART. Would it be possible to visualize both these measurements in the same plot using a script? Perhaps by writing to a reference or math channel? We would have to be able to see all the values and plots live. Thanks! David
  10. Hi With the waveforms tool is it possible using python scripting in the Waveforms platform to do the following ?? Use the Digilent Analogue discovery 2 - Attach a device like a PMOD device eg accelerometer https://store.digilentinc.com/pmod-acl-3-axis-accelerometer/ using the Analogue discovery 2 ability to chat SPI & IC2 - pmod DEVICES SUPPORT 12-pin Pmod connector with SPI interface and 2×4-pin I²C interface - Then using the read information from the PMOD device treat it like an extra oscilloscope channel . Either as a Analog channel or Digital channel depending on the the signal type acquired from the PMOD device. This is possible with Labview but that would also require a lot of code writing. If this is possible this is outstanding feature when considering all the available PMOD devices available from the list https://store.digilentinc.com/by-function/input/ This would be a real product enhancement for Digilent and the Analog Discovery and help sell the AD2 in to many new places . Best wishes Simon
  11. I am trying to use the power supply and I keepy getting this message for V+. V- works just fine by itself. I have tried: reconnecting the Analog Discover 2 restarting my laptop disconnecting every cable and running the AD2 by itself connecting the auxillary supply Any help would be greatly appreciated!
  12. Hello, I am trying to plot the sine wave of frequency 100 Hz and 500mV amplitude, but the waves in the scope are not reflecting it. I have also observed that the measurements for the frequency is also exceeding the 100 Hz. I would really appreciate if anyone can explain this concept.
  13. Hi all hope you are all doing well. I need to use the SDK and measure all this measurements but apparently there are no functions to calculate for example AC RMS values to call. do i need to come up with my formula or is there any function that can return all the following values ? thank you.
  14. Any help will be greatly appreciated. My goal is to receive a trigger on a Analog-In Channel to be followed by a Generated Signal on an Analog Out Channel after a specified time, and this needs to be repeated numerous times. How accurate can this specified time and how consistent can it be? Are there any built in functions that can get this accomplished. I have seen many references to the defined Wait functionality, which can accomplish this expected behavior, however the wait time varies and there is an approximate ~17ms delay. Thanks for your help.
  15. Hello, I have an Analog Discovery 2 that has had an issue on Channel 2 of its oscilloscope for a few months now. Essentially, the channel measures around -25 V at all times, whether it is floating, grounded, shorted, connected to the BNC adapter board, etc. I have not used it in any high-voltage applications or scenarios. I have attempted to manually recalibrate the oscilloscope, but I get an error when I do so telling me the voltage on Channel 2 is between -2.7418 and -2.7412 V but it should be around 0 V. I've attached a screenshot of this error below. Note that I did calibrate the Wavegen 1 offset as suggested but that did not fix the issue. I've also tried loading the factory calibration, which seemed to load successfully but didn't resolve the issue. When I measure the DC voltage on 2+ pin on the AD2 I see it's around -4.8 V, whereas the 1+, 1- and 2- pins all read around 0 V. I'm happy to probe around more to help debug, but for now I'm not too sure where to start. Thanks, K
  16. Hi all, I have a question about AD2 immediate sampling data output. I am doing a university project which needs AD2 to do analog signal measurement on LabVIEW. AD2 measures a signal with 12.8 KHz sampling frequency. I am wondering if I can get the immediate measured data without sample lost? Thanks!
  17. To have a better FFT resolution we want to reduce the sample rate to around 1Msps either in AD2 or Openscope, can we replace the main clock or have other option to accomplish it? Thanks
  18. We're excited about using the AD2 for a whole bunch of courses in our college as we teach online for the foreseeable future. One useful feature would be if we could get the raw A to D data from the scope channels so we can use them in LabVIEW. At this point, niVB_MSO_ReadAnalogDigitalU64 provides the voltages, all cleaned up, instead. Is there another dwf that provides the raw data, or could this feature be added to the next revision? At this point, I'm taking the voltage and converting it back to a step count using the step size, but we'd be just a bit more accurate if we had the raw data.
  19. Hello, I see in the manual that the WG has + and - supplies, though the supplies are limited to 5V. Is it possible to use both WG outputs in sync to do a ramp from -5 to +5V? I want to do a 0-10V sweep.
  20. Hi Attila, A year ago exactly (I really coincidentally just decided to send you this exactly 1 year from when it was posted ... go figure!!!) you posted the following: Posted September 30, 2019 Hi @iDetect Soon you may find devices at Digilent better suited for your needs. I'm planning to add support for lower latency captures with Analog Discovery, but it will take some time to implement it. Thank you for your post. Such feedback/requests direct the soft/hardware developments. Wondering if there is any news in this 'lower latency' realm? I have an application involving analog data acquisition that requires the capture of a 'sliver' of data 20 usecs of data (at 50Msps) to be collected every 6msec. Via any automation software strategy for the AD2 is it possible to write custom software so that I can transfer small segments of data 'on the fly' to a target buffer/file (appending each 20usec chunk of data every 6msec)? (I know the rough composite maximum AD2 rate is/was ~1Msp as you have stated in the past so it would be below that rate on 1 channel acquisition). Any improvement in this realm? I don't necessarily need to trigger for each 6msec period because of the repetition capture time window being a deterministic 6msec period BUT I may want to actually use multiple triggers to capture such small segments for other applications I'm basically trying to reduce the data transfer total to have a fighting chance to make at least soft real-time decisions. So I just need 20usecs captures each 6msec period which works out to 166 20usec 50Msps captures/6msec samples per so the total data collected is 20usecs * 166 @ 50Msps Multiple triggers would be 'nice' for other application Thank you, Dean Vieau
  21. Hi I am new with AD2 and love using is so far. I need to create a measurement script to measure the time between minimum and max values. rise time function does not work correctly for my application for some reason. thank you in advance. thanks
  22. Hello, I see in the specs that the max buffer size is over 16k points, but it seems that I can only get 8192 samples from this code. "FDwfAnalogInBufferSizeInfo" returns 8192. How can I get the 16k samples? I would like to get 16k samples for each ADC channel. I am using the Analog Discovery 2. Thanks! int main(int carg, char **szarg) { HDWF hdwf; STS sts; double* rgdSamples; int cSamples; int cChannel; char szError[512] = { 0 }; int channum = 0; cout << "hello world!"; remove("ADC_results.txt"); printf("Open automatically the first available device\n"); if (!FDwfDeviceOpen(-1, &hdwf)) { FDwfGetLastErrorMsg(szError); printf("Device open failed\n\t%s", szError); return 0; } // get the number of analog in channels FDwfAnalogInChannelCount(hdwf, &cChannel); // enable channels for (int c = 0; c < cChannel; c++) { FDwfAnalogInChannelEnableSet(hdwf, c, true); } // set 5V pk2pk input range for all channels FDwfAnalogInChannelRangeSet(hdwf, channum, 5); // 10MHz sample rate FDwfAnalogInFrequencySet(hdwf, 10000000.0); // get the maximum buffer size FDwfAnalogInBufferSizeInfo(hdwf, NULL, &cSamples); FDwfAnalogInBufferSizeSet(hdwf, cSamples); // acquisition mode set added by Phil FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeSingle); rgdSamples = new double[cSamples]; // configure trigger FDwfAnalogInTriggerSourceSet(hdwf, trigsrcNone); Wait(2); // start FDwfAnalogInConfigure(hdwf, 0, true); printf("Waiting for triggered or auto acquisition\n"); do { FDwfAnalogInStatus(hdwf, true, &sts); } while (sts != stsDone); FDwfAnalogInStatusData(hdwf, channum, rgdSamples, cSamples); fopen_s(&gDatLog, "ADC_results.txt", "a"); for (int i = 0; i < cSamples; i++) { fprintf(gDatLog, "%lg\n", rgdSamples); } fclose(gDatLog); // close the device FDwfDeviceClose(hdwf); //} return 0; }
  23. I am using the AD2 on LabVIEW with dwf.dll. I am using the I2C interface on DIO bits 0 and 1 and the positive power supply. I have configured everything based on the python example code. When I set the power supply and write the I2C data, several other DIO bits go high even though they are not configured in this program. I have auto configuration enabled. I can do the same thing in WaveForms and it works fine. Any suggestions would be appreciated. Thank you
  24. Hi. I have troubles using the trigger functions in the SDK to align the recording of a signal with the pattern generator (DigitalOut Instrument on AD2). What I want to do is essentially, using the SDK in a python script is: - I record a signal from the AWG on the AD2 I am sending through an analog circuit using two multiplexers. - I control the multiplexers with the digitalOut instrument on the AD2. - I want to align the starting point of the digitalOut-pattern and the starting point of the AnalogIn acquisition (record-mode, int16 data) As far as I understand from the SDK reference for this purpose I can trigger the analogIn with the digitalOut (use trigsrcDigitalOut from the dwf constants). However, when I implemented this, I get an undefined timelag between the acquistion of data and the start of the digitalOut signal. To illustrate this, I recorded the signal of one of the digital pins I use to generate the pattern for the multiplexers (I record the bare 16int ADC conversions, to read faster from the AD2). I sample at 1Mhz and the the pattern I output on this particular pin starts with (1,0,...) at 100Hz. As you can see, the timelag seems to be around ca. 1.5 ms. I also did another experiment, trying out the same thing in the WaveForms Software. Instead of outputting a custom pattern, I just output a clock at 100Hz on the same digital pin and record this signal through channel 1 of the oscilloscope. From what I understand, the two experiments should be pretty much equal, so I am puzzled I get this delay of approximately 1.5ms when I implement it with SDK functions. Does anyone have an explanation why the trigger is not correctly aligned in my python script, and why this timelag is not deterministic? Any help would be greatly appreciated! (PS: I can provide a code snippet, but right now my code is shared from different fies & classes, so it is not straightforward to copy it to here...) updated: I have a code snippet for illustration below: import math import sys import time from ctypes import * import matplotlib.pyplot as plt import numpy from dwfconstants import * if sys.platform.startswith("win"): dwf = cdll.dwf elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") # declare ctype variables hdwf = c_int() sts = c_byte() hzAcq = c_double(1e6) nSamples = 2 ** 17 rgSamples = (c_int16 * nSamples)() cAvailable = c_int() cLost = c_int() cCorrupted = c_int() fLost = 0 fCorrupted = 0 # print(DWF version version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("DWF Version: " + str(version.value)) # open device print("Opening first device") dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == hdwfNone.value: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) print("failed to open device") quit() ######################################################################################## # set up pattern generator data = [1, 0, 1, 0, 0, 1, 0, 0, 1] pin = 11 hzSys = c_double() dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys)) rgbdata = (c_ubyte * ((len(data) + 7) >> 3))(0) # array to bits in byte array for j in range(len(data)): if data[j] != 0: rgbdata[j >> 3] |= 1 << (j & 7) # var |= value is var = var | value print("bytestream of data " + str(pin) + ": " + str(list(rgbdata))) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(pin), c_int(1)) dwf.FDwfDigitalOutTypeSet(hdwf, c_int(pin), DwfDigitalOutTypeCustom) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(pin), DwfDigitalOutIdleLow) # set Divider to generate output at frequency f_scan. dwf.FDwfDigitalOutDividerSet(hdwf, c_int(pin), c_int(int(hzSys.value / 100))) dwf.FDwfDigitalOutDataSet(hdwf, c_int(pin), byref(rgbdata), c_int(len(data))) dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcNone) # set up acquisition dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord) dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq) dwf.FDwfAnalogInRecordLengthSet( hdwf, c_double(nSamples / hzAcq.value) ) # -1 infinite record length dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDigitalOut) # wait at least 2 seconds for the offset to stabilize time.sleep(2) print(f"Starting oscilloscope. Measure digitalout pin {pin}") dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) # configure digitalOut instrument, don't run yet (enough time to fill buffer with data) dwf.FDwfDigitalOutConfigure(hdwf, c_int(0)) time.sleep(2) cSamples = 0 # start the digitalOut instrument dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) while cSamples < nSamples: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if cSamples == 0 and ( sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed ): # Acquisition not yet started. continue dwf.FDwfAnalogInStatusRecord( hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted) ) cSamples += cLost.value if cLost.value: fLost = 1 if cCorrupted.value: fCorrupted = 1 if cAvailable.value == 0: continue if cSamples + cAvailable.value > nSamples: cAvailable = c_int(nSamples - cSamples) dwf.FDwfAnalogInStatusData16( hdwf, c_int(0), byref(rgSamples, sizeof(c_int16) * cSamples), c_int(0), cAvailable, ) # get channel 1 data # dwf.FDwfAnalogInStatusData16(hdwf, c_int(1), byref(rgSamples, sizeof(c_int16)*cSamples), c_int(c), Available) # get channel 2 data cSamples += cAvailable.value dwf.FDwfAnalogOutReset(hdwf, c_int(0)) dwf.FDwfDeviceCloseAll() print("Recording done") if fLost: print("Samples were lost! Reduce frequency") if fCorrupted: print("Samples could be corrupted! Reduce frequency") f = open("record.csv", "w") for v in rgSamples: f.write("%s\n" % v) f.close() plt.plot(numpy.fromiter(rgSamples, dtype=numpy.int16)) plt.show()