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); } }
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); } }
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); } }