//============================================================================================== /// <summary> /// Virtual method to set up ranges and active channels for an output scan /// </summary> //============================================================================================== protected virtual void SetRanges() { int loChan = m_daqDevice.DriverInterface.CriticalParams.LowAoChannel; int hiChan = m_daqDevice.DriverInterface.CriticalParams.HighAoChannel; if (loChan <= hiChan) { m_activeChannels = new ActiveChannels[hiChan - loChan + 1]; int rangeIndex = 0; for (int i = loChan; i <= hiChan; i++) { string rangeQuery = String.Format("?AOSCAN:RANGE{0}", MessageTranslator.GetChannelSpecs(i)); try { string rangeValue; string response = m_daqDevice.SendMessage("@AO:RANGES").ToString(); if (response.Contains("PROG")) { m_daqDevice.SendMessageDirect(rangeQuery).ToString(); response = m_daqDevice.DriverInterface.ReadStringDirect(); rangeValue = response.Substring(response.IndexOf("=") + 1); } else { rangeValue = response.Substring(response.IndexOf("%") + 1); } m_activeChannels[rangeIndex].ChannelNumber = i; m_activeChannels[rangeIndex].UpperLimit = m_supportedRanges[rangeValue].UpperLimit; m_activeChannels[rangeIndex].LowerLimit = m_supportedRanges[rangeValue].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[rangeIndex].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", i, rangeValue)].Slope; m_activeChannels[rangeIndex].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", i, rangeValue)].Offset; } } catch (Exception ex) { System.Diagnostics.Debug.Assert(false, ex.Message); } rangeIndex++; } } }
//=========================================================================================== /// <summary> /// Validates the Ai Value message /// </summary> /// <param name="message">The message</param> /// <returns>An error code</returns> //=========================================================================================== internal override ErrorCodes ProcessValueSetMessage(ref string message) { int channelNumber = MessageTranslator.GetChannel(message); if (channelNumber >= 0 && channelNumber < m_channelCount) { string value = String.Empty; m_valueUnits = String.Empty; if (message.Contains(ValueResolvers.RAW)) { // set the clones for restoring original flags after SendMessage is complete m_calibrateDataClone = m_calibrateData; m_scaleDataClone = m_scaleData; // set original flags m_calibrateData = false; m_scaleData = false; m_valueUnits = Constants.VALUE_RESOLVER + ValueResolvers.RAW; value = MessageTranslator.GetPropertyValue(message); message = MessageTranslator.RemoveValueResolver(message); message += (Constants.EQUAL_SIGN + value); } else if (message.Contains(ValueResolvers.VOLTS)) { // set the clones for restoring original flags after SendMessage is complete m_calibrateDataClone = m_calibrateData; m_scaleDataClone = m_scaleData; // set original flags if (m_daqDevice.GetDevCapsString("AO:FACCAL", false).Contains(DevCapValues.SUPPORTED)) m_calibrateData = true; m_scaleData = true; m_valueUnits = Constants.VALUE_RESOLVER + ValueResolvers.VOLTS; value = MessageTranslator.GetPropertyValue(message); message = MessageTranslator.RemoveValueResolver(message); message += (Constants.EQUAL_SIGN + value); } else if (message.Contains("AO{0}:VALUE/")) { return ErrorCodes.InvalidMessage; } m_activeChannels = new ActiveChannels[1]; string rangeKey = m_ranges[channelNumber].Substring(m_ranges[channelNumber].IndexOf(Constants.EQUAL_SIGN) + 1); m_activeChannels[0].ChannelNumber = channelNumber; m_activeChannels[0].UpperLimit = m_supportedRanges[rangeKey].UpperLimit; m_activeChannels[0].LowerLimit = m_supportedRanges[rangeKey].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[0].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", channelNumber, rangeKey)].Offset; m_activeChannels[0].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", channelNumber, rangeKey)].Slope; } } return ErrorCodes.NoErrors; }
//==================================================================================== /// <summary> /// Sets up the active channels array with scaling and cal coeff info /// This gets called from the Ai.PreprocesAiScanMessage when the AISCAN:START message /// is sent. /// </summary> //==================================================================================== protected virtual ErrorCodes SetRanges() { bool useRangeQueue = false; bool useNewQueueMethod = false; string aiConfiguration = "SE"; string queueQuery; try { DaqResponse response; ///////////////////////////////////////////////////////////// // first check if the input queue is supported and enabled ///////////////////////////////////////////////////////////// // get the supported queue length response = m_daqDevice.SendMessage("@AISCAN:QUEUELEN"); double elements = response.ToValue(); if (!Double.IsNaN(elements) && elements > 0) { // check if the queue is enabled m_daqDevice.SendMessageDirect(Messages.AISCAN_QUEUE_QUERY); queueQuery = m_daqDevice.DriverInterface.ReadStringDirect(); if (queueQuery.Contains(PropertyValues.ENABLE)) useRangeQueue = true; else useRangeQueue = false; // now check if the queue is implemented with the old or new method // the old method uses the AISCAN:RANGE{e/c} message // the new method uses the AIQUEUE{e}:CHAN, AIQUEUE{e}:CHMODE, AIQUEUE{e}:RANGE messages // (e = element, c = channel) if (useRangeQueue && m_daqDevice.SendMessageDirect(Messages.AIQUEUE_COUNT_QUERY) == ErrorCodes.NoErrors) useNewQueueMethod = true; } } catch (Exception) { useRangeQueue = false; } if (useRangeQueue) { /////////////////////////////////////////////// // Using Range Queue /////////////////////////////////////////////// try { if (useNewQueueMethod) { /////////////////////////////////////////////// // using new queue programming method /////////////////////////////////////////////// string response; string rangeValue; string rangeKey; string supportedChannelModes; string queueConfig; // get the number of elements in the queue m_daqDevice.SendMessageDirect(Messages.AIQUEUE_COUNT_QUERY); response = m_daqDevice.DriverInterface.ReadStringDirect(); int queueCount = Convert.ToInt32(MessageTranslator.GetPropertyValue(response)); m_activeChannels = new ActiveChannels[queueCount]; int channel; //int rangeIndex = 0; string msg; string chMode; if (queueCount > 0) { for (int i = 0; i < queueCount; i++) { //////////////////////////////////////////// // get the channel for queue element i //////////////////////////////////////////// channel = m_aiQueueList[i].ChannelNumber; if (channel < 0) { msg = Messages.AIQUEUE_CHAN_QUERY; msg = Messages.InsertElement(msg, i); m_daqDevice.SendMessageDirect(msg); channel = (int)m_daqDevice.DriverInterface.ReadValueDirect(); } m_activeChannels[i].ChannelNumber = channel; //////////////////////////////////////////// // get the channel mode for queue element i //////////////////////////////////////////// queueConfig = m_daqDevice.GetDevCapsString("AISCAN:QUEUECONFIG", false); if (queueConfig.Contains(PropertyValues.CHMODE)) { chMode = m_aiQueueList[i].ChannelMode; if (chMode == PropertyValues.NOT_SET) { msg = Messages.AIQUEUE_CHMODE_QUERY; msg = Messages.InsertElement(msg, i); m_daqDevice.SendMessageDirect(msg); chMode = m_daqDevice.DriverInterface.ReadStringDirect(); chMode = MessageTranslator.GetPropertyValue(chMode); } } else { supportedChannelModes = m_daqDevice.GetDevCapsString("AI:CHMODES", false); if (supportedChannelModes.Contains(DevCapImplementations.FIXED)) { chMode = m_daqDevice.GetDevCapsString("AI:CHMODES", true); } else { msg = Messages.AI_CH_CHMODE_QUERY; msg = Messages.InsertChannel(msg, channel); m_daqDevice.SendMessageDirect(msg); chMode = m_daqDevice.DriverInterface.ReadStringDirect(); chMode = MessageTranslator.GetPropertyValue(chMode); if (!supportedChannelModes.Contains(chMode)){ m_daqDevice.SendMessageDirect(Messages.AI_CHMODE_QUERY); chMode = m_daqDevice.DriverInterface.ReadStringDirect(); chMode = MessageTranslator.GetPropertyValue(chMode); } } } //////////////////////////////////////////// // get the range for queue element i //////////////////////////////////////////// rangeValue = m_aiQueueList[i].Range; if (rangeValue == PropertyValues.NOT_SET) { msg = Messages.AIQUEUE_RANGE_QUERY; msg = Messages.InsertElement(msg, i); m_daqDevice.SendMessageDirect(msg); rangeValue = m_daqDevice.DriverInterface.ReadStringDirect(); rangeValue = MessageTranslator.GetPropertyValue(rangeValue); } // build the range key rangeKey = String.Format("{0}:{1}", rangeValue, chMode); m_activeChannels[i].UpperLimit = m_supportedRanges[rangeKey].UpperLimit; m_activeChannels[i].LowerLimit = m_supportedRanges[rangeKey].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[i].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", channel, rangeKey)].Slope; m_activeChannels[i].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", channel, rangeKey)].Offset; } } } else { return ErrorCodes.InputQueueIsEmpty; } } else { /////////////////////////////////////////////// // using old queue programming method /////////////////////////////////////////////// string response; string rangeValue; // get the channel mode (with the old method this query pertains to all channels) m_daqDevice.SendMessageDirect(Messages.AI_CHMODE_QUERY); response = m_daqDevice.DriverInterface.ReadStringDirect(); aiConfiguration = MessageTranslator.GetPropertyValue(response); // get the number of elements in the queue m_daqDevice.SendMessageDirect(Messages.AISCAN_RANGE_QUERY); response = m_daqDevice.DriverInterface.ReadStringDirect(); int queueCount = Convert.ToInt32(MessageTranslator.GetPropertyValue(response)); m_activeChannels = new ActiveChannels[queueCount]; int channel; int indexOfChannel; int indexOfBrace; int rangeIndex = 0; if (queueCount > 0) { for (int i = 0; i < queueCount; i++) { // Continue here for the USB-7204 string rangeQuery = String.Format("?AISCAN:RANGE{0}", MessageTranslator.GetChannelSpecs(i)); m_daqDevice.SendMessageDirect(rangeQuery).ToString(); response = m_daqDevice.DriverInterface.ReadStringDirect(); rangeValue = response.Substring(response.IndexOf("=") + 1); rangeValue += (":" + aiConfiguration); indexOfChannel = response.IndexOf(Constants.VALUE_RESOLVER) + 1; indexOfBrace = response.IndexOf(CurlyBraces.RIGHT); channel = Convert.ToInt32(response.Substring(indexOfChannel, indexOfBrace - indexOfChannel)); m_activeChannels[rangeIndex].ChannelNumber = channel; m_activeChannels[rangeIndex].UpperLimit = m_supportedRanges[rangeValue].UpperLimit; m_activeChannels[rangeIndex].LowerLimit = m_supportedRanges[rangeValue].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[rangeIndex].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", channel, rangeValue)].Slope; m_activeChannels[rangeIndex].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", channel, rangeValue)].Offset; } rangeIndex++; } } else { return ErrorCodes.InputQueueIsEmpty; } } } catch (Exception) { } } else { /////////////////////////////////////////////// // Not using Range Queue /////////////////////////////////////////////// int loChan = m_daqDevice.DriverInterface.CriticalParams.LowAiChannel; int hiChan = m_daqDevice.DriverInterface.CriticalParams.HighAiChannel; if (loChan <= hiChan) { string msg; string response; m_activeChannels = new ActiveChannels[hiChan - loChan + 1]; int rangeIndex = 0; for (int i = loChan; i <= hiChan; i++) { string rangeQuery = GetAiScanRange(i); try { if (this is FixedModeAiComponent) { msg = "@AI:CHMODES"; response = m_daqDevice.SendMessage(msg).ToString(); aiConfiguration = response.Substring(response.IndexOf('%') + 1); } else { if (this is DualModeAiComponent) { msg = Messages.AI_CHMODE_QUERY; } else { msg = Messages.AI_CH_CHMODE_QUERY; msg = Messages.InsertChannel(msg, i); } response = m_daqDevice.SendMessage(msg).ToString(); aiConfiguration = response.Substring(response.IndexOf('=') + 1); } m_daqDevice.SendMessageDirect(rangeQuery); response = m_daqDevice.DriverInterface.ReadStringDirect(); if (response.Contains(PropertyValues.MIXED)) { msg = Messages.AI_CH_RANGE_QUERY; msg = Messages.InsertChannel(msg, i); m_daqDevice.SendMessageDirect(msg); response = m_daqDevice.DriverInterface.ReadStringDirect(); } string rangeValue = response.Substring(response.IndexOf("=") + 1); rangeValue += (":" + aiConfiguration); m_activeChannels[rangeIndex].ChannelNumber = i; m_activeChannels[rangeIndex].UpperLimit = m_supportedRanges[rangeValue].UpperLimit; m_activeChannels[rangeIndex].LowerLimit = m_supportedRanges[rangeValue].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[rangeIndex].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", i, rangeValue)].Slope; m_activeChannels[rangeIndex].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", i, rangeValue)].Offset; } } catch (Exception ex) { System.Diagnostics.Debug.Assert(false, ex.Message); return ErrorCodes.ActiveChannelsNotSet; } rangeIndex++; } } } // update the channel count and recalculate the bulk in xfer size m_daqDevice.DriverInterface.CriticalParams.AiChannelCount = m_activeChannels.Length; m_daqDevice.DriverInterface.CriticalParams.BulkInXferSize = m_daqDevice.DriverInterface.GetOptimalInputBufferSize(m_daqDevice.DriverInterface.CriticalParams.InputScanRate); return ErrorCodes.NoErrors; }
//================================================================================================================= /// <summary> /// Overriden to initialize range information /// </summary> //================================================================================================================= internal override void InitializeRanges() { m_supportedRanges.Add(MessageTranslator.ConvertToCurrentCulture(PropertyValues.BIPPT073125V) + ":DIFF", new Range(0.073125, -0.073125)); m_supportedRanges.Add(MessageTranslator.ConvertToCurrentCulture(PropertyValues.BIPPT14625V) + ":DIFF", new Range(0.14625, -0.14625)); // store default range m_ranges[0] = MessageTranslator.ConvertToCurrentCulture("AI{0}:RANGE=BIP73.125E-3V"); m_activeChannels = new ActiveChannels[1]; m_activeChannels[0].ChannelNumber = 0; m_activeChannels[0].UpperLimit = m_supportedRanges[MessageTranslator.ConvertToCurrentCulture(PropertyValues.BIPPT073125V) + ":DIFF"].UpperLimit; m_activeChannels[0].LowerLimit = m_supportedRanges[MessageTranslator.ConvertToCurrentCulture(PropertyValues.BIPPT073125V) + ":DIFF"].LowerLimit; }
////==================================================================================== ///// <summary> ///// Virtual method for processing the xfer mode message ///// </summary> ///// <param name="message">The device message</param> ////==================================================================================== //internal override ErrorCodes PreProcessXferModeMessage(ref string message) //{ // ErrorCodes errorCode; // errorCode = base.PreProcessXferModeMessage(ref message); // /* override the setting of this critical param. This device only supports one sample per channel in SINGLEIO mode because of the different data rates */ // if (errorCode == ErrorCodes.NoErrors) // m_daqDevice.CriticalParams.NumberOfSamplesForSingleIO = 1; // return errorCode; //} //====================================================================================================================== /// <summary> /// Overridden because the channels can have different channel mode settings /// </summary> /// <param name="channelNumber">The channel number</param> /// <param name="message">The value get message</param> /// <returns>An error code</returns> //====================================================================================================================== internal override ErrorCodes ProcessValueGetMessage(int channelNumber, ref string message) { m_aiChannelType[channelNumber] = GetChannelType(channelNumber); m_activeChannels = new ActiveChannels[1]; string rangeKey = m_ranges[channelNumber].Substring(m_ranges[channelNumber].IndexOf(Constants.EQUAL_SIGN) + 1); m_channelModes[channelNumber] = GetChannelMode(channelNumber); rangeKey += String.Format(":{0}", m_channelModes[channelNumber]); if (channelNumber < m_channelCount) { m_activeChannels[0].ChannelNumber = channelNumber; m_activeChannels[0].UpperLimit = m_supportedRanges[rangeKey].UpperLimit; m_activeChannels[0].LowerLimit = m_supportedRanges[rangeKey].LowerLimit; if (m_calCoeffs.Count > 0) { m_activeChannels[0].CalOffset = m_calCoeffs[String.Format("Ch{0}:{1}", channelNumber, rangeKey)].Offset; m_activeChannels[0].CalSlope = m_calCoeffs[String.Format("Ch{0}:{1}", channelNumber, rangeKey)].Slope; } } return base.ProcessValueGetMessage(channelNumber, ref message); }