Example #1
0
        static void Main(string[] args)
        {
            try
            {
                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);
                // enable first channel FDwfAnalogInChannelEnableSet(hdwf, 0, true)
                // set 0V offset
                Dwf.AnalogInChannelOffsetSet(hdwf, 0, 0);
                // set 5V pk2pk input range, -2.5V to 2.5V
                Dwf.AnalogInChannelRangeSet(hdwf, 0, 5);
                // start signal generation
                Dwf.AnalogInConfigure(hdwf, false, false);
                // wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change
                Wait(2);

                for (int i = 0; i < 10; i++)
                {
                    Wait(1);
                    // fetch analog input information from the device
                    var state = Dwf.AnalogInStatus(hdwf, false);
                    // read voltage input of first channel
                    var voltage = Dwf.AnalogInStatusSample(hdwf, 0);
                    cout.WriteLine(voltage.ToString() + " V", voltage);
                }
                // close all opened devices by this process
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #2
0
 static void Main(string[] args)
 {
     try
     {
         // detect connected all supported devices
         var cDevice = Dwf.Enumerate(ENUMFILTER.All);
         // list information about each device
         cout.WriteLine("found " + cDevice.ToString() + " devices");
         for (int i = 0; i < cDevice; i++)
         {
             // we use 0 based indexing
             var szDeviceName = Dwf.EnumDeviceName(i);
             var szSN         = Dwf.EnumSN(i);
             cout.WriteLine("device: " + (i + 1).ToString() + " name: " + szDeviceName + " " + szSN);
             // before opening, check if the device isn’t already opened by other application, like: WaveForms
             var fIsInUse = Dwf.EnumDeviceIsOpened(i);
             if (!fIsInUse)
             {
                 var hdwf           = Dwf.DeviceOpen(i);
                 var cChannel       = Dwf.AnalogInChannelCount(hdwf);
                 var frequencyRange = Dwf.AnalogInFrequencyInfo(hdwf);
                 cout.WriteLine("number of analog input channels: " + cChannel.ToString() + " maximum freq.: " + frequencyRange.Max.ToString() + " Hz");
                 Dwf.DeviceClose(hdwf);
                 hdwf = -1;
             }
         }
         // before application exit make sure to close all opened devices by this process
         Dwf.DeviceCloseAll();
     }
     catch (Exception ex)
     {
         cout.WriteLine("Error: " + ex.Message);
     }
 }
Example #3
0
 static void Main(string[] args)
 {
     try
     {
         // open automatically the first available device
         var hdwf = Dwf.DeviceOpen(-1);
         // enable first channel
         Dwf.AnalogOutNodeEnableSet(hdwf, 0, ANALOGOUTNODE.Carrier, true);
         // set sine function
         Dwf.AnalogOutNodeFunctionSet(hdwf, 0, ANALOGOUTNODE.Carrier, FUNC.Sine);
         // 10kHz
         Dwf.AnalogOutNodeFrequencySet(hdwf, 0, ANALOGOUTNODE.Carrier, 10000.0);
         // 1.41V amplitude (1Vrms), 2.82V pk2pk
         Dwf.AnalogOutNodeAmplitudeSet(hdwf, 0, ANALOGOUTNODE.Carrier, 1.41);
         // 1.41V offset
         Dwf.AnalogOutNodeOffsetSet(hdwf, 0, ANALOGOUTNODE.Carrier, 1.41);
         // start signal generation
         Dwf.AnalogOutConfigure(hdwf, 0, true);
         // it will run until stopped, reset, parameter changed or device closed
         Wait(2);
         // on close device is stopped and configuration lost
         Dwf.DeviceClose(hdwf);
     }
     catch (Exception ex)
     {
         cout.WriteLine("Error: " + ex.Message);
     }
 }
Example #4
0
        static void Main(string[] args)
        {
            try
            {
                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);

                var hzSys = Dwf.DigitalOutInternalClockInfo(hdwf);

                for (int i = 0; i < 16; i++)
                {
                    Dwf.DigitalOutEnableSet(hdwf, i, true);
                    // increase by 2 the period of successive bits
                    Dwf.DigitalOutDividerSet(hdwf, i, 1u << i);
                    // 100kHz coutner rate, SystemFrequency/100kHz
                    Dwf.DigitalOutCounterSet(hdwf, i, (uint)(hzSys / 1e5), (uint)(hzSys / 1e5));
                }

                Dwf.DigitalOutConfigure(hdwf, true);

                // it will run until stopped, reset, parameter changed or device closed
                Wait(5);
                Dwf.DigitalOutReset(hdwf);

                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                cout.WriteLine("Open automatically the first available device");
                var hdwf = Dwf.DeviceOpen(-1);

                var hzSys = Dwf.DigitalInInternalClockInfo(hdwf);

                // sample rate to 1MHz
                Dwf.DigitalInDividerSet(hdwf, (uint)(hzSys / 1e6));

                // 16bit WORD format
                Dwf.DigitalInSampleFormatSet(hdwf, 16);

                // get the maximum buffer size
                var cSamples = Dwf.DigitalInBufferSizeInfo(hdwf);
                // default buffer size is set to maximum
                //Dwf.DigitalInBufferSizeSet(hdwf, cSamples);

                // set trigger position to the middle
                Dwf.DigitalInTriggerPositionSet(hdwf, (uint)(cSamples / 2));

                // trigger on any pin transition
                Dwf.DigitalInTriggerSourceSet(hdwf, TRIGSRC.DetectorDigitalIn);
                Dwf.DigitalInTriggerAutoTimeoutSet(hdwf, 10.0);
                Dwf.DigitalInTriggerSet(hdwf, 0, 0, 0xFFFF, 0xFFFF);

                // start
                Dwf.DigitalInConfigure(hdwf, false, true);

                cout.WriteLine("Waiting for triggered or auto acquisition");
                STATE sts;
                do
                {
                    sts = Dwf.DigitalInStatus(hdwf, true);
                } while (sts != STATE.Done);

                // get the samples
                var rgwSamples = Dwf.DigitalInStatusData(hdwf, cSamples);

                cout.WriteLine("done");

                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            try
            {
                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);

                //
                var hzSys = Dwf.DigitalOutInternalClockInfo(hdwf);

                // 1kHz pulse on IO pin 0
                Dwf.DigitalOutEnableSet(hdwf, 0, true);
                // prescaler to 2kHz, SystemFrequency/1kHz/2
                Dwf.DigitalOutDividerSet(hdwf, 0, (uint)(hzSys / 1e3 / 2));
                // 1 tick low, 1 tick high
                Dwf.DigitalOutCounterSet(hdwf, 0, 1, 1);

                // 1kHz 25% duty pulse on IO pin 1
                Dwf.DigitalOutEnableSet(hdwf, 1, true);
                // prescaler to 4kHz SystemFrequency/1kHz/2
                Dwf.DigitalOutDividerSet(hdwf, 1, (uint)(hzSys / 1e3 / 4));
                // 3 ticks low, 1 tick high
                Dwf.DigitalOutCounterSet(hdwf, 1, 3, 1);

                // 2kHz random on IO pin 2
                Dwf.DigitalOutEnableSet(hdwf, 2, true);
                Dwf.DigitalOutTypeSet(hdwf, 2, DIGITALOUTTYPE.Random);
                Dwf.DigitalOutDividerSet(hdwf, 2, (uint)(hzSys / 2e3));

                var rgcustom = new byte[] { 0x00, 0xAA, 0x66, 0xFF };
                // 1kHz custom on IO pin 3
                Dwf.DigitalOutEnableSet(hdwf, 3, true);
                Dwf.DigitalOutTypeSet(hdwf, 3, DIGITALOUTTYPE.Custom);
                Dwf.DigitalOutDividerSet(hdwf, 3, (uint)(hzSys / 2e3));
                Dwf.DigitalOutDataSet(hdwf, 3, rgcustom, 4 * 8);

                Dwf.DigitalOutConfigure(hdwf, true);

                // it will run until stopped, reset, parameter changed or device closed
                Wait(5);

                Dwf.DigitalOutReset(hdwf);
                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            try
            {
                var rgdSamples = new double[1024];
                int idxChannel = 0;

                // generate custom samples normalized to +-1
                for (int i = 0; i < 1024; i++)
                {
                    rgdSamples[i] = 2.0 * i / 1023 - 1;
                }

                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);
                // needed for EExplorer, don't care for ADiscovery
                Dwf.AnalogOutCustomAMFMEnableSet(hdwf, idxChannel, true);
                // enable first channel
                Dwf.AnalogOutNodeEnableSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, true);
                // set sine carrier
                Dwf.AnalogOutNodeFunctionSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, FUNC.Sine);
                // 1V amplitude, 2V pk2pk
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, 1.0);
                // 10kHz carrier frequency
                Dwf.AnalogOutNodeFrequencySet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, 1000.0);
                // enable amplitude modulation
                Dwf.AnalogOutNodeEnableSet(hdwf, idxChannel, ANALOGOUTNODE.AM, true);
                // set custom AM
                Dwf.AnalogOutNodeFunctionSet(hdwf, idxChannel, ANALOGOUTNODE.AM, FUNC.Custom);
                // +-100% modulation index, will result with 1V amplitude carrier, 0V to 2V
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, idxChannel, ANALOGOUTNODE.AM, 100);
                // 10Hz AM frequency
                Dwf.AnalogOutNodeFrequencySet(hdwf, idxChannel, ANALOGOUTNODE.AM, 10.0);
                // set custom waveform samples
                // normalized to ±1 values
                Dwf.AnalogOutNodeDataSet(hdwf, idxChannel, ANALOGOUTNODE.AM, rgdSamples);
                // by default the offset is 0V
                // start signal generation
                Dwf.AnalogOutConfigure(hdwf, idxChannel, true);
                // it will run until stopped or device closed
                Wait(5);
                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            try
            {
                int    idxChannel = 0;
                double hzStart    = 1e3;
                double hzStop     = 1e5;
                double secSweep   = 1;

                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);
                // enable first channel
                Dwf.AnalogOutNodeEnableSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, true);
                // set sine carrier
                Dwf.AnalogOutNodeFunctionSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, FUNC.Sine);
                // 1V amplitude, 2V pk2pk
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, 1.0);
                // 10kHz carrier frequency
                Dwf.AnalogOutNodeFrequencySet(hdwf, idxChannel, ANALOGOUTNODE.Carrier, (hzStart + hzStop) / 2);
                // enable frequency modulation
                Dwf.AnalogOutNodeEnableSet(hdwf, idxChannel, ANALOGOUTNODE.FM, true);
                // linear sweep with ramp up symmetry 100%
                Dwf.AnalogOutNodeFunctionSet(hdwf, idxChannel, ANALOGOUTNODE.FM, FUNC.RampUp);
                Dwf.AnalogOutNodeSymmetrySet(hdwf, idxChannel, ANALOGOUTNODE.FM, 100);
                // modulation index
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, idxChannel, ANALOGOUTNODE.FM, 100.0 * (hzStop - hzStart) / (hzStart + hzStop));
                // FM frequency = 1/sweep time
                Dwf.AnalogOutNodeFrequencySet(hdwf, idxChannel, ANALOGOUTNODE.FM, 1.0 / secSweep);

                // by default the offset is 0V
                // start signal generation
                Dwf.AnalogOutConfigure(hdwf, idxChannel, true);
                // it will run until stopped or device closed
                Wait(5);
                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                var rgdSamples = new double[4096];

                // generate custom samples normalized to +-1
                for (int i = 0; i < 4096; i++)
                {
                    rgdSamples[i] = 2.0 * i / 4095 - 1;
                }

                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);
                // enable first channel
                Dwf.AnalogOutNodeEnableSet(hdwf, 0, ANALOGOUTNODE.Carrier, true);
                // set custom function
                Dwf.AnalogOutNodeFunctionSet(hdwf, 0, ANALOGOUTNODE.Carrier, FUNC.Custom);
                // set custom waveform samples
                // normalized to ±1 values
                Dwf.AnalogOutNodeDataSet(hdwf, 0, ANALOGOUTNODE.Carrier, rgdSamples);
                // 10kHz waveform frequency
                Dwf.AnalogOutNodeFrequencySet(hdwf, 0, ANALOGOUTNODE.Carrier, 10000.0);
                // 2V amplitude, 4V pk2pk, for sample value -1 will output -2V, for 1 +2V
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, 0, ANALOGOUTNODE.Carrier, 2);
                // by default the offset is 0V
                // start signal generation
                Dwf.AnalogOutConfigure(hdwf, 0, true);
                // it will run until stopped or device closed
                Wait(5);
                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            try
            {
                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);
                // enable two channels
                Dwf.AnalogOutNodeEnableSet(hdwf, 0, ANALOGOUTNODE.Carrier, true);
                Dwf.AnalogOutNodeEnableSet(hdwf, 1, ANALOGOUTNODE.Carrier, true);
                // 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 parameters for master channel
                // when using different frequencies it might need periodical resynchronization
                // to do so set limited runtime and repeat infinite

                // configure enabled channels
                Dwf.AnalogOutNodeFunctionSet(hdwf, -1, ANALOGOUTNODE.Carrier, FUNC.Sine);
                Dwf.AnalogOutNodeFrequencySet(hdwf, -1, ANALOGOUTNODE.Carrier, 10000.0);
                Dwf.AnalogOutNodeAmplitudeSet(hdwf, -1, ANALOGOUTNODE.Carrier, 1.0);
                // set phase for second channel
                Dwf.AnalogOutNodePhaseSet(hdwf, 1, ANALOGOUTNODE.Carrier, 180.0);

                // slave channel will only be initialized
                Dwf.AnalogOutConfigure(hdwf, 1, true);
                // starting master will start slave channels too
                Dwf.AnalogOutConfigure(hdwf, 0, true);
                // it will run until stopped, reset, parameter changed or device closed
                Wait(10);
                // on close device is stopped and configuration lost
                Dwf.DeviceClose(hdwf);
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                // open automatically the first available device
                var hdwf = Dwf.DeviceOpen(-1);

                var hzSys = Dwf.DigitalOutInternalClockInfo(hdwf);

                // 10 bit walking 1
                for (int i = 0; i < 10; i++)
                {
                    Dwf.DigitalOutEnableSet(hdwf, i, true);
                    // divide system frequency down to 1khz
                    Dwf.DigitalOutDividerSet(hdwf, i, (uint)(hzSys / 1e3));
                    // all pins will be 9 ticks low and 1 high
                    Dwf.DigitalOutCounterSet(hdwf, i, 9, 1);
                    // first bit will start high others low with increasing phase
                    Dwf.DigitalOutCounterInitSet(hdwf, i, i == 0, (uint)i);
                }

                // start digital out
                Dwf.DigitalOutConfigure(hdwf, true);

                // it will run until stopped, reset, parameter changed or device closed
                Wait(5);
                Dwf.DigitalOutReset(hdwf);

                // on close device is stopped and configuration lost
                Dwf.DeviceCloseAll();
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                cout.WriteLine("Open automatically the first available device");
                var hdwf = Dwf.DeviceOpen(-1);

                // get the number of analog in channels
                var cChannel = Dwf.AnalogInChannelCount(hdwf);

                // enable channels
                for (int c = 0; c < cChannel; c++)
                {
                    Dwf.AnalogInChannelEnableSet(hdwf, c, true);
                }
                // set 5V pk2pk input range for all channels
                Dwf.AnalogInChannelRangeSet(hdwf, -1, 5);

                // 20MHz sample rate
                Dwf.AnalogInFrequencySet(hdwf, 20000000.0);

                // get the maximum buffer size
                var cSamples = Dwf.AnalogInBufferSizeInfo(hdwf).Max;
                Dwf.AnalogInBufferSizeSet(hdwf, cSamples);

                // configure trigger
                Dwf.AnalogInTriggerSourceSet(hdwf, TRIGSRC.DetectorAnalogIn);
                Dwf.AnalogInTriggerAutoTimeoutSet(hdwf, 10.0);
                Dwf.AnalogInTriggerChannelSet(hdwf, 0);
                Dwf.AnalogInTriggerTypeSet(hdwf, TRIGTYPE.Edge);
                Dwf.AnalogInTriggerLevelSet(hdwf, 1.0);
                Dwf.AnalogInTriggerConditionSet(hdwf, TRIGCOND.RisingPositive);

                // wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change
                Wait(2);

                // start
                Dwf.AnalogInConfigure(hdwf, false, true);

                cout.WriteLine("Waiting for triggered or auto acquisition");
                STATE sts;
                do
                {
                    sts = Dwf.AnalogInStatus(hdwf, true);
                } while (sts != STATE.Done);

                double[] rgdSamples = null;

                // get the samples for each channel
                for (int c = 0; c < cChannel; c++)
                {
                    rgdSamples = Dwf.AnalogInStatusData(hdwf, c, cSamples);
                    // do something with it
                }

                cout.WriteLine("done");

                // close the device
                Dwf.DeviceClose(hdwf);
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            try
            {
                const int nSamples   = 100000;
                double[]  rgdSamples = new double[nSamples];
                int       cSamples   = 0;
                bool      fLost      = false;
                bool      fCorrupted = false;

                cout.WriteLine("Open automatically the first available device\n");
                var hdwf = Dwf.DeviceOpen(-1);

                Dwf.AnalogInChannelEnableSet(hdwf, 0, true);

                Dwf.AnalogInChannelRangeSet(hdwf, 0, 5);

                // recording rate for more samples than the device buffer is limited by device communication
                Dwf.AnalogInAcquisitionModeSet(hdwf, ACQMODE.Record);
                Dwf.AnalogInFrequencySet(hdwf, 50000.0);

                // make sure we calculate record length with the real frequency
                var hzAcq = Dwf.AnalogInFrequencyGet(hdwf);
                Dwf.AnalogInRecordLengthSet(hdwf, 1.0 * nSamples / hzAcq);

                // wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change
                Wait(2);

                // start
                Dwf.AnalogInConfigure(hdwf, false, true);

                cout.WriteLine("Recording...");
                while (cSamples < nSamples)
                {
                    var sts = Dwf.AnalogInStatus(hdwf, true);
                    if (cSamples == 0 && (sts == STATE.Config || sts == STATE.Prefill || sts == STATE.Armed))
                    {
                        // Acquisition not yet started.
                        continue;
                    }

                    var stats = Dwf.AnalogInStatusRecord(hdwf);

                    cSamples += stats.Lost;

                    if (stats.Lost > 0)
                    {
                        fLost = true;
                    }
                    if (stats.Corrupt > 0)
                    {
                        fCorrupted = false;
                    }

                    if (stats.Available > 0)
                    {
                        var remaining = nSamples - cSamples;
                        var todo      = Math.Min(remaining, stats.Available);
                        // get samples
                        Dwf.AnalogInStatusData(hdwf, 0, rgdSamples, cSamples, todo);
                        cSamples += stats.Available;
                    }
                }

                cout.WriteLine("done");

                if (fLost)
                {
                    cout.WriteLine("Samples were lost! Reduce frequency");
                }
                else if (fCorrupted)
                {
                    cout.WriteLine("Samples could be corrupted! Reduce frequency");
                }

                // close the device
                Dwf.DeviceClose(hdwf);
            }
            catch (Exception ex)
            {
                cout.WriteLine("Error: " + ex.Message);
            }
        }