예제 #1
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);
     }
 }
예제 #2
0
        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);
            }
        }