/// <summary> /// Relais output parameter construction (hysteresis or window mode) /// </summary> /// <param name="portId"></param> /// <param name="normallyInverted"></param> /// <param name="mvCode"></param> /// <param name="mvRangeMin"></param> /// <param name="mvRangeMax"></param> /// <param name="switchPoint1"></param> /// <param name="hysteresis1"></param> /// <param name="switchPoint2"></param> /// <param name="hysteresis2"></param> /// <param name="mvVariant"></param> /// <param name="errorIndicationEnabled"></param> /// <param name="activeIfError"></param> public SetOutputConfigCmdParams_Relais(byte portId, bool normallyInverted, MVCode mvCode, float mvRangeMin, float mvRangeMax, float switchPoint1, float hysteresis1, float?switchPoint2, float?hysteresis2, ValueVariant?mvVariant = null, bool?errorIndicationEnabled = null, bool activeIfError = false) : base(portId) { //... set bytes }
/// <summary> /// Determines whether measurement value code 1 is from different unit system as the specified measurement value code 2. /// </summary> /// <param name="mvCode1">The measurement value code 1.</param> /// <param name="mvCode2">The measurement value code 2.</param> /// <returns> /// <c>true</c> if they are from different unit systems; otherwise, <c>false</c>. /// </returns> public static bool IsDifferentUnitSystem(MVCode mvCode1, MVCode mvCode2) { //return (IsUnitSystemSI(mvCode1) && IsUnitSystemUS(mvCode2)) || // (IsUnitSystemUS(mvCode1) && IsUnitSystemSI(mvCode2)); SIUSUnit unit1 = GetUnitSystem(mvCode1); SIUSUnit unit2 = GetUnitSystem(mvCode2); return(unit1 != unit2); }
/// <summary> /// Analog output parameter construction /// </summary> /// <param name="portId"></param> /// <param name="analogMode"></param> /// <param name="mvCode"></param> /// <param name="mvRangeMin"></param> /// <param name="mvRangeMax"></param> /// <param name="analogRangeMin"></param> /// <param name="analogRangeMax"></param> /// <param name="mvVariant"></param> /// <param name="errorIndicationEnabled"></param> /// <param name="errorIndication"></param> /// <param name="isInput"></param> public SetOutputConfigCmdParams_Analog(byte portId, byte analogMode, MVCode mvCode, float mvRangeMin, float mvRangeMax, float analogRangeMin, float analogRangeMax, ValueVariant?mvVariant = null, bool?errorIndicationEnabled = null, float errorIndication = 0, bool isInput = false) : base(portId, isInput) { if (analogMode != 0x0 && analogMode != 0x1) { throw new ArgumentOutOfRangeException("analogMode", "Only 0x0 (current mode) or 0x1 (voltage mode) is allowed"); } //... set bytes }
/// <summary> /// Gets the (engineering) unit system, i.e. SI or US (or undefined for neutral MV codes). /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <returns></returns> public static SIUSUnit GetUnitSystem(MVCode mvCode) { if (Enumerable.Contains(MembersUnitSI, mvCode)) { return(SIUSUnit.SI); } if (Enumerable.Contains(MembersUnitUS, mvCode)) { return(SIUSUnit.US); } return(SIUSUnit.Undefined); }
internal override void InterpretResult(bool reverseByteOrder, IEECmdConverters cmdConv, IEECommandParameter cmdParams) { // Create command specific result from data if (Data.Length < cmdParams.CmdData.Length + 1) { Code = EECmdResultCode.InvalidResult; } else { // First response byte is 0, data begins at 1 int resultIdx = 1; // Get number of requested values from sent command data int nrValues = cmdParams.CmdData.Length / 2; for (int i = 0; i < nrValues; i++) { // Get MVCode from sent command data MVCode code = cmdConv.MVIndexToMVCode(cmdParams.CmdData[i * 2]); // Get data type (try to get from MVCode if invalid) MVDataType dataType = (MVDataType)Data[resultIdx++]; // Get value for data type double value = double.NaN; switch (dataType) { case MVDataType.Float: if ((resultIdx + 4) <= Data.Length) { value = DataTypeConverter.ByteConverter.ToFloat(Data, resultIdx, reverseByteOrder).ToDoubleWithFloatResolution(); } resultIdx += 4; break; case MVDataType.Double: if ((resultIdx + 8) <= Data.Length) { value = DataTypeConverter.ByteConverter.ToDouble(Data, resultIdx, reverseByteOrder); } resultIdx += 8; break; } MeasValues.Add(new KeyValuePair <MVCode, double>(code, value)); } } }
/// <summary> /// Modifies the MVCode collection with specified MVCodes (given as string list). /// </summary> /// <param name="mvCodes">MVCode collection</param> /// <param name="itemsToProcess">Items to add or remove</param> /// <param name="adding">Given items should be added (true) or removed (false)</param> private static void Modify(IList <MVCode> mvCodes, string itemsToProcess, bool adding) { if (null == mvCodes || null == itemsToProcess) { return; } string[] items = itemsToProcess.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in items) { MVCode mvCode = MVCodeHelper.ParseSafe(item); MVClass mvClass = MVClassHelper.ParseSafe(item); if (MVCode.INVALID != mvCode) { if (adding && !mvCodes.Contains(mvCode)) { mvCodes.Add(mvCode); } if (!adding && mvCodes.Contains(mvCode)) { mvCodes.Remove(mvCode); } } if (MVClass.INVALID != mvClass) { IEnumerator <MVCode> enumerator = MVEnumerator.GetCodesOfClass(mvClass); while (enumerator.MoveNext()) { MVCode current = enumerator.Current; if (current == MVCode.INVALID) { continue; } if (adding && !mvCodes.Contains(current)) { mvCodes.Add(current); } if (!adding && mvCodes.Contains(current)) { mvCodes.Remove(current); } } } } }
/// <summary> /// Pulse output parameter construction /// </summary> /// <param name="portId"></param> /// <param name="normallyInverted"></param> /// <param name="mvCode"></param> /// <param name="mvRangeMin"></param> /// <param name="mvRangeMax"></param> /// <param name="pulseWidth"></param> /// <param name="pulseWeight"></param> /// <param name="mvVariant"></param> /// <param name="errorIndicationEnabled"></param> /// <param name="activeIfError"></param> public SetOutputConfigCmdParams_Pulse(byte portId, bool normallyInverted, MVCode mvCode, float mvRangeMin, float mvRangeMax, float pulseWidth, float pulseWeight, ValueVariant?mvVariant = null, bool?errorIndicationEnabled = null, bool activeIfError = false) : base(portId) { int size = 20; if (mvVariant != null || errorIndicationEnabled != null) { size += 1; // additional byte for variant } if (errorIndicationEnabled != null) { size += errorIndicationEnabled.Value ? 2 : 1; // additional byte for enabled (2 additional if 'true') } //... set bytes }
/// <summary> /// Ensures measurement value is of the unit system US. /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <returns>Measurement value code that is of unit system US (may be the same as parameter <paramref name="mvCode"/>).</returns> public static MVCode EnsureUnitSystemUS(MVCode mvCode) { if (MVCode.INVALID == mvCode) { return(mvCode); } if (MVCode.TEMP__DEG_K == mvCode) { return(MVCode.TEMP__DEG_F); } if (IsUnitSystemUSorNeutral(mvCode)) { return(mvCode); } return(MembersUnitUS.ElementAt(MembersUnitSI.ToList().FindIndex(mv => mv.Equals(mvCode)))); }
/// <summary> /// Initializes a new instance of the <see cref="MVClassOrMVCode" /> class. /// </summary> /// <param name="mvCode">The MVCode.</param> public MVClassOrMVCode(MVCode mvCode) : this(MVEnumerator.GetClass(mvCode), mvCode) { }
/// <summary> /// Converts the EE31 standardized measval index (Cmds 0x33/0x34) to MVCode. /// </summary> /// <param name="ee31MVIdx"></param> /// <returns></returns> public MVCode MVIndexToMVCode(int ee31MVIdx) { if (UseMVCodeInsteadOfEE31Index) { // Use MVCode enum values instead of EE31 index numbers to identify measurands // (with unit). Only newer devices like EE210 support this. try { MVCode mvCode = (MVCode)ee31MVIdx; if (Enum.IsDefined(typeof(MVCode), mvCode)) { return(mvCode); } } catch (Exception ex) { Diagnostic.Msg(1, "MVIndexToMVCode", "Exception: " + ex.Message); } return(MVCode.INVALID); } bool bIsUnitSystemUS = SIUS == SIUSUnit.US; foreach (byte cmd in new byte[] { 0x33, 0x67 }) { if (null != CfgMVCodeTranslations && CfgMVCodeTranslations.ContainsKey(cmd) && CfgMVCodeTranslations[cmd].Count > 0) { // If unit override exists, try to find there MVCodeTranslationData mvcTD = CfgMVCodeTranslations[cmd].FirstOrDefault(a => a.EE31Index == ee31MVIdx); if (null != mvcTD) { if (bIsUnitSystemUS) { return(mvcTD.MVCodeUS); } return(mvcTD.MVCode); } } } switch (ee31MVIdx) { case 0: // Temperature T [°C; °F] if (bIsUnitSystemUS) { return(MVCode.TEMP__DEG_F); } return(MVCode.TEMP__DEG_C); case 1: // Relative Humidity RH [%rH] return(MVCode.RH__PCT); case 2: // Water vapor partial pressure e [mbar; psi] if (bIsUnitSystemUS) { return(MVCode.e__PSI); } return(MVCode.e__MBAR); case 3: // Dew point Td [°C; °F] if (bIsUnitSystemUS) { return(MVCode.Td__DEG_F); } return(MVCode.Td__DEG_C); case 4: // Wet bulb Tw [°C; °F] if (bIsUnitSystemUS) { return(MVCode.Tw__DEG_F); } return(MVCode.Tw__DEG_C); case 5: // Water vapor concentration dv [g/m3; gr/ft3] if (bIsUnitSystemUS) { return(MVCode.dv__GR_FT3); } return(MVCode.dv__G_M3); case 6: // Mixing ratio r [g/kg; gr/lb] if (bIsUnitSystemUS) { return(MVCode.r__GR_LB); } return(MVCode.r__G_KG); case 7: // Enthalpy h [kJ/kg; ft lbf/lb] if (bIsUnitSystemUS) { return(MVCode.h__FT_LBF_LB); } return(MVCode.h__KJ_KG); case 8: // Dew point Td or Frost point Tf [°C; °F] if (bIsUnitSystemUS) { return(MVCode.TdTf__DEG_F); } return(MVCode.TdTf__DEG_C); case 10: // CO2 raw [ppm] return(MVCode.CO2_RAW__PPM); case 11: // CO2 mean [ppm] return(MVCode.CO2_MEAN__PPM); case 12: // (Air) Velocity [m/s; ft/min] if (bIsUnitSystemUS) { return(MVCode.V__FT_PER_MIN); } return(MVCode.V__M_PER_SEC); case 13: // Aw [1] return(MVCode.Aw__1); case 14: // Water content X [ppm] return(MVCode.X__PPM); case 27: // Volume concentration (Humidity!) [ppm] return(MVCode.Wv__PPM); case 28: // %S [%] return(MVCode.PctS__PCT); case 40: // O2 mean value [%] return(MVCode.O2_MEAN__PCT); } return(MVCode.INVALID); }
/// <summary> /// Converts the MVCode to EE31 standardized measval index (Cmds 0x33/0x34). /// </summary> /// <param name="mvCode">The mv code.</param> /// <returns></returns> public byte MVCodeToEE31MVIndex(MVCode mvCode) { // Use MVCode enum values instead of EE31 index numbers to identify measurands (with // unit). Only newer devices like EE210 support this. if (UseMVCodeInsteadOfEE31Index) { return((byte)mvCode); } foreach (byte cmd in new byte[] { 0x33, 0x67 }) { if (null != CfgMVCodeTranslations && CfgMVCodeTranslations.ContainsKey(cmd) && CfgMVCodeTranslations[cmd].Count > 0) { // If unit override exists, try to find there MVCodeTranslationData mvcTD = CfgMVCodeTranslations[cmd].FirstOrDefault(a => a.MVCode == mvCode || a.MVCodeUS == mvCode); if (null != mvcTD) { return((byte)mvcTD.EE31Index); } } } switch (mvCode) { case MVCode.TEMP__DEG_C: // Temp. [°C] case MVCode.TEMP__DEG_F: // Temp. [°F] case MVCode.TEMP__DEG_K: // Temp. [K] return(0); case MVCode.RH__PCT: // RH [%rH] return(1); case MVCode.e__MBAR: // Water vapor partial pressure e [mbar] case MVCode.e__PSI: // Water vapor partial pressure e [psi] return(2); case MVCode.Td__DEG_C: // Dew point temperature Td [°C] case MVCode.Td__DEG_F: // Dew point temperature Td [°F] case MVCode.Td__DEG_K: // Dew point temperature Td [K] return(3); case MVCode.Tw__DEG_C: // Wet bulb temperature Tw [°C] case MVCode.Tw__DEG_F: // Wet bulb temperature Tw [°F] case MVCode.Tw__DEG_K: // Wet bulb temperature Tw [K] return(4); case MVCode.dv__G_M3: // Absolute humidity dv [g/m3] case MVCode.dv__GR_FT3: // Absolute humidity dv [gr/ft3] return(5); case MVCode.r__G_KG: // Mixing ratio r [g/kg] case MVCode.r__GR_LB: // Mixing ratio r [gr/lb] return(6); case MVCode.h__KJ_KG: // Enthalpy h [kJ/kg] case MVCode.h__FT_LBF_LB: // Enthalpy h [ft lbf/lb] case MVCode.h__BTU_LB: // Enthalpy h [BTU/lb] return(7); case MVCode.TdTf__DEG_C: // Td/Tf [°C] case MVCode.TdTf__DEG_F: // Td/Tf [°F] case MVCode.TdTf__DEG_K: // Td/Tf [K] return(8); case MVCode.CO2_RAW__PPM: // CO2 raw [ppm] return(10); case MVCode.CO2_MEAN__PPM: // CO2 mean value (Median 11) [ppm] return(11); case MVCode.V__M_PER_SEC: // (Air) Velocity [m/s] case MVCode.V__FT_PER_MIN: // (Air) Velocity [ft/min] return(12); case MVCode.Aw__1: // Aw [1] return(13); case MVCode.X__PPM: // Water content X [ppm] return(14); case MVCode.Wv__PPM: // Volume concentration (Humidity!) [ppm] return(27); case MVCode.PctS__PCT: // %S [%] return(28); case MVCode.O2_MEAN__PCT: // O2 mean value [%] return(40); //case AirPres__MBAR: // Air pressure [mbar] } return(0xFF); }
/// <summary> /// Parameter constructor to set measurement value and measurement range for Out1 and Out2 /// </summary> public SetOut1Out2MVAndRangeCmdParams(MVCode out1MVCode, float out1MVRangeMin, float out1MVRangeMax, MVCode out2MVCode, float out2MVRangeMin, float out2MVRangeMax) : base(0x0) { //... set bytes }
/// <summary> /// Determines whether measurement value code is of unit system US or neutral. /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <returns> /// <c>true</c> if it is of unit system US or neutral; otherwise, <c>false</c>. /// </returns> public static bool IsUnitSystemUSorNeutral(MVCode mvCode) { return(Enumerable.Contains(MembersUnitUS, mvCode) || IsUnitSystemNeutral(mvCode)); }
/// <summary> /// Determines whether measurement value code is of unit system US. /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <returns> /// <c>true</c> if it is of unit system US; otherwise, <c>false</c>. /// </returns> public static bool IsUnitSystemUS(MVCode mvCode) { return(Enumerable.Contains(MembersUnitUS, mvCode)); }
/// <summary> /// Determines whether measurement value code is member of the specified mv class. /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <param name="mvClass">The measurement value class.</param> /// <returns> /// <c>true</c> if is member of [the specified measurement value class; otherwise, <c>false</c>. /// </returns> public static bool IsMemberOf(MVCode mvCode, MVClass mvClass) { switch (mvClass) { case MVClass.Temperature: return(Enumerable.Contains(MembersTemperature, mvCode)); case MVClass.RelativeHumidity: return(Enumerable.Contains(MembersRelativeHumidity, mvCode)); case MVClass.Velocity: return(Enumerable.Contains(MembersVelocity, mvCode)); case MVClass.StdVelocity: return(Enumerable.Contains(MembersStdVelocity, mvCode)); case MVClass.CO2: return(Enumerable.Contains(MembersCO2, mvCode)); case MVClass.CO2Raw: return(Enumerable.Contains(MembersCO2Raw, mvCode)); case MVClass.O2: return(Enumerable.Contains(MembersO2, mvCode)); case MVClass.WaterVaporPartialPressure: return(Enumerable.Contains(MembersWaterVaporPartialPressure, mvCode)); case MVClass.DewPoint: return(Enumerable.Contains(MembersDewPoint, mvCode)); case MVClass.WetBulb: return(Enumerable.Contains(MembersWetBulb, mvCode)); case MVClass.AbsoluteHumidity: return(Enumerable.Contains(MembersAbsoluteHumidity, mvCode)); case MVClass.MixingRatio: return(Enumerable.Contains(MembersMixingRatio, mvCode)); case MVClass.Enthalpy: return(Enumerable.Contains(MembersEnthalpy, mvCode)); case MVClass.DewPointOrFrostPoint: return(Enumerable.Contains(MembersDewPointOrFrostPoint, mvCode)); case MVClass.WaterActivity: return(Enumerable.Contains(MembersWaterActivity, mvCode)); case MVClass.PercentSaturation: return(Enumerable.Contains(MembersPercentSaturation, mvCode)); case MVClass.VolumeConcentration: return(Enumerable.Contains(MembersVolumeConcentration, mvCode)); case MVClass.WaterContent: return(Enumerable.Contains(MembersWaterContent, mvCode)); case MVClass.SpecificMassFlow: return(Enumerable.Contains(MembersSpecificMassFlow, mvCode)); case MVClass.MassFlow: return(Enumerable.Contains(MembersMassFlow, mvCode)); case MVClass.StdVolumetricFlow: return(Enumerable.Contains(MembersStdVolumetricFlow, mvCode)); case MVClass.VolumetricFlow: return(Enumerable.Contains(MembersVolumetricFlow, mvCode)); case MVClass.VolumetricConsumption: return(Enumerable.Contains(MembersVolumetricConsumption, mvCode)); case MVClass.VolumetricConsumptionTotal: return(Enumerable.Contains(MembersVolumetricConsumptionTotal, mvCode)); case MVClass.Pressure: return(Enumerable.Contains(MembersPressure, mvCode)); case MVClass.Resistance: return(Enumerable.Contains(MembersResistance, mvCode)); case MVClass.Current: return(Enumerable.Contains(MembersCurrent, mvCode)); case MVClass.Frequency: return(Enumerable.Contains(MembersFrequency, mvCode)); case MVClass.Voltage: return(Enumerable.Contains(MembersVoltage, mvCode)); case MVClass.Diameter: return(Enumerable.Contains(MembersDiameter, mvCode)); case MVClass.FilterContamination: return(Enumerable.Contains(MembersFilterContamination, mvCode)); case MVClass.LevelIndicator: return(Enumerable.Contains(MembersLevelIndicator, mvCode)); case MVClass.DifferentialPressure: return(Enumerable.Contains(MembersDifferentialPressure, mvCode)); } return(false); }
/// <summary> /// Determines whether measurement value code 1 is from different class as the specified measurement value code 2. /// </summary> /// <param name="mvCode1">The measurement value code 1.</param> /// <param name="mvCode2">The measurement value code 2.</param> /// <returns> /// <c>true</c> if they are from different measurement value classes; otherwise, <c>false</c>. /// </returns> public static bool IsDifferentClass(MVCode mvCode1, MVCode mvCode2) { return(GetClass(mvCode1) != GetClass(mvCode2)); }
/// <summary> /// Parameter constructor to set constant measurement value /// </summary> /// <param name="portId">1, 2, 3 or 0xFF</param> /// <param name="mvCode">Measurement value code</param> /// <param name="constValue">Output value</param> /// <param name="mode">1 = use all adjustment data, /// 2 = use only factory adjustment, /// 3 = use unadjusted</param> public SetConstantValueCmdParams_MV(byte portId, MVCode mvCode, float constValue, byte mode = 1) : base(portId, mode, (byte)mvCode, constValue) { }
/// <summary> /// Gets the measurement value class from a measurement value code. /// </summary> /// <param name="mvCode">The measurement value code.</param> /// <returns></returns> public static MVClass GetClass(MVCode mvCode) { if (Enumerable.Contains(MembersTemperature, mvCode)) { return(MVClass.Temperature); } if (Enumerable.Contains(MembersRelativeHumidity, mvCode)) { return(MVClass.RelativeHumidity); } if (Enumerable.Contains(MembersVelocity, mvCode)) { return(MVClass.Velocity); } if (Enumerable.Contains(MembersStdVelocity, mvCode)) { return(MVClass.StdVelocity); } if (Enumerable.Contains(MembersCO2, mvCode)) { return(MVClass.CO2); } if (Enumerable.Contains(MembersCO2Raw, mvCode)) { return(MVClass.CO2Raw); } if (Enumerable.Contains(MembersO2, mvCode)) { return(MVClass.O2); } if (Enumerable.Contains(MembersWaterVaporPartialPressure, mvCode)) { return(MVClass.WaterVaporPartialPressure); } if (Enumerable.Contains(MembersDewPoint, mvCode)) { return(MVClass.DewPoint); } if (Enumerable.Contains(MembersWetBulb, mvCode)) { return(MVClass.WetBulb); } if (Enumerable.Contains(MembersAbsoluteHumidity, mvCode)) { return(MVClass.AbsoluteHumidity); } if (Enumerable.Contains(MembersMixingRatio, mvCode)) { return(MVClass.MixingRatio); } if (Enumerable.Contains(MembersEnthalpy, mvCode)) { return(MVClass.Enthalpy); } if (Enumerable.Contains(MembersDewPointOrFrostPoint, mvCode)) { return(MVClass.DewPointOrFrostPoint); } if (Enumerable.Contains(MembersWaterActivity, mvCode)) { return(MVClass.WaterActivity); } if (Enumerable.Contains(MembersPercentSaturation, mvCode)) { return(MVClass.PercentSaturation); } if (Enumerable.Contains(MembersVolumeConcentration, mvCode)) { return(MVClass.VolumeConcentration); } if (Enumerable.Contains(MembersWaterContent, mvCode)) { return(MVClass.WaterContent); } if (Enumerable.Contains(MembersSpecificMassFlow, mvCode)) { return(MVClass.SpecificMassFlow); } if (Enumerable.Contains(MembersMassFlow, mvCode)) { return(MVClass.MassFlow); } if (Enumerable.Contains(MembersStdVolumetricFlow, mvCode)) { return(MVClass.StdVolumetricFlow); } if (Enumerable.Contains(MembersVolumetricFlow, mvCode)) { return(MVClass.VolumetricFlow); } if (Enumerable.Contains(MembersVolumetricConsumption, mvCode)) { return(MVClass.VolumetricConsumption); } if (Enumerable.Contains(MembersVolumetricConsumptionTotal, mvCode)) { return(MVClass.VolumetricConsumptionTotal); } if (Enumerable.Contains(MembersPressure, mvCode)) { return(MVClass.Pressure); } if (Enumerable.Contains(MembersResistance, mvCode)) { return(MVClass.Resistance); } if (Enumerable.Contains(MembersCurrent, mvCode)) { return(MVClass.Current); } if (Enumerable.Contains(MembersFrequency, mvCode)) { return(MVClass.Frequency); } if (Enumerable.Contains(MembersVoltage, mvCode)) { return(MVClass.Voltage); } if (Enumerable.Contains(MembersDiameter, mvCode)) { return(MVClass.Diameter); } if (Enumerable.Contains(MembersFilterContamination, mvCode)) { return(MVClass.FilterContamination); } if (Enumerable.Contains(MembersLevelIndicator, mvCode)) { return(MVClass.LevelIndicator); } if (Enumerable.Contains(MembersDifferentialPressure, mvCode)) { return(MVClass.DifferentialPressure); } return(MVClass.INVALID); }