public Device GetDevice(DeviceType deviceType, int deviceId) { DeviceMgr mgr = GetDeviceMgr(deviceType); if (mgr == null) { return(null); } return(mgr.GetDevice(deviceId)); }
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; } }
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; } }
private void btn_init_Click(object sender, System.EventArgs e) { string keyvalue = ConfigurationManager.AppSettings["keyname"].ToString(); int numberOfBuffers = Convert.ToInt32(ConfigurationManager.AppSettings["NumberOfbuffers"]); string clockFreq = ConfigurationManager.AppSettings["clockFreq"].ToString(); string sensor0gain = ConfigurationManager.AppSettings["sensor0gain"].ToString(); string sensor1gain = ConfigurationManager.AppSettings["sensor1gain"].ToString(); string sensor0offset = ConfigurationManager.AppSettings["sensor0offset"].ToString(); string sensor1offset = ConfigurationManager.AppSettings["sensor1offset"].ToString(); string samplesPerBuffer = ConfigurationManager.AppSettings["samplesPerBuffer"]; statusBarPanel.Text = "No Error"; string deviceName = (string)deviceComboBox.SelectedItem; try { serialPort.PortName = "COM1"; serialPort.BaudRate = 9600; serialPort.DataBits = 8; serialPort.Parity = Parity.None; serialPort.StopBits = StopBits.One; serialPort.Open(); } catch (Exception ex) { MessageBox.Show("Port je vec otvoren" + ex.ToString()); } try { // Create the device object device = deviceMgr.GetDevice(deviceName); // Create the device's analog input subsystem wiht element zero ainSS = device.AnalogInputSubsystem(0); // Create an event handler delegate to handle driver runtime error events ainSS.DriverRunTimeErrorEvent += new DriverRunTimeErrorEventHandler(HandleDriverRunTimeErrorEvent); // Create an event handler delegate to handle buffer done events ainSS.BufferDoneEvent += new BufferDoneHandler(HandleBufferDone); // Create an event handler delegate to handle queue done events ainSS.QueueDoneEvent += new QueueDoneHandler(HandleQueueDone); // Create and event handler delegate to handle queue stopped events ainSS.QueueStoppedEvent += new QueueStoppedHandler(HandleQueueStopped); } catch (OlException ex) { string err = ex.Message; statusBarPanel.Text = err; return; } if (device == null) { MessageBox.Show("No Device Selected.", "Error"); return; } try { // int numberOfBuffers = Convert.ToInt32(6); // Free all previously allocated buffers in case we are updating the number // or the size of buffers ainSS.BufferQueue.FreeAllQueuedBuffers(); daqBuffers = new OlBuffer[Convert.ToInt32(numberOfBuffers)]; // Create the buffers to store the raw data // Place the buffers onto the queue of analog input subsystem for (int i = 0; i < numberOfBuffers; ++i) { daqBuffers[i] = new OlBuffer(int.Parse(samplesPerBuffer), ainSS); ainSS.BufferQueue.QueueBuffer(daqBuffers[i]); } // Set the data flow to continuous to setup for buffered I/O ainSS.DataFlow = DataFlow.Continuous; // Update the Clock object with the frequency ainSS.Clock.Frequency = float.Parse(clockFreq); // Clear the analog input subsystem channel list ainSS.ChannelList.Clear(); int physicalChannelNumber = Convert.ToInt32(0); // Create a channel object and add it to the channel list of the // analog input subsystem SupportedChannelInfo channelInfo = ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, 0); SupportedChannelInfo channelInfo1 = ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, 1); // Set the channel sensor parameters channelInfo.SensorGain = Convert.ToDouble(sensor0gain); channelInfo.SensorOffset = Convert.ToDouble(sensor0offset); channelInfo1.SensorGain = Convert.ToDouble(sensor1gain); channelInfo1.SensorOffset = Convert.ToDouble(sensor1offset); ChannelListEntry channelToRead = new ChannelListEntry(channelInfo); ChannelListEntry channelToRead1 = new ChannelListEntry(channelInfo1); // Add the channel object to the channel list ainSS.ChannelList.Add(channelToRead); ainSS.ChannelList.Add(channelToRead1); // Configure the subsystem to apply all the previous settings to the hardware ainSS.Config(); // Check the closest clock frequency set by the hardware clockFreq = String.Format("{0:0.000}", ainSS.Clock.Frequency); btn_start.Enabled = true; } catch (OlException ex) { string err = ex.Message; statusBarPanel.Text = err; return; } }