protected virtual void OnWaveformTransition(WaveformEventArgs e)
 {
     if (WaveformTransition != null)
     {
         WaveformTransition(this, e);
     }
 }
 public DigitalWaveformGenerator(string line, bool periodic)
 {
     periodicWaveform             = periodic;
     waveform                     = new WaveformState[2];
     waveform[0]                  = new WaveformState();
     waveform[0].state            = true;
     waveform[0].durationMilliSec = onDuration;
     waveform[1]                  = new WaveformState();
     waveform[1].state            = false;
     waveform[1].durationMilliSec = offDuration;
     transitionevent              = new WaveformEventArgs();
     lastStateIdx                 = 0;
     digitalLine                  = line;
     try
     {
         DAQTask = new Task();
         DOChannel outputChannel = DAQTask.DOChannels.CreateChannel(digitalLine, "waveform", ChannelLineGrouping.OneChannelForAllLines);
         outputChannel.OutputDriveType = DOOutputDriveType.ActiveDrive;
         DAQTask.Start();
         writer = new DigitalSingleChannelWriter(DAQTask.Stream);
     }
     catch (DaqException ex)
     {
         MessageBox.Show(ex.Message);
         if (DAQTask != null)
         {
             DAQTask.Dispose();
             DAQTask = null;
         }
     }
 }
Esempio n. 3
0
        private void SampleAggregator_WaveformCalculated(object sender, WaveformEventArgs e)
        {
            SeriesCollection[0].Values.Clear();
            SeriesCollection[0].Values.AddRange(e.PulseCodeModulation.Cast <Object>());

            SeriesCollection2[0].Values.Clear();
            SeriesCollection2[0].Values.AddRange(e.FastFourierTransform.Cast <Object>());

            RaisePropertyChanged("SeriesCollection");
            RaisePropertyChanged("SeriesCollection2");
        }
Esempio n. 4
0
        private void ResumeGenerating()
        {
            bool signalLevel = GetSignalLevel(waveform[lastStateIdx].state);

            if (!periodicWaveform)
            {
                if (rnd == null)
                {
                    rnd = new Random();
                }
                if (signalLevel == true)
                {
                    waveform[lastStateIdx].durationMicroSec = rnd.Next(onMinDuration, onMaxDuration);
                }
                else
                {
                    waveform[lastStateIdx].durationMicroSec = rnd.Next(offMinDuration, offMaxDuration);
                }
            }

            WaveformEventArgs transitionevent;

            if (signalLevel == true)
            {
                activeTransitionCounter++;
                transitionevent = new WaveformEventArgs(DigitalLineTransition.ToHigh);
            }
            else
            {
                transitionevent = new WaveformEventArgs(DigitalLineTransition.ToLow);
            }
            OnWaveformTransition(transitionevent);

            if (waveformType == WaveformType.DigitalIO)
            {
                try
                {
                    writer.BeginWriteSingleSampleSingleLine(true, signalLevel, new AsyncCallback(OnDataWritten), DAQTask);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (waveformType == WaveformType.TCP)
            {
                tcpClientGeneratorThread.Start();
                running = true;
            }
            startCounter++;
        }
Esempio n. 5
0
 public Digital_WaveformGenerator(WaveformType type, IPAddress deviceAddress, string line, bool periodic)
 {
     waveformType                 = type;
     periodicWaveform             = periodic;
     waveform                     = new SignalState[2];
     waveform[0]                  = new SignalState();
     waveform[0].state            = true;
     waveform[0].durationMicroSec = onDuration;
     waveform[1]                  = new SignalState();
     waveform[1].state            = false;
     waveform[1].durationMicroSec = offDuration;
     transitionevent              = new WaveformEventArgs();
     stateevent                   = new WaveformEventArgs();
     lastStateIdx                 = 0;
     digitalLine                  = line;
     activeTransitionCounter      = 0;
     startCounter                 = 0;
     if (waveformType == WaveformType.DigitalIO)
     {
         try
         {
             DAQTask = new Task();
             DOChannel outputChannel = DAQTask.DOChannels.CreateChannel(digitalLine, "waveform", ChannelLineGrouping.OneChannelForAllLines);
             //outputChannel.OutputDriveType = DOOutputDriveType.ActiveDrive;
             DAQTask.Start();
             writer = new DigitalSingleChannelWriter(DAQTask.Stream);
         }
         catch (DaqException ex)
         {
             MessageBox.Show(ex.Message);
             if (DAQTask != null)
             {
                 DAQTask.Dispose();
                 DAQTask = null;
             }
         }
     }
     if (waveformType == WaveformType.TCP)
     {
         Int32 hostport;
         Int32.TryParse(line, out hostport);
         tcpClientGenerator       = new ClientConnection(deviceAddress.ToString(), hostport);
         tcpClientGeneratorThread = new Thread(new ThreadStart(DoTCPConnection));
     }
     if (waveformType == WaveformType.Serial)
     {
     }
 }
Esempio n. 6
0
        private bool prepareNextTransition()
        {
            lastStateIdx = (++lastStateIdx) % waveform.Length;

            bool signalLevel = GetSignalLevel(waveform[lastStateIdx].state);

            if (!periodicWaveform)
            {
                if (rnd == null)
                {
                    rnd = new Random();
                }
                if (signalLevel == true)
                {
                    waveform[lastStateIdx].durationMicroSec = rnd.Next(onMinDuration, onMaxDuration);
                }
                else
                {
                    waveform[lastStateIdx].durationMicroSec = rnd.Next(offMinDuration, offMaxDuration);
                }
            }

            WaveformEventArgs transitionevent;

            if (signalLevel == true)
            {
                activeTransitionCounter++;
                transitionevent = new WaveformEventArgs(DigitalLineTransition.ToHigh);
            }
            else
            {
                transitionevent = new WaveformEventArgs(DigitalLineTransition.ToLow);
            }
            OnWaveformTransition(transitionevent);

            return(signalLevel);
        }
Esempio n. 7
0
 protected virtual void OnWaveformTransition(WaveformEventArgs e)
 {
     WaveformTransition?.Invoke(this, e);
 }
Esempio n. 8
0
 protected virtual void OnWaveformStateChange(WaveformEventArgs e)
 {
     WaveformStateChange?.Invoke(this, e);
 }
        private void OnDataWritten(IAsyncResult result)
        {
            if (DAQTask != null && DAQTask == result.AsyncState)
            {
                writer.EndWrite(result);

                if (!running && GetSignalLevel(waveform[lastStateIdx].state) == false)
                {
                    stopped = true;
                    return;
                }

                System.Threading.Thread.Sleep(waveform[lastStateIdx].durationMilliSec);

                //if (running || GetSignalLevel(waveform[lastStateIdx].state) == true)
                {
                    lastStateIdx = (++lastStateIdx) % waveform.Length;

                    bool signalLevel = GetSignalLevel(waveform[lastStateIdx].state);

                    if (!periodicWaveform)
                    {
                        if (rnd == null)
                        {
                            rnd = new Random();
                        }
                        if (signalLevel == true)
                        {
                            waveform[lastStateIdx].durationMilliSec = rnd.Next(onMinDuration, onMaxDuration);
                        }
                        else
                        {
                            waveform[lastStateIdx].durationMilliSec = rnd.Next(offMinDuration, offMaxDuration);
                        }
                    }

                    WaveformEventArgs transitionevent;
                    if (signalLevel == true)
                    {
                        transitionevent = new WaveformEventArgs(DigitalLineTransition.ToHigh);
                    }
                    else
                    {
                        transitionevent = new WaveformEventArgs(DigitalLineTransition.ToLow);
                    }
                    OnWaveformTransition(transitionevent);

                    try
                    {
                        writer.BeginWriteSingleSampleSingleLine(true, signalLevel, new AsyncCallback(OnDataWritten), DAQTask);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                //                 else
                //                 {
                //                     if (writer != null)
                //                         writer.EndWrite(result);
                //                 }
            }
        }
Esempio n. 10
0
 private static void SampleAggregator_WaveformCalculated(object sender, WaveformEventArgs e)
 {
 }