def AnalogOutIn(): version = dwf.GetVersion() print "Version: " + version cdevices = dwf.Enum(0) print "Number of Devices: " + str(cdevices) print "Opening first device" hdev = dwf.DeviceOpen(0) print "Configure and start first analog out channel" dwf.AnalogOutEnableSet(hdev, 0, 1) print "1 = Sine wave" dwf.AnalogOutFunctionSet(hdev, 0, 1) dwf.AnalogOutFrequencySet(hdev, 0, 3000) print "" dwf.AnalogOutConfigure(hdev, 0, 1) print "Configure analog in" dwf.AnalogInFrequencySet(hdev, 1000000) print "Set range for all channels" dwf.AnalogInChannelRangeSet(hdev, -1, 4) anInBufSize = 4000 dwf.AnalogInBufferSizeSet(hdev, anInBufSize) print "Wait after first device opening the analog in offset to stabilize" time.sleep(2) print "Starting acquisition" dwf.AnalogInConfigure(hdev, 1, 1) print " waiting to finish" while True: sts = dwf.AnalogInStatus(hdev, 1) if sts == dwf.DwfStateDone: break time.sleep(0.1) print " done" print " reading data" rg = np.zeros(anInBufSize, dtype=np.double) dwf.AnalogInStatusData(hdev, 0, rg) dwf.DeviceCloseAll() dc = np.mean(rg) print "DC: " + str(dc) + "V" plt.plot(rg) plt.show()
def AnalogIn_Acquisition(): #print DWF version version = dwf.GetVersion() print "DWF Version: %s" % (version) #open device print "Opening first device" hdwf = dwf.DeviceOpen(-1) if hdwf == dwf.hdwfNone: print "failed to open device" else: print "Preparing to read sample..." #set up acquisition dwf.AnalogInFrequencySet(hdwf, 20000000.0) dwf.AnalogInBufferSizeSet(hdwf, 4000) dwf.AnalogInChannelEnableSet(hdwf, 0, True) dwf.AnalogInChannelRangeSet(hdwf, 0, 5) #wait at least 2 seconds for the offset to stabilize time.sleep(2) #begin acquisition dwf.AnalogInConfigure(hdwf, False, True) print " waiting to finish" while True: sts = dwf.AnalogInStatus(hdwf, 1) print "STS VAL: %s STS DONE: %s" %( sts, dwf.DwfStateDone) if sts == dwf.DwfStateDone : break time.sleep(0.1) print "Acquisition finished" rgdSamples = np.zeros(4000, dtype=np.double) dwf.AnalogInStatusData(hdwf, 0, rgdSamples) dwf.DeviceCloseAll() #plot window dc = np.mean(rgdSamples) print "DC: %f V" % (dc) plt.plot(rgdSamples) plt.show()
def AnalogIn_Trigger(hdwf): rgdSamples = np.zeros(4000, dtype=np.double) #set up acquisition dwf.AnalogInFrequencySet(hdwf, 20000000.0) dwf.AnalogInBufferSizeSet(hdwf, 8192) dwf.AnalogInChannelEnableSet(hdwf, 0, True) dwf.AnalogInChannelRangeSet(hdwf, 0, 5) #set up trigger dwf.AnalogInTriggerAutoTimeoutSet(hdwf, 0) #disable auto trigger dwf.AnalogInTriggerSourceSet( hdwf, dwf.trigsrcDetectorAnalogIn) #one of the analog in channels dwf.AnalogInTriggerTypeSet(hdwf, dwf.trigtypeEdge) dwf.AnalogInTriggerChannelSet(hdwf, 0) # first channel dwf.AnalogInTriggerLevelSet(hdwf, 1.5) # 1.5V dwf.AnalogInTriggerConditionSet(hdwf, dwf.trigcondRisingPositive) #wait at least 2 seconds for the offset to stabilize time.sleep(2) print " starting repeated acquisitons" for iTrigger in range(1, 100): #begin acquisition dwf.AnalogInConfigure(hdwf, False, True) while True: sts = dwf.AnalogInStatus(hdwf, 1) if sts == dwf.DwfStateDone: break time.sleep(0.001) dwf.AnalogInStatusData(hdwf, 0, rgdSamples) dc = np.mean(rgdSamples) print "Acquisition #%3d average: %g V" % (iTrigger, dc) dwf.DeviceCloseAll()
def AcquireAnalog(fd, cnt, fSample=2E6, chNr=0): ''' Aquire analog input data: fd Descriptor for the file cnt Sample count to aquire fSample Sample frequency in [Hz] chNr Input channel 0..1 ''' data = None if 0 <= chNr < 2: data = np.zeros(cnt, dtype=np.double) dwf.AnalogInFrequencySet(fd, fSample) dwf.AnalogInBufferSizeSet(fd, cnt) dwf.AnalogInChannelEnableSet(fd, chNr, True) dwf.AnalogInChannelRangeSet(fd, chNr, 5) time.sleep(2) dwf.AnalogInConfigure(fd, False, True) sts = dwf.stsCfg while not sts == dwf.stsDone: sts = dwf.AnalogInStatus(fd, True) print("Current analog status: %d" % sts) dwf.AnalogInStatusData(fd, chNr, data) return data
def AnalogIn_Sample(): #print DWF version version = dwf.GetVersion() print "DWF Version: %s" % (version) #open device "Opening first device..." hdwf = dwf.DeviceOpen(-1) if hdwf == dwf.hdwfNone: print "failed to open device" else: print "Preparing to read sample..." dwf.AnalogInChannelEnableSet(hdwf, 0, True) dwf.AnalogInChannelOffsetSet(hdwf, 0, 0) dwf.AnalogInChannelRangeSet(hdwf, 0, 5) dwf.AnalogInConfigure(hdwf, False, False) time.sleep(2) sts = dwf.AnalogInStatus(hdwf, False) voltage = dwf.AnalogInStatusSample(hdwf, 0) print "Voltage: %f V" % (voltage) dwf.DeviceCloseAll()