Jump to content

Take4

Members
  • Posts

    5
  • Joined

  • Last visited

Take4's Achievements

Newbie

Newbie (1/4)

2

Reputation

  1. Hi @reddish The dwf package seems very useful. I installed it. Thanks for the useful information.
  2. Hi @attila Thank you for your help. I set analog input to 2V by dwf.FDwfAnalogInChannelRangeSet(hdwf, channel#, c_double(2.0)) and got the waveform below. The new version looks useful, I'll consider updating. One more question, can the sample mode be changed from the SDK? Thank you.
  3. from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy import csv 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(1000000) N = 262144 rgdSamples1 = (c_double*N)() rgdSamples2 = (c_double*N)() 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() #------------------------------------Waveform setting------------------------------------------ print("Generating sine wave...") dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(500)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(0.2)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1)) #---------------------------------set up for aquisition---------------------------------------- dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_int(1)) dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1)) dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord) dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq) dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(N/hzAcq.value)) # -1 infinite record length #wait at least 2 seconds for the offset to stabilize time.sleep(2) print("Starting oscilloscope") dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) cSamples = 0 Channel1_data = [] Channel2_data = [] #---------------------------------------------Start aquisition------------------------------------------------- while cSamples < N: 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 > N : cAvailable = c_int(N-cSamples) dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples1, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgdSamples2, sizeof(c_double)*cSamples), cAvailable) # 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") #aquiring data length data_length = len(rgdSamples1) #Storing data in arrays for i in range(data_length): Channel1_data.append(rgdSamples1[i]) Channel2_data.append(rgdSamples2[i]) #--------------------------stored in csv file------------------------------ with open('record.csv', mode = 'w', newline = '') as file: writer = csv.writer(file) for item1, item2 in zip(Channel1_data, Channel2_data): writer.writerow([item1, item2]) plt.plot(numpy.fromiter(rgdSamples1, dtype = numpy.float64)) plt.plot(numpy.fromiter(rgdSamples2, dtype = numpy.float64)) plt.show() The top waveform was obtained from the Waveform application and the bottom waveform was obtained using the Waveform SDK. Hello, I have a question regarding the behavior of WaveForm SDK when acquiring waveforms. I use an ADP3450 and I want to get the same waveforms in the WaveForms app and the WaveForm SDK, but this makes a difference. Is this a difference between the settings in the SDK and the application? Can someone please help me with a solution to this? I attach the program of my python and the screen shot of the setting for acquiring waveforms in the application. Below is a screen shot of the settings for waveform acquisition in the application. This is the entire WaveForms setup screen. And, this image is the setting for acquiring waveforms. Thank you.
  4. Hi @attila Thank you for the answer. I checked it while switching between DC and AC mode and it worked fine. Thank you for your help.
  5. from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy import csv 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(1000000) N = 262144 rgdSamples1 = (c_double*N)() rgdSamples2 = (c_double*N)() 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() #------------------------------------Waveform setting------------------------------------------ print("Generating sine wave...") dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(500)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(0.2)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1)) #---------------------------------set up for aquisition---------------------------------------- dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_int(1)) dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1)) dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord) dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq) dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(N/hzAcq.value)) # -1 infinite record length #wait at least 2 seconds for the offset to stabilize time.sleep(2) print("Starting oscilloscope") dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) cSamples = 0 Channel1_data = [] Channel2_data = [] #---------------------------------------------Start aquisition------------------------------------------------- while cSamples < N: 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 > N : cAvailable = c_int(N-cSamples) dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples1, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgdSamples2, sizeof(c_double)*cSamples), cAvailable) # 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") #aquiring data length data_length = len(rgdSamples1) #Storing data in arrays for i in range(data_length): Channel1_data.append(rgdSamples1[i]) Channel2_data.append(rgdSamples2[i]) #--------------------------stored in csv file------------------------------ with open('record.csv', mode = 'w', newline = '') as file: writer = csv.writer(file) for item1, item2 in zip(Channel1_data, Channel2_data): writer.writerow([item1, item2]) plt.plot(numpy.fromiter(rgdSamples1, dtype = numpy.float64)) plt.plot(numpy.fromiter(rgdSamples2, dtype = numpy.float64)) plt.show() Hello, I have a question about programming with Waveform SDK. I use an ADP3450 and I want to change the coupling of the Input channels from DC to AC. I added to the program the command below dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1)) ,but it didn't work. Could somebody tell me how to get the program to work properly? I attach the program of my python. Thank you.
×
×
  • Create New...