Jump to content
  • 0

Waveforms SDK Reecord with tirrger example code


HJ Son

Question

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

test image.JPG

Form1.cs

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Thank you very much for your kind answer.
Trigger record seems to work fine.
The slightly modified source code and project files are attached below.

https://drive.google.com/file/d/1s2U49mt-7Zw9euQcCVgq-0CeeMuLfSuA/view?usp=share_link

Last more 1 questions :
I set the sampling rate to 100Mhz, but the pulse start position is different. Do you know why?
Should I modify my trigger settings?

 

// 100MHz sample rate
  Dwf.AnalogInFrequencySet(hdwf, 100000000.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.AnalogInTriggerHysteresisSet(hdwf, 0.005);
Dwf.AnalogInTriggerConditionSet(hdwf, TRIGCOND.RisingPositive);

 

 

4.thumb.JPG.2b573c812b72f02aca3be436cd21aa8b.JPG3.thumb.JPG.cbd4a9858615d3a422251b21b5b08017.JPG2.thumb.JPG.e879165a4b8a73c46945633e8b158d4c.JPG1.thumb.JPG.619d3e7139ce6e9dc332042a07377cee.JPGIMG_0136.thumb.jpeg.84795753bd5e8945a7206416d677310b.jpeg

 

 

 

Form1.cs

Edited by HJ Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...