//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public Usb2001TcAi(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 1) { // default is scale data... m_scaleData = true; // create thermocouple types... m_tcTypes = new ThermocoupleTypes[m_maxChannels]; m_thermocouples = new Thermocouple[m_maxChannels]; // create an array for CJC values m_cjcValues = new double[m_maxChannels]; // create an array of channel types... m_aiChannelType[0] = AiChannelTypes.Temperature; // get the tc type... m_tcTypes[0] = GetTcType(0); if (m_tcTypes[0] != ThermocoupleTypes.NotSet) { // create the thermocouple object... m_thermocouples[0] = Thermocouple.CreateThermocouple(m_tcTypes[0]); } }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal AiComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_calibrateData = true; m_aiQueueList.Clear(); m_rateCalculatorDecrementCount = 1; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal Usb7204Ai(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 8) { m_previousChMode = PropertyValues.DIFF; m_adjustScanRateForChannelCount = true; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public DioComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { // dimension arrays here initialize them in Initialize() m_portWidths = new int[m_maxChannels]; m_configMasks = new int[m_maxChannels]; m_outputValues = new int[m_maxChannels]; }
//=================================================================================================== /// <summary> /// ctor /// </summary> /// <param name="daqDevice">A reference to the DaqDevice object that creates this component</param> /// <param name="deviceInfo">A referemce tp the DeviceInfo object that the Driver Interace uses</param> //=================================================================================================== public VirtualSSEventCounter(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_lastCount = new uint[maxChannels]; m_isCounting = new bool[maxChannels]; for (int i = 0; i < maxChannels; i++) { m_lastCount[i] = 0; m_isCounting[i] = false; } }
internal DaqException(DaqDevice device, string errorMessage, ErrorCodes errorCode, ErrorLevel level, DaqResponse lastResponse) : base(errorMessage) { m_errorCode = errorCode; m_level = level; m_lastResponse = lastResponse; m_inputScanStatus = device.DriverInterface.InputScanStatus.ToString(); m_inputScanCount = device.DriverInterface.InputScanCount; m_inputScanIndex = device.DriverInterface.InputScanIndex; m_outputScanStatus = device.DriverInterface.OutputScanState.ToString(); m_outputScanCount = device.DriverInterface.OutputScanCount; m_outputScanIndex = device.DriverInterface.OutputScanIndex; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal Usb1608GAi(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 16) { // create channel mappings m_channelMappings.Add(0, 8); m_channelMappings.Add(1, 9); m_channelMappings.Add(2, 10); m_channelMappings.Add(3, 11); m_channelMappings.Add(4, 12); m_channelMappings.Add(5, 13); m_channelMappings.Add(6, 14); m_channelMappings.Add(7, 15); }
//======================================================================================================== /// <summary> /// ctor - for use with setting up a callback for an input scan /// </summary> /// <param name="daqDevice">A DaqDevice object</param> /// <param name="numberOfSamples">The number of samples to pass to each callback </param> /// <param name="callback">A InputScanCallbackDelegate</param> //======================================================================================================== internal CallbackControl(DaqDevice daqDevice, InputScanCallbackDelegate callback, CallbackType type, object callbackData) { InitializeComponent(); m_daqDevice = daqDevice; if (type == CallbackType.OnDataAvailable) { try { m_numberOfSamples = (int)callbackData; } catch (Exception) { System.Diagnostics.Debug.Assert(false, "OnDataAvailable callback data is not the correct data type"); } } m_callback = callback; m_type = type; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal Usb2408xAi(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 16) { // default is scale data... m_scaleData = true; // create thermocouple types... m_tcTypes = new ThermocoupleTypes[m_maxChannels / 2]; m_thermocouples = new Thermocouple[m_maxChannels / 2]; // create an array for CJC values m_cjcValues = new double[m_maxChannels / 2]; // create channel types... for (int i = 0; i < m_maxChannels; i++) { m_aiChannelType[i] = GetChannelType(i); } // create thermocouple objects... for (int i = 0; i < (m_maxChannels / 2); i++) { m_tcTypes[i] = GetTcType(i); if (m_tcTypes[i] != ThermocoupleTypes.NotSet) { m_thermocouples[i] = Thermocouple.CreateThermocouple(m_tcTypes[i]); } } // create channel mappings m_channelMappings.Add(0, 8); m_channelMappings.Add(1, 9); m_channelMappings.Add(2, 10); m_channelMappings.Add(3, 11); m_channelMappings.Add(4, 12); m_channelMappings.Add(5, 13); m_channelMappings.Add(6, 14); m_channelMappings.Add(7, 15); }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public Usb1608GXAo(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 2) { }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public CtrComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_counterWidths = new uint[m_maxChannels]; m_counterTypes = new CounterTypes[m_maxChannels]; }
//=================================================================================================== /// <summary> /// ctor /// </summary> /// <param name="daqDevice">A reference to the DaqDevice object that creates this component</param> /// <param name="deviceInfo">A referemce tp the DeviceInfo object that the Driver Interace uses</param> //=================================================================================================== public EventCounter(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { }
internal DriverInterface(DaqDevice daqDevice, DeviceInfo deviceInfo, Object deviceLock) { m_deviceInfo = deviceInfo; m_daqDevice = daqDevice; m_deviceLock = deviceLock; m_platformInterop = PlatformInterop.GetUsbPlatformInterop(deviceInfo, m_criticalParams); // the error code may be set if the device did not initialzie m_errorCode = m_platformInterop.ErrorCode; m_usbPackets = new List<UsbSetupPacket>(); m_usbPacketsDirect = new List<UsbSetupPacket>(); m_ae = new ASCIIEncoding(); string message; // convert following messages to an array of bytes for direct use by this driver interface message = "?AISCAN:STATUS"; Array.Clear(m_aiStatusMessage, 0, m_aiStatusMessage.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiStatusMessage, 0); message = "?AISCAN:TRIG"; Array.Clear(m_aiTrigStatus, 0, m_aiTrigStatus.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiTrigStatus, 0); message = "?AITRIG:REARM"; Array.Clear(m_aiRearmStatus, 0, m_aiRearmStatus.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiRearmStatus, 0); message = "?AISCAN:SAMPLES"; Array.Clear(m_aiQuerySamples, 0, m_aiQuerySamples.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiQuerySamples, 0); message = "AISCAN:SAMPLES="; Array.Clear(m_aiScanSamples, 0, m_aiScanSamples.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiScanSamples, 0); message = "?AOSCAN:STATUS"; Array.Clear(m_aoStatusMessage, 0, m_aoStatusMessage.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aoStatusMessage, 0); message = "AISCAN:STOP"; Array.Clear(m_aiScanStopMessage, 0, m_aiScanStopMessage.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aiScanStopMessage, 0); message = "AOSCAN:STOP"; Array.Clear(m_aoScanStopMessage, 0, m_aoScanStopMessage.Length); m_ae.GetBytes(message.ToCharArray(), 0, message.Length, m_aoScanStopMessage, 0); m_deferredResponsePacket = new UsbSetupPacket(Constants.MAX_COMMAND_LENGTH); m_deferredResponsePacket.TransferType = UsbTransferTypes.ControlIn; m_deferredResponsePacket.Request = ControlRequest.MESSAGE_REQUEST; m_deferredResponsePacket.DeferTransfer = false; m_deferredResponsePacket.Index = 0; m_deferredResponsePacket.Value = 0; m_deferredResponsePacket.Length = Constants.MAX_COMMAND_LENGTH; m_inputBufferSizeOverride = false; m_controlInPacket = new UsbSetupPacket(Constants.MAX_MESSAGE_LENGTH); m_controlInPacket.TransferType = UsbTransferTypes.ControlIn; m_controlInPacket.Request = ControlRequest.MESSAGE_REQUEST; m_controlOutPacket = new UsbSetupPacket(Constants.MAX_MESSAGE_LENGTH); m_controlOutPacket.TransferType = UsbTransferTypes.ControlOut; m_controlOutPacket.Request = ControlRequest.MESSAGE_REQUEST; m_controlInPacketDirect = new UsbSetupPacket(Constants.MAX_MESSAGE_LENGTH); m_controlInPacketDirect.TransferType = UsbTransferTypes.ControlIn; m_controlInPacketDirect.Request = ControlRequest.MESSAGE_REQUEST; m_controlOutPacketDirect = new UsbSetupPacket(Constants.MAX_MESSAGE_LENGTH); m_controlOutPacketDirect.TransferType = UsbTransferTypes.ControlOut; m_controlOutPacketDirect.Request = ControlRequest.MESSAGE_REQUEST; m_criticalParams.ScanType = ScanType.AnalogInput; m_currentOutputScanWriteIndex = 0; m_outputTransferStartIndex = 0; unsafe { m_externalReadBuffer = null; } m_inputBlockSize = PropertyValues.DEFAULT; // by default, don't let old data that hasn't been read yet get overwritten m_criticalParams.InputScanOverwrite = false; m_internalReadBuffer = new byte[INTERNAL_READ_BUFFER_SIZE]; m_internalWriteBuffer = new byte[INTERNAL_WRITE_BUFFER_SIZE]; m_stopOutputScanDelegate = new StopOutputScanDelegate(StopOutputScan); m_stopOutputScanCallback = new AsyncCallback(StopOutputScanCallback); }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public AoComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_calibrateData = true; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal Usb7202Ai(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 8) { }
//=================================================================================================== /// <summary> /// Calculates the delta t between samples per channel /// </summary> /// <param name="device"></param> /// <returns></returns> //=================================================================================================== public static double GetSampleDt(DaqDevice device) { double sampleRate; int channelCount = 0; if (device.SendMessage(Messages.AISCAN_STATUS_QUERY).ToString().Contains(PropertyValues.IDLE)) { try { // test if the queue component is supported by the device... channelCount = (int)device.SendMessage(Messages.AIQUEUE_COUNT_QUERY).ToValue(); ErrorCodes e = device.SendMessageDirect("XYZ"); } catch (Exception) { // no queue component support... int lowChannel = (int)device.SendMessage(Messages.AISCAN_LOWCHAN_QUERY).ToValue(); int highChannel = (int)device.SendMessage(Messages.AISCAN_HIGHCHAN_QUERY).ToValue(); channelCount = highChannel - lowChannel + 1; } // get the current sample rate setting... sampleRate = device.SendMessage(Messages.AISCAN_RATE_QUERY).ToValue(); // calculate the sample dt... m_sampleDt = 1.0 / sampleRate; } return m_sampleDt; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public TmrComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_minPeriod = new double[maxChannels]; m_maxPeriod = new double[maxChannels]; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal Usb1208FSPlusAi(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo) { m_adjustScanRateForChannelCount = false; }
//============================================================================================================ /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> /// <param name="maxChannels">The max number of counters for this device</param> //============================================================================================================ public PulseTimer(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { m_minDelay = new double[maxChannels]; m_maxDelay = new double[maxChannels]; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal IoComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) { m_daqDevice = daqDevice; m_deviceInfo = deviceInfo; m_maxChannels = maxChannels; }
//====================================================================== /// <summary> /// Lets the driver free any resources associated with the device /// </summary> //====================================================================== public static void ReleaseDevice(DaqDevice daqDevice) { daqDevice.ReleaseDevice(); m_daqDeviceList.Remove(daqDevice); }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public Usb7204Ao(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 2) { if (m_daqDevice.FirmwareVersion < 2.0) m_aoScanSupported = false; }
//============================================================================== /// <summary> /// Gets a daq device object based on the selected daq item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //============================================================================== private void OnDeviceSelected(object sender, EventArgs e) { m_deviceName = deviceListComboBox.Items[deviceListComboBox.SelectedIndex].ToString(); // create a daq device object using the daq device manager and the device name try { if (m_previouslySelectedDevice != null) DaqDeviceManager.ReleaseDevice(m_previouslySelectedDevice); this.Cursor = Cursors.WaitCursor; m_daqDevice = DaqDeviceManager.CreateDevice(m_deviceName); m_previouslySelectedDevice = m_daqDevice; // initialize the message combo boxes AddPages(); } catch (DaqException ex) { statusLabel.Text = ex.Message; } finally { this.Cursor = Cursors.Default; } }
private void OnDeviceChanged(object sender, EventArgs e) { statusLabel.Text = string.Empty; ScanDataTextBox.Text = string.Empty; CurrentQueueElements.Clear(); tempUnitsComboBox.Items.Clear(); tempUnitsComboBox.Enabled = false; try { // Release the device if (Device != null) DaqDeviceManager.ReleaseDevice(Device); string name = deviceComboBox.SelectedItem.ToString(); // Create a new device object Cursor.Current = Cursors.WaitCursor; Device = DaqDeviceManager.CreateDevice(name); InitializeControls(); Cursor.Current = Cursors.Default; } catch (Exception ex) { statusLabel.Text = ex.Message; } }
private void OnDeviceChanged(object sender, EventArgs e) { try { // Release the device if (Device != null) DaqDeviceManager.ReleaseDevice(Device); string name = deviceComboBox.SelectedItem.ToString(); // Create a new device object Cursor.Current = Cursors.WaitCursor; Device = DaqDeviceManager.CreateDevice(name); InitializeControls(); Cursor.Current = Cursors.Default; } catch (Exception ex) { statusLabel.Text = ex.Message; } }
//============================================================================= /// <summary> /// Gets setup parameters /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //============================================================================= private void OnSetupButtonClicked(object sender, EventArgs e) { LogData = false; LogFile = String.Empty; Notes = String.Empty; SetupDialog.ShowDialog(); if (SetupDialog.DaqDevice != null) { if (SetupDialog.SupportsTemperature) { string msg; DaqDevice = SetupDialog.DaqDevice; DeviceName = SetupDialog.DeviceName.Split(new char[] { ':' })[0]; DeviceSerno = SetupDialog.DeviceName.Split(new char[] { ':' })[2]; TcType = SetupDialog.TcType; Channel = SetupDialog.Channel; // try setting the channel mode if it's programmable try { msg = "AI{*}:CHMODE=#"; msg = msg.Replace("*", Channel); msg = msg.Replace("#", SetupDialog.ChannelMode); DaqDevice.SendMessage(msg); } catch (Exception) { try { msg = "AI:CHMODE=#"; msg = msg.Replace("#", SetupDialog.ChannelMode); DaqDevice.SendMessage(msg); } catch (Exception) { } } // set the sensor type for the selected channel msg = "AI{*}:SENSOR=TC/#"; msg = msg.Replace("*", Channel); msg = msg.Replace("#", TcType); SendDeviceMessage(msg); SelectedUnits = SetupDialog.Units; SamplePeriod = SetupDialog.SamplePeriod; LogData = SetupDialog.LogData; Notes = SetupDialog.Description; yLabel.Text = SelectedUnits; if (LogData) { LogFile = SetupDialog.LogFile; Notes = SetupDialog.Description; } startButton.Enabled = true; stopButton.Enabled = true; } } }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= public Usb1208FSPlusAo(DaqDevice daqDevice, DeviceInfo deviceInfo) : base(daqDevice, deviceInfo, 2) { }
//============================================================================================== /// <summary> /// calculates the max scan rate based on the method type calculation and channel count /// </summary> /// <param name="device">the daq device</param> /// <returns>max rate base on current configuration</returns> //============================================================================================== public static double CalculateMaxAiScanRate(DaqDevice device) { double deviceMaxRate; double deviceMaxThruput; double deviceMaxBurstRate; double deviceMaxBurstThruput; double maxRate = 0; int channelCount = 0; string xferMode; string sampleRateCalculationMethod; string msg; string textResponse; ErrorCodes msgError; // test if the queue component is supported by the device... msgError = device.SendMessageDirect(Messages.AIQUEUE_COUNT_QUERY); if (msgError == ErrorCodes.NoErrors) { // get the response... textResponse = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); // convert to int... if (!PlatformParser.TryParse(textResponse, out channelCount)) { // alert the developer... System.Diagnostics.Debug.Assert(false, "RateCalulator.CalculateMaxAiScanRate: The channel count could not be parsed"); // use a default value... channelCount = 1; } } if (channelCount == 0) { int lowChannel; int highChannel; // get the low channel number... device.SendMessageDirect(Messages.AISCAN_LOWCHAN_QUERY); // get the reponse... textResponse = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); if (!PlatformParser.TryParse(textResponse, out lowChannel)) { // alert the developer... System.Diagnostics.Debug.Assert(false, "RateCalulator.CalculateMaxAiScanRate: The low channel could not be parsed"); // use a default value... lowChannel = 0; } // get the high channel number... device.SendMessageDirect(Messages.AISCAN_HIGHCHAN_QUERY); // get the reponse... textResponse = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); if (!PlatformParser.TryParse(textResponse, out highChannel)) { // alert the developer... System.Diagnostics.Debug.Assert(false, "RateCalulator.CalculateMaxAiScanRate: The high channel could not be parsed"); // use a default value... highChannel = 0; } channelCount = highChannel - lowChannel + 1; } // get the transfer mode... device.SendMessageDirect(Messages.AISCAN_XFRMODE_QUERY); // get the response... xferMode = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); // get the scan rate calculation method... sampleRateCalculationMethod = device.GetDevCapsString("AISCAN:SCANRATECALC", true); switch (sampleRateCalculationMethod) { // multiplexed... case (PropertyValues.METHOD1): { if (xferMode == PropertyValues.BURSTIO) { // get the max burst rate... deviceMaxBurstRate = device.GetDevCapsValue("AISCAN:MAXBURSTRATE"); // calculate the max rate... if (channelCount > 0) { maxRate = deviceMaxBurstRate / channelCount; } else { maxRate = deviceMaxBurstRate; } } else { // get the max scan rate... deviceMaxRate = device.GetDevCapsValue("AISCAN:MAXSCANRATE"); // calculate the max rate... if (channelCount > 0) { maxRate = deviceMaxRate / channelCount; } else { maxRate = deviceMaxRate; } } break; } // simultaneous... case (PropertyValues.METHOD2): { if (xferMode == PropertyValues.BURSTIO) { // get the max burst thruput... deviceMaxBurstThruput = device.GetDevCapsValue("AISCAN:MAXBURSTTHRUPUT"); // get the max burst rate... deviceMaxBurstRate = device.GetDevCapsValue("AISCAN:MAXBURSTRATE"); // calculate the max rate... if (channelCount > 0) { maxRate = Math.Min(deviceMaxBurstThruput / channelCount, deviceMaxBurstRate); } else { maxRate = deviceMaxBurstThruput; } } else { // get the max scan thruput... deviceMaxThruput = device.GetDevCapsValue("AISCAN:MAXSCANTHRUPUT"); // get the max scan rate... deviceMaxRate = device.GetDevCapsValue("AISCAN:MAXSCANRATE"); // calculate the max rate... if (channelCount > 0) { maxRate = Math.Min(deviceMaxThruput / channelCount, deviceMaxRate); } else { maxRate = deviceMaxThruput; } } break; } // multiplexed - 2408 series case (PropertyValues.METHOD3): { double sum = 0.0; double dataRate; for (int i = 0; i < channelCount; i++) { msg = Messages.AIQUEUE_DATARATE_QUERY; msg = msg.Replace("*", i.ToString()); device.SendMessageDirect(msg); textResponse = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); if (PlatformParser.TryParse(textResponse, out dataRate)) { // get the data rate value... dataRate = device.SendMessage(msg).ToValue(); } else { // alert the developer... System.Diagnostics.Debug.Assert(false, "RateCalulator.CalculateMaxAiScanRate: The data rate could not be parsed"); // use a default value... dataRate = 100; } sum += (1.0 / dataRate) + 0.000640; } maxRate = 1.0 / sum; break; } default: { System.Diagnostics.Debug.Assert(false, String.Format("{0} is not supported by GetMaxAiScanRate()", sampleRateCalculationMethod)); break; } } // truncate to two decimal digits... #if WindowsCE maxRate = (double)((int)maxRate); #else maxRate = Math.Truncate(maxRate); #endif // save the caculated rate... device.Ai.CalculatedMaxSampleRate = maxRate; // query the rate... device.SendMessageDirect(Messages.AISCAN_RATE_QUERY); // read the current value... string response = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); // try and convert the value... double currentRate = Double.NaN; // parse the value... if (PlatformParser.TryParse(response, out currentRate)) { // construct the set rate message... msg = Messages.AISCAN_RATE; // inject the max rate value... msg = msg.Replace("#", maxRate.ToString()); // set the rate... device.SendMessageDirect(msg); // query the rate... device.SendMessageDirect(Messages.AISCAN_RATE_QUERY); // read the value... response = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); double actualMaxRate = Double.NaN; if (PlatformParser.TryParse(response, out actualMaxRate)) { double returnedRate = actualMaxRate; // was the value returned rounded up?... while (returnedRate > maxRate) { // decrease it... actualMaxRate = Math.Round(actualMaxRate - device.Ai.RateCalculatorDecrementCount, 2); msg = Messages.AISCAN_RATE; msg = msg.Replace("#", actualMaxRate.ToString()); // update the rate... device.SendMessageDirect(msg); // query the rate... device.SendMessageDirect(Messages.AISCAN_RATE_QUERY); // read the value... response = MessageTranslator.GetPropertyValue(device.DriverInterface.ReadStringDirect()); if (!PlatformParser.TryParse(response, out returnedRate)) { // alert developers... System.Diagnostics.Debug.Assert(!Double.IsNaN(currentRate), "RateCalculator.GetMaxAiScanRate: The max rate could not be converted to a double"); } } // set the actual max rate... maxRate = actualMaxRate; // save the actual max rate... device.Ai.ActualDeviceMaxSampleRate = maxRate; // restore the rate... msg = Messages.AISCAN_RATE; // is it the device max rate?... if (currentRate == device.Ai.ActualDeviceMaxSampleRate) { // use the calculated max rate... msg = msg.Replace("#", device.Ai.CalculatedMaxSampleRate.ToString()); } else { // use the current rate... msg = msg.Replace("#", currentRate.ToString()); } // set the rate... device.SendMessageDirect(msg); } else { // alert developers... System.Diagnostics.Debug.Assert(!Double.IsNaN(currentRate), "RateCalculator.GetMaxAiScanRate: The max rate could not be converted to a double"); } } else { // alert developers... System.Diagnostics.Debug.Assert(!Double.IsNaN(currentRate), "RateCalculator.GetMaxAiScanRate: The rate could not be converted to a double"); } return maxRate; }
//================================================================================================================= /// <summary> /// ctor /// </summary> /// <param name="daqDevice">The DaqDevice object that creates this component</param> /// <param name="deviceInfo">The DeviceInfo oject passed down to the driver interface</param> //================================================================================================================= internal FixedModeAiComponent(DaqDevice daqDevice, DeviceInfo deviceInfo, int maxChannels) : base(daqDevice, deviceInfo, maxChannels) { }
//============================================================================================== /// <summary> /// Returns the min scan rate /// </summary> /// <param name="device">The daq device</param> /// <returns>min rate</returns> //============================================================================================== public static double GetMinAiScanRate(DaqDevice device) { double minRate = device.GetDevCapsValue("AISCAN:MINSCANRATE"); return minRate; }