I am using c# and I want to add CH1 trigger in analogin_record example.
I tried the source code below, but it doesn't seem working CH1 trigger.
Can I get the example source code that becomes a record when a trigger input is received?
I have attached the project source code.
https://drive.google.com/file/d/1Bbjg7fEu4K6su_-XfZq2uIJP6SbVPnkg/view?usp=share_link
Thank you!!
try
{
int cSamples = 0;
bool fLost = false;
bool fCorrupted = false;
textBox1.AppendText("Open automatically the first available device\n" + Environment.NewLine);
var hdwf = Dwf.DeviceOpen(-1);
// get the number of analog in channels
var cChannel = Dwf.AnalogInChannelCount(hdwf);
textBox1.AppendText("Analog IN Channels : " + cChannel + Environment.NewLine);
// enable CH 1 Channel
Dwf.AnalogInChannelEnableSet(hdwf, 0, true);
// set 5V pk2pk input range for all channels
Dwf.AnalogInChannelRangeSet(hdwf, 0, 5);
// recording rate for more samples than the device buffer is limited by device communication
Dwf.AnalogInAcquisitionModeSet(hdwf, ACQMODE.Record);
// 50KHz sample rate
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);
// 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);
textBox1.AppendText("Waiting for triggered or auto acquisition" + Environment.NewLine);
STATE status;
do
{
status = Dwf.AnalogInStatus(hdwf, true);
} while (status != STATE.Done);
textBox1.AppendText("Recording..." + Environment.NewLine);
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, CH1_ADC_DATA, cSamples, todo);
cSamples += stats.Available;
}
}
textBox1.AppendText("done" + Environment.NewLine);
textBox1.AppendText("DATA Length : " + CH1_ADC_DATA.Length + Environment.NewLine);
FUNCTION_ADC_DATA_DISPLAY();
if (fLost)
{
textBox1.AppendText("Samples were lost! Reduce frequency" + Environment.NewLine);
}
else if (fCorrupted)
{
textBox1.AppendText("Samples could be corrupted! Reduce frequency" + Environment.NewLine);
}
// close the device
Dwf.DeviceClose(hdwf);
}
catch (Exception ex)
{
textBox1.AppendText("Error: " + ex.Message + Environment.NewLine);
}
Form1.cs