示例#1
0
def Device_Enumeration():

    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: " + version

    #enumerate and print device information
    cdevices = dwf.Enum(0)
    print "Number of Devices: " + str(cdevices)

    for i in range(0, cdevices):
        devicename = dwf.EnumDeviceName(i)
        serialnum = dwf.EnumSN(i)
        print "------------------------------"
        print "Device %d :" % (i)
        print "\t" + devicename
        print "\t" + serialnum
        IsInUse = dwf.EnumDeviceIsOpened(i)

        if not IsInUse:
            hdwf = dwf.DeviceOpen(i)
            channel = dwf.AnalogInChannelCount(hdwf)
            hzfreq = dwf.AnalogInFrequencyInfo(hdwf)
            print "\tAnalog input channels: " + str(channel)
            print "\tMax freq: " + str(hzfreq)
            dwf.DeviceClose(hdwf)
            hdwf = -1

    # ensure all devices are closed
    dwf.DeviceCloseAll()
示例#2
0
def DigitalOut_BinarayCounter():
    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: " + 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..."

        hzSys = dwf.DigitalOutInternalClockInfo(hdwf)
        print " internal frequency is  %.3f Hz" % (hzSys)
        # generate counter
        for i in range(0, 15):
            dwf.DigitalOutEnableSet(hdwf, i, 1)
            # increase by 2 the period of successive bits
            dwf.DigitalOutDividerSet(hdwf, i, 1 << i)
            # 100kHz counter rate, SystemFrequency/100kHz
            cntFreq = hzSys / 1e5
            cntFreqres = int(math.floor(cntFreq))
            print " counter frequency is %.3f Hz " % (cntFreqres)
            dwf.DigitalOutCounterSet(hdwf, i, cntFreqres, cntFreqres)

        dwf.DigitalOutConfigure(hdwf, 1)

        time.sleep(10)
    dwf.DeviceCloseAll()
示例#3
0
def DigitalIO():
    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: "+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 Digital IO pins..."
    
        # enable output/mask on 8 LSB IO pins, from DIO 0 to 7
        dwf.DigitalIOOutputEnableSet(hdwf, 0x00FF) 
        # set value on enabled IO pins
        dwf.DigitalIOOutputSet(hdwf, 0x12) 
        # fetch digital IO information from the device 
        dwf.DigitalIOStatus (hdwf) 
        # read state of all pins, regardless of output enable
        dwRead = dwf.DigitalIOInputStatus(hdwf) 
    
        #print dwRead as bitfield (32 digits, removing 0b at the front)
        print "Digital IO Pins:  " + bin(dwRead)[2:].zfill(32)
        
        dwf.DeviceCloseAll()
def AnalogIO_AnalogDiscovery_SystemMonitor():
    #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"
        return
    else:
        print "Preparing to monitor Voltage, Current, Temp..."

    #monitor voltage, current, temperature
    #60 times, once per second
    for i in range(1, 60):
        # wait between readings; the update rate is approximately 1Hz
        time.sleep(1)
        # fetch analog IO status from device
        dwf.AnalogIOStatus(hdwf)
        # get system monitor readings
        deviceVoltage = dwf.AnalogIOChannelNodeStatus(hdwf, 2, 0)
        deviceCurrent = dwf.AnalogIOChannelNodeStatus(hdwf, 2, 1)
        deviceTemperature = dwf.AnalogIOChannelNodeStatus(hdwf, 2, 2)
        print "Device USB supply voltage: %5g V" % (deviceVoltage)
        print "Device USB supply current: %5g A" % (deviceCurrent)
        print "Device temperature:        %.2f C" % (deviceTemperature)
    #close the device
    dwf.DeviceCloseAll()
示例#5
0
def AnalogOut_Custom():
    #Generate Sawtooth
    rgdSamples = np.zeros(4000, dtype=np.double)
    for i in xrange(rgdSamples.shape[0]):
        val  =((i%100)-50)/100.0
        rgdSamples[i] = val
    channel = 0
    
    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: "+version
    
    #open device
    "Opening first device..."
    hdwf =dwf.DeviceOpen(-1)
    
    if hdwf == dwf.hdwfNone:
        print "failed to open device"
    else:
        print "Generating custom waveform..."
        dwf.AnalogOutNodeEnableSet(hdwf, channel, dwf.AnalogOutNodeCarrier, True)
        dwf.AnalogOutNodeFunctionSet(hdwf, channel, dwf.AnalogOutNodeCarrier, dwf.funcCustom) 
        dwf.AnalogOutNodeDataSet(hdwf, channel, dwf.AnalogOutNodeCarrier, rgdSamples)
        dwf.AnalogOutNodeFrequencySet(hdwf, channel, dwf.AnalogOutNodeCarrier, 10000.0) 
        dwf.AnalogOutNodeAmplitudeSet(hdwf, channel, dwf.AnalogOutNodeCarrier, 2) 
        dwf.AnalogOutConfigure(hdwf, channel, True)
        print "Playing waveform for 10 seconds..."
        time.sleep(10)
        print "done."
        dwf.DeviceCloseAll() 
示例#6
0
def DigitalIn_Acquisition():
    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: " + 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..."

    # generate on DIO-0 1Mhz pulse (100MHz/25/(3+1)), 25% duty (3low 1high)
    #dwf.DigitalOutEnableSet(hdwf, c_int(i), 1)
    #dwf.DigitalOutDividerSet(hdwf, c_int(i), 25)
    #dwf.DigitalOutCounterSet(hdwf, c_int(i), 3, 1)

    # generate counter
    for i in range(0, 15):
        dwf.DigitalOutEnableSet(hdwf, i, 1)
        dwf.DigitalOutDividerSet(hdwf, i, (1 << i))
        dwf.DigitalOutCounterSet(hdwf, i, 1, 1)

    dwf.DigitalOutConfigure(hdwf, 1)

    #sample rate = system frequency / divider, 100MHz/1
    dwf.DigitalInDividerSet(hdwf, 1)
    # 16bit per sample format
    dwf.DigitalInSampleFormatSet(hdwf, 16)
    # set number of sample to acquire
    cSamples = 1000
    rgwSamples = np.zeros(cSamples, dtype=np.uint16)
    dwf.DigitalInBufferSizeSet(hdwf, cSamples)

    # begin acquisition
    dwf.DigitalInConfigure(hdwf, False, True)
    print "   waiting to finish"

    while True:
        sts = dwf.DigitalInStatus(hdwf, 1)
        print "STS VAL: " + str(sts)
        if sts == dwf.stsDone:
            break
        time.sleep(1)
    print "Acquisition finished"

    # get samples, byte size
    dwf.DigitalInStatusData(hdwf, rgwSamples)
    dwf.DeviceCloseAll()

    plt.plot(rgwSamples)
    plt.show()
示例#7
0
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 AnalogIO_AnalogDiscovery_Power():
    #print DWF version
    version = dwf.GetVersion()
    print "DWF Version: " + 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 analog IO channel node
        dwf.AnalogIOChannelNodeSet(hdwf, 0, 0, 1)
        # enable negative supply
        dwf.AnalogIOChannelNodeSet(hdwf, 1, 0, 1)
        # master enable
        dwf.AnalogIOEnableSet(hdwf, True)

        for i in range(1, 60):
            #wait 1 second between readings
            time.sleep(1)
            #fetch analogIO status from device
            sts = dwf.AnalogIOStatus(hdwf)

            #supply monitor
            supplyVoltage = dwf.AnalogIOChannelNodeStatus(hdwf, 3, 0)
            supplyCurrent = dwf.AnalogIOChannelNodeStatus(hdwf, 3, 1)
            supplyPower = supplyVoltage * supplyCurrent
            print "Total supply power: " + str(supplyPower) + "W"

            supplyLoadPercentage = 100 * (supplyCurrent / 0.2)
            print "Load: " + str(supplyLoadPercentage) + "%"

            # in case of overcurrent condition the supplies are disabled
            IsEnabled = dwf.AnalogIOEnableStatus(hdwf)
            if not IsEnabled:
                #re-enable supplies
                dwf.AnalogIOEnableSet(hdwf, False)
                dwf.AnalogIOEnableSet(hdwf, True)

        #close the device
        dwf.DeviceCloseAll()
示例#9
0
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()
示例#10
0
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()
示例#11
0
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()