示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }