public DTControl(double frequency, int[] analogChannels, Logger log, DoneSignalHandler callback)
    {
      try
      {
        m_deviceMgr = DeviceMgr.Get();

        if (!m_deviceMgr.HardwareAvailable())
          throw new Exception("No Devices Available.");

        // Get first available device
        m_device = m_deviceMgr.GetDevice(m_deviceMgr.GetDeviceNames()[0]);

        // Get subsystems
        m_ainSS = m_device.AnalogInputSubsystem(0);
        m_dinSS = m_device.DigitalInputSubsystem(0);
        m_doutSS = m_device.DigitalOutputSubsystem(0);

        /*
         * ANALOG SETUP
         */

        //Add event handlers
        m_ainSS.DriverRunTimeErrorEvent += HandleDriverRunTimeErrorEvent;
        m_ainSS.BufferDoneEvent += HandleBufferDone;
        m_ainSS.QueueDoneEvent += HandleQueueDone;
        m_ainSS.QueueStoppedEvent += HandleQueueStopped;

        // Set frequency
        m_frequency = (m_ainSS.Clock.MaxFrequency < frequency) ? m_ainSS.Clock.MaxFrequency : frequency;
        m_ainSS.Clock.Frequency = m_frequency;
        m_ainSS.VoltageRange = new Range(-10, 10);

        // Setup buffers
        m_ainSS.BufferQueue.FreeAllQueuedBuffers(); //just in case some are in the queue
        m_daqBuffers = new OlBuffer[MaxBuffers];
        for (int i = 0; i < MaxBuffers; i++)
        {
          // Allocate and place each buffer in queue
          m_daqBuffers[i] = new OlBuffer(SampleSize, m_ainSS);
          m_ainSS.BufferQueue.QueueBuffer(m_daqBuffers[i]);
        }

        // Set for continuous operation
        m_ainSS.DataFlow = DataFlow.Continuous;

        // Set channel list
        m_ainSS.ChannelList.Clear();
        m_physicalChannels = new List<int>();
        foreach (int channel in analogChannels)
        {
          ChannelListEntry channelListEntry = new ChannelListEntry(m_ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, channel));
          channelListEntry.Gain = 1.0;
          m_ainSS.ChannelList.Add(channelListEntry);
          m_physicalChannels.Add(channel);
        }

        // Save configuration
        m_ainSS.Config();

        /*
         * DIGITAL SETUP
         */
        m_dinSS.DataFlow = DataFlow.SingleValue;
        m_doutSS.DataFlow = DataFlow.SingleValue;

        m_dinSS.Config();
        m_doutSS.Config();

        doneSignalHandler += callback;

        Log = log;

        Log("DT9816 and all subsystems initialized.");

        // Display actual hardware frequency set
        Log(String.Format("Actual Hardware Frequency = {0:0.000}", m_ainSS.Clock.Frequency));
      }
      catch (Exception ex)
      {
        throw ex;
      }
    }
Beispiel #2
0
        public DTControl(double frequency, int[] analogChannels, Logger log, DoneSignalHandler callback)
        {
            try
            {
                m_deviceMgr = DeviceMgr.Get();

                if (!m_deviceMgr.HardwareAvailable())
                {
                    throw new Exception("No Devices Available.");
                }

                // Get first available device
                m_device = m_deviceMgr.GetDevice(m_deviceMgr.GetDeviceNames()[0]);

                // Get subsystems
                m_ainSS  = m_device.AnalogInputSubsystem(0);
                m_dinSS  = m_device.DigitalInputSubsystem(0);
                m_doutSS = m_device.DigitalOutputSubsystem(0);

                /*
                 * ANALOG SETUP
                 */

                //Add event handlers
                m_ainSS.DriverRunTimeErrorEvent += HandleDriverRunTimeErrorEvent;
                m_ainSS.BufferDoneEvent         += HandleBufferDone;
                m_ainSS.QueueDoneEvent          += HandleQueueDone;
                m_ainSS.QueueStoppedEvent       += HandleQueueStopped;

                // Set frequency
                m_frequency             = (m_ainSS.Clock.MaxFrequency < frequency) ? m_ainSS.Clock.MaxFrequency : frequency;
                m_ainSS.Clock.Frequency = m_frequency;
                m_ainSS.VoltageRange    = new Range(-10, 10);

                // Setup buffers
                m_ainSS.BufferQueue.FreeAllQueuedBuffers(); //just in case some are in the queue
                m_daqBuffers = new OlBuffer[MaxBuffers];
                for (int i = 0; i < MaxBuffers; i++)
                {
                    // Allocate and place each buffer in queue
                    m_daqBuffers[i] = new OlBuffer(SampleSize, m_ainSS);
                    m_ainSS.BufferQueue.QueueBuffer(m_daqBuffers[i]);
                }

                // Set for continuous operation
                m_ainSS.DataFlow = DataFlow.Continuous;

                // Set channel list
                m_ainSS.ChannelList.Clear();
                m_physicalChannels = new List <int>();
                foreach (int channel in analogChannels)
                {
                    ChannelListEntry channelListEntry = new ChannelListEntry(m_ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, channel));
                    channelListEntry.Gain = 1.0;
                    m_ainSS.ChannelList.Add(channelListEntry);
                    m_physicalChannels.Add(channel);
                }

                // Save configuration
                m_ainSS.Config();

                /*
                 * DIGITAL SETUP
                 */
                m_dinSS.DataFlow  = DataFlow.SingleValue;
                m_doutSS.DataFlow = DataFlow.SingleValue;

                m_dinSS.Config();
                m_doutSS.Config();

                doneSignalHandler += callback;

                Log = log;

                Log("DT9816 and all subsystems initialized.");

                // Display actual hardware frequency set
                Log(String.Format("Actual Hardware Frequency = {0:0.000}", m_ainSS.Clock.Frequency));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }