예제 #1
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()
예제 #2
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()
예제 #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_Sine():
    channel = 0

    #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 "Generating sine wave..."
        dwf.AnalogOutNodeEnableSet(hdwf, channel, dwf.AnalogOutNodeCarrier,
                                   True)
        dwf.AnalogOutNodeFunctionSet(hdwf, channel, dwf.AnalogOutNodeCarrier,
                                     dwf.funcSine)
        dwf.AnalogOutNodeFrequencySet(hdwf, channel, dwf.AnalogOutNodeCarrier,
                                      10000)
        dwf.AnalogOutNodeAmplitudeSet(hdwf, channel, dwf.AnalogOutNodeCarrier,
                                      1.41)
        dwf.AnalogOutNodeOffsetSet(hdwf, channel, dwf.AnalogOutNodeCarrier,
                                   1.41)
        print "Play sine wave for 10 seconds..."
        dwf.AnalogOutConfigure(hdwf, channel, True)
        time.sleep(10)
        print "done."
        dwf.DeviceClose(hdwf)
예제 #6
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() 
예제 #7
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()
예제 #8
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()
예제 #9
0
def main():
    sel = 0x0010
    a = dwf.Enum(dwf.enumfilterAll)
    print(a)
    a = dwf.EnumDeviceType(0)
    print(a)
    a = dwf.EnumDeviceIsOpened(0)
    print(a)
    fd = dwf.DeviceOpen(0)
    print(fd)
    if sel & 0x0001:
        a = dwf.EnumDeviceIsOpened(0)
        print(a)
        a = dwf.EnumUserName(0)
        print(a)
        a = dwf.EnumSN(0)
        print(a)
        a = dwf.GetVersion()
        print(a)
        a = dwf.EnumDeviceName(0)
        print(a)
        a = dwf.GetLastErrorMsg()
        print(a)
    if sel & 0x0002:
        generateSinus(fd, 0, 12346, 1.41, sqrt(2))
        data = AcquireAnalog(fd, 1000, 1000E3)
        plt.plot(data)
        print(np.mean(data), np.std(data))
        plt.show()

        generateSinus(fd, 1, 12346, 1.00, sqrt(2))
        data = AcquireAnalog(fd, 1000, 1000E3, 1)
        plt.plot(data)
        print(np.mean(data), np.std(data))
        plt.show()

    if sel & 0x0004:
        generateDigitalPattern8(fd, [0, 1, 2, 3, 4, 5, 6, 7], 1E3)

        data = AcquireDigital(fd, 1024)
        print(data, len(data))

    if sel & 0x0008:
        DigitalIO(fd)

    if sel & 0x0010:
        SysMon(fd, 10)

    dwf.DeviceClose(fd)
예제 #10
0
def openDevice():

    #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..."

    return hdwf
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()
예제 #12
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()
예제 #13
0
def AnalogOut_Sync():
    
    #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 "Generating sine wave..."
        # enable two channels
        dwf.AnalogOutNodeEnableSet(hdwf, 0, dwf.AnalogOutNodeCarrier, 1)
        dwf.AnalogOutNodeEnableSet(hdwf, 1, dwf.AnalogOutNodeCarrier, 1)
        # for second channel set master the first channel
        dwf.AnalogOutMasterSet(hdwf, 1, 0);
        # slave channel is controlled by the master channel
        # it is enough to set trigger, wait, run and repeat paramters for master channel
        
        # configure enabled channels
        dwf.AnalogOutNodeFunctionSet(hdwf, -1, dwf.AnalogOutNodeCarrier, dwf.funcSine)
        dwf.AnalogOutNodeFrequencySet(hdwf, -1, dwf.AnalogOutNodeCarrier, 1000.0)
        dwf.AnalogOutNodeAmplitudeSet(hdwf, -1, dwf.AnalogOutNodeCarrier, 1.0)
    
        #set phase for second channel
        dwf.AnalogOutNodePhaseSet(hdwf, 1, dwf.AnalogOutNodeCarrier, 180.0)
    
        print "Play sine wave for 10 seconds..."
        # start signal generation, 
        # the second, slave channel will start too
        dwf.AnalogOutConfigure(hdwf, 0, True)
        
        time.sleep(10)
        
        print "done."
        dwf.DeviceClose(hdwf)
예제 #14
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()