Esempio n. 1
0
        /// <summary>
        /// 读取负载数据
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="data"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadLoadValue(int wAddr, ref CData data, out string er)
        {
            er = string.Empty;

            try
            {
                string CID   = "0F";
                string INFO  = string.Empty;
                string wCmd  = CalDataFromERS272Cmd(wAddr, CID, INFO);
                string rData = string.Empty;
                int    rLen  = C_LEN + 65;
                if (!SendCmdToERS272(wCmd, rLen, out rData, out er))
                {
                    return(false);
                }
                string temp = string.Empty;
                string rVal = string.Empty;
                if (!checkErrorCode(rData, out rVal, out temp))
                {
                    return(false);
                }

                /*
                 * 第1-64字节为各个通道的实时数据,
                 * 从第1通道开始,每个通道含8个字节数据
                 * 每通道的第1/2字节为负载电压值
                 * 第3/4字节为大电流通道的电流值
                 * 第5/6字节为LLC输入电压值
                 * 第7/8字节为通道状态信息
                 * 第65字节数据为逆变器状态信息。
                 */

                for (int i = 0; i < _maxCH; i++)
                {
                    string rCmd = rVal.Substring(i * 16, 16);                      //单通道数据

                    int byte0 = System.Convert.ToInt16(rCmd.Substring(0, 4), 16);  //负载电压值

                    int byte1 = System.Convert.ToInt16(rCmd.Substring(4, 4), 16);  //负载电流值

                    int byte2 = System.Convert.ToInt16(rCmd.Substring(8, 4), 16);  //输入电压值

                    int byte3 = System.Convert.ToInt16(rCmd.Substring(12, 4), 16); //通道状态信息

                    CCHData ch = new CCHData();

                    ch.volt = (double)byte0 / 20;      //电压(V)=2byte值 /20

                    ch.current = (double)byte1 / 1000; //电流(A)=2byte值 /1000

                    ch.input_ac = (double)byte2 / 20;  //电压(V)=2byte值 /20

                    ch.alarmInfo = string.Empty;

                    //通道状态信息

                    //bit0
                    if ((byte3 & (1 << 0)) == (1 << 0))
                    {
                        ch.ch_status.DC_DC = EDC.ON;
                    }
                    else
                    {
                        ch.ch_status.DC_DC = EDC.OFF;
                    }

                    //bit1
                    if ((byte3 & (1 << 1)) == (1 << 1))
                    {
                        ch.ch_status.LLC_AC = ELLC.OVP;
                        ch.alarmInfo       += "OVP;";
                    }
                    else
                    {
                        ch.ch_status.LLC_AC = ELLC.正常;
                    }

                    //bit2-bit3
                    int bit2_3 = (byte3 & 0xC) / 0x4;

                    if (bit2_3 == 0)
                    {
                        ch.ch_status.AC_STATUS = EAC.压;
                        ch.alarmInfo          += CLanguage.Lan("输入电压欠压") + ";";
                    }
                    if (bit2_3 == 0x1)
                    {
                        ch.ch_status.AC_STATUS = EAC.正常;
                    }
                    else if (bit2_3 == 0x10)
                    {
                        ch.ch_status.AC_STATUS = EAC.过压;
                        ch.alarmInfo          += CLanguage.Lan("输入电压过压") + ";";
                    }

                    //bit4
                    if ((byte3 & (1 << 4)) == (1 << 4))
                    {
                        ch.ch_status.OPP = EOPP.OPP;
                        ch.alarmInfo    += "OPP;";
                    }
                    else
                    {
                        ch.ch_status.OPP = EOPP.正常;
                    }

                    //bit5
                    if ((byte3 & (1 << 5)) == (1 << 5))
                    {
                        ch.ch_status.OTP = EOTP.OTP;
                        ch.alarmInfo    += "OTP;";
                    }
                    else
                    {
                        ch.ch_status.OTP = EOTP.正常;
                    }

                    //bit6-bit7
                    int bit6_7 = (byte3 & 0xC0) / 0x40;

                    if (bit6_7 == 0)
                    {
                        ch.ch_status.VBus = EVBus.压;
                        ch.alarmInfo     += CLanguage.Lan("直流母线电压欠压") + ";";
                    }
                    if (bit6_7 == 0x1)
                    {
                        ch.ch_status.VBus = EVBus.正常;
                    }
                    else if (bit6_7 == 0x10)
                    {
                        ch.ch_status.VBus = EVBus.过压;
                        ch.alarmInfo     += CLanguage.Lan("直流母线电压过压") + ";";
                    }

                    //bit8
                    if ((byte3 & (1 << 8)) == (1 << 8))
                    {
                        ch.ch_status.maxCur = EMaxCUR.过流;
                        ch.alarmInfo       += CLanguage.Lan("大电流通道过流") + ";";
                    }
                    else
                    {
                        ch.ch_status.maxCur = EMaxCUR.正常;
                    }

                    //bit9
                    if ((byte3 & (1 << 9)) == (1 << 9))
                    {
                        ch.ch_status.minCur = EMinCUR.过流;
                        ch.alarmInfo       += CLanguage.Lan("小电流通道过流") + ";";
                    }
                    else
                    {
                        ch.ch_status.minCur = EMinCUR.正常;
                    }

                    data.chan[i].volt      = ch.volt;
                    data.chan[i].current   = ch.current;
                    data.chan[i].ch_status = ch.ch_status;
                    data.chan[i].alarmInfo = ch.alarmInfo;
                    data.chan[i].input_ac  = ch.input_ac;
                }

                //逆变状态

                int byte4 = System.Convert.ToInt16(rVal.Substring(rVal.Length - 4, 4), 16); //通道状态信息

                data.alarmInfo = string.Empty;

                //bit0
                if ((byte4 & (1 << 0)) == (1 << 0))
                {
                    data.inv_status.OTP = EINVOTP.OTP;
                    data.alarmInfo     += "OTP";
                }
                else
                {
                    data.inv_status.OTP = EINVOTP.正常;
                }
                //bit1
                if ((byte4 & (1 << 1)) == (1 << 1))
                {
                    data.inv_status.AD = EINVAD.故障;
                    data.alarmInfo    += CLanguage.Lan("AD采样故障") + ";";
                }
                else
                {
                    data.inv_status.AD = EINVAD.正常;
                }

                //bit2-bit3
                int _bit2_3 = (byte4 & 0xC) / 0x4;

                if (_bit2_3 == 0)
                {
                    data.inv_status.ACBus = EINVACBus.压;
                    data.alarmInfo       += CLanguage.Lan("电网电压状态欠压") + ";";
                }
                if (_bit2_3 == 0x1)
                {
                    data.inv_status.ACBus = EINVACBus.正常;
                }
                else if (_bit2_3 == 0x10)
                {
                    data.inv_status.ACBus = EINVACBus.过压;
                    data.alarmInfo       += CLanguage.Lan("电网电压状态过压") + ";";
                }

                //bit4
                if ((byte4 & (1 << 4)) == (1 << 4))
                {
                    data.inv_status.Fan = EINVFan.故障;
                    data.alarmInfo     += CLanguage.Lan("风扇故障") + ";";
                }
                else
                {
                    data.inv_status.Fan = EINVFan.正常;
                }
                //bit5
                if ((byte4 & (1 << 5)) == (1 << 5))
                {
                    data.inv_status.Time = EINVTIME.超时;
                    data.alarmInfo      += CLanguage.Lan("超时故障") + ";";
                }
                else
                {
                    data.inv_status.Time = EINVTIME.正常;
                }

                //bit6-bit7
                int _bit6_7 = (byte4 & 0xC0) / 0x40;

                if (_bit6_7 == 0)
                {
                    data.inv_status.DCBus = EINVDCBus.压;
                    data.alarmInfo       += CLanguage.Lan("直流母线电压状态欠压") + ";";
                }
                if (_bit6_7 == 0x1)
                {
                    data.inv_status.DCBus = EINVDCBus.正常;
                }
                else if (_bit6_7 == 0x10)
                {
                    data.inv_status.DCBus = EINVDCBus.过压;
                    data.alarmInfo       += CLanguage.Lan("直流母线电压状态过压") + ";";
                }

                data.rCmd = rData;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 读取负载数据
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="data"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadLoadValue(int wAddr, ref CData data, out string er)
        {
            er = string.Empty;

            try
            {
                string CID = "0F";

                string INFO = string.Empty;

                string wCmd = CalDataFromELCmd(wAddr, CID, INFO);

                string rData = string.Empty;

                int rLen = C_LEN + 97;

                if (!SendCmdToELoad(wCmd, rLen, out rData, out er))
                {
                    return(false);
                }

                string temp = string.Empty;

                string rVal = string.Empty;

                if (!ReturnResult(rData, out rVal, out temp))
                {
                    return(false);
                }

                for (int i = 0; i < _maxCH; i++)
                {
                    int byte0 = System.Convert.ToInt16(rVal.Substring(i * 12, 4), 16);     //1-2Bytes:电压值

                    int byte1 = System.Convert.ToInt16(rVal.Substring(i * 12 + 4, 4), 16); //3-4:电流值

                    int byte2 = System.Convert.ToInt16(rVal.Substring(i * 12 + 8, 4), 16); //5-6状态信息

                    double vol = (double)byte0 / 20;

                    double curr = (double)byte1 / 100;

                    data.chan[i].volt = vol;

                    data.chan[i].current = curr;

                    data.chan[i].alarmInfo = string.Empty;

                    //通道状态信息

                    //bit0
                    if ((byte2 & (1 << 0)) == (1 << 0))
                    {
                        data.chan[i].ch_status.DC_DC = EDC.ON;
                    }
                    else
                    {
                        data.chan[i].ch_status.DC_DC = EDC.OFF;
                    }

                    //bit1
                    if ((byte2 & (1 << 1)) == (1 << 1))
                    {
                        data.chan[i].ch_status.LLC_AC = ELLC.OVP;
                        data.chan[i].alarmInfo       += "OVP;";
                    }
                    else
                    {
                        data.chan[i].ch_status.LLC_AC = ELLC.正常;
                    }

                    //bit2-bit3
                    int bit2_3 = (byte2 & 0xC) / 0x4;

                    if (bit2_3 == 0)
                    {
                        data.chan[i].ch_status.AC_STATUS = EAC.压;
                        data.chan[i].alarmInfo          += CLanguage.Lan("输入电压欠压") + ";";
                    }
                    if (bit2_3 == 0x1)
                    {
                        data.chan[i].ch_status.AC_STATUS = EAC.正常;
                    }
                    else if (bit2_3 == 0x10)
                    {
                        data.chan[i].ch_status.AC_STATUS = EAC.过压;
                        data.chan[i].alarmInfo          += CLanguage.Lan("输入电压过压") + ";";
                    }

                    //bit4
                    if ((byte2 & (1 << 4)) == (1 << 4))
                    {
                        data.chan[i].ch_status.OPP = EOPP.OPP;
                        data.chan[i].alarmInfo    += "OPP;";
                    }
                    else
                    {
                        data.chan[i].ch_status.OPP = EOPP.正常;
                    }

                    //bit5
                    if ((byte2 & (1 << 5)) == (1 << 5))
                    {
                        data.chan[i].ch_status.OTP = EOTP.OTP;
                        data.chan[i].alarmInfo    += "OTP;";
                    }
                    else
                    {
                        data.chan[i].ch_status.OTP = EOTP.正常;
                    }

                    //bit6-bit7
                    int bit6_7 = (byte2 & 0xC0) / 0x40;

                    if (bit6_7 == 0)
                    {
                        data.chan[i].ch_status.VBus = EVBus.压;
                        data.chan[i].alarmInfo     += CLanguage.Lan("直流母线电压欠压") + ";";
                    }
                    if (bit6_7 == 0x1)
                    {
                        data.chan[i].ch_status.VBus = EVBus.正常;
                    }
                    else if (bit6_7 == 0x10)
                    {
                        data.chan[i].ch_status.VBus = EVBus.过压;
                        data.chan[i].alarmInfo     += CLanguage.Lan("直流母线电压过压") + ";";
                    }

                    //bit8
                    if ((byte2 & (1 << 8)) == (1 << 8))
                    {
                        data.chan[i].ch_status.maxCur = EMaxCUR.过流;
                        data.chan[i].alarmInfo       += CLanguage.Lan("大电流通道过流") + ";";
                    }
                    else
                    {
                        data.chan[i].ch_status.maxCur = EMaxCUR.正常;
                    }

                    //bit9
                    if ((byte2 & (1 << 9)) == (1 << 9))
                    {
                        data.chan[i].ch_status.minCur = EMinCUR.过流;
                        data.chan[i].alarmInfo       += CLanguage.Lan("小电流通道过流") + ";";
                    }
                    else
                    {
                        data.chan[i].ch_status.minCur = EMinCUR.正常;
                    }
                }

                data.alarmInfo = string.Empty;

                string strInvStatus = Convert.ToString(Convert.ToInt16(rData.Substring(96 * 2, 2), 16), 2);

                strInvStatus = strInvStatus.PadLeft(8, '0');

                CINVSTAT inverStatus = new CINVSTAT
                {
                    OTP = strInvStatus.Substring(0, 1) == "1" ? EINVOTP.OTP : EINVOTP.正常,
                    AD  = strInvStatus.Substring(1, 1) == "1" ? EINVAD.故障 : EINVAD.正常
                };

                if (inverStatus.OTP != EINVOTP.正常)
                {
                    data.alarmInfo += "OTP;";
                }
                if (inverStatus.AD != EINVAD.正常)
                {
                    data.alarmInfo += "AD;";
                }

                if (strInvStatus.Substring(2, 2) == "00")
                {
                    inverStatus.ACBus = EINVACBus.压;
                    data.alarmInfo   += "欠压1;";
                }
                else if (strInvStatus.Substring(2, 2) == "10")
                {
                    inverStatus.ACBus = EINVACBus.过压;
                    data.alarmInfo   += "过压2;";
                }
                else
                {
                    inverStatus.ACBus = EINVACBus.正常;
                }

                inverStatus.Fan = strInvStatus.Substring(4, 1) == "1" ? EINVFan.故障 : EINVFan.正常;

                inverStatus.OTP = strInvStatus.Substring(5, 1) == "1" ? EINVOTP.OTP : EINVOTP.正常;

                if (inverStatus.Fan != EINVFan.正常)
                {
                    data.alarmInfo += "Fan;";
                }
                if (inverStatus.OTP != EINVOTP.正常)
                {
                    data.alarmInfo += "OTP;";
                }

                if (strInvStatus.Substring(6, 2) == "00")
                {
                    inverStatus.DCBus = EINVDCBus.压;
                    data.alarmInfo   += "欠压1;";
                }
                else if (strInvStatus.Substring(6, 2) == "10")
                {
                    inverStatus.DCBus = EINVDCBus.过压;
                    data.alarmInfo   += "过压2;";
                }
                else
                {
                    inverStatus.DCBus = EINVDCBus.正常;
                }

                if (data.alarmInfo == string.Empty)
                {
                    data.alarmInfo = "正常";
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }