Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="address"></param>
        /// <param name="realData"></param>
        /// <returns></returns>
        public static CommResultState ProcessReceived(
            byte[] data,
            out int address,
            out GRRealData realData
            )
        {
            address  = -1;
            realData = null;

            if (data == null || data.Length == 0)
            {
                return(CommResultState.NullData);
            }

            if (data.Length != 113)
            {
                return(CommResultState.LengthError);
            }

            if (data[4] != 0xA0 || data[5] != 0x1E)
            {
                return(CommResultState.DataError);
            }
            byte cachi, caclo;

            CRC16.CalculateCRC(data, 113 - 2, out cachi, out caclo);

            byte hi = data[113 - 1];
            byte lo = data[113 - 2];

            if (cachi != hi || caclo != lo)
            {
                return(CommResultState.CheckError);
            }

            byte[] innerData = GetReceivedInnerData(data);
            //int
            address = data[GRDef.ADDRESS_POS];

            GRRealData rd = GRRealData.Parse(innerData, address);

            //rd.FromAddress = address;

            //_realData = rd;
            realData = rd;
            //Singles.S.OutSideTemperature = _realData.OutSideTemp;

            //Utilities.frmPropertiesGrid f = new frmPropertiesGrid();
            //f.ShowMe( rd,"");
            return(CommResultState.Correct);
        }
Example #2
0
        /// <summary>
        /// return a grRealData or null
        /// </summary>
        /// <returns></returns>
        public override object ToValue()
        {
            byte[] data = _bytes;

            if (data == null || data.Length == 0)
            {
                _commResultState = CommResultState.NullData;
                return(null);
            }

            if (data.Length != 113)
            {
                _commResultState = CommResultState.LengthError;
                return(null);
            }

            // dev type and fc
            if (data[4] != 0xA0 || data[5] != 0x1E)
            {
                _commResultState = CommResultState.DataError;
                return(null);
            }

            byte cachi, caclo;

            CRC16.CalculateCRC(data, 113 - 2, out cachi, out caclo);

            byte hi = data[113 - 1];
            byte lo = data[113 - 2];

            if (cachi != hi || caclo != lo)
            {
                _commResultState = CommResultState.CheckError;
                return(null);
            }

            int address = -1;

            address = data[GRDef.ADDRESS_POS];

            byte[]     innerData = GRCommandMaker.GetReceivedInnerData(data);
            GRRealData realData  = GRRealData.Parse(innerData, address);

            if (realData != null)
            {
                _commResultState = CommResultState.Correct;
            }
            _value = realData;
            return(realData);
        }
Example #3
0
        /// <summary>
        /// 将 byte[] 转换成供热控制器的实时数据对象,
        /// </summary>
        /// <param name="datas">is innerDatas</param>
        /// <param name="fromAddress"></param>
        /// <returns></returns>
        static public GRRealData Parse(byte[] datas, int fromAddress)
        {
            ArgumentChecker.CheckNotNull(datas);
            Debug.Assert(datas.Length == 0x68, "Parse GRRealData"); //Decimal  104

            GRRealData rd = new GRRealData();


            rd._twoGiveBaseTemp = GetFloatValue(datas, 0 + 8);
            rd._DrangeSubSet    = GetFloatValue(datas, 4 + 8);
            rd._DrangeSet       = GetFloatValue(datas, 8 + 8);
            rd._outsideTemp     = GetFloatValue(datas, 12 + 8);
            rd._oneGiveTemp     = GetFloatValue(datas, 16 + 8);
            rd._oneBackTemp     = GetFloatValue(datas, 20 + 8);
            rd._twoGiveTemp     = GetFloatValue(datas, 24 + 8);
            rd._twoBackTemp     = GetFloatValue(datas, 28 + 8);
            rd._oneGivePress    = GetFloatValue(datas, 32 + 8);
            rd._oneBackPress    = GetFloatValue(datas, 36 + 8);
            rd._twoGivePress    = GetFloatValue(datas, 40 + 8);
            rd._twoBackPress    = GetFloatValue(datas, 44 + 8);

            rd._openDegree = GetByteValue(datas, 48 + 8);

            rd._WatBoxLevel = GetFloatValue(datas, 49 + 8);
            rd._oneInstant  = GetFloatValue(datas, 53 + 8);
            rd._twoInstant  = GetFloatValue(datas, 57 + 8);

            rd._oneAccum = GetULongValue(datas, 69 + 8);
            rd._twoAccum = GetULongValue(datas, 73 + 8);

            rd._warn1    = GetByteValue(datas, 86 + 8);
            rd._warn2    = GetByteValue(datas, 87 + 8);
            rd._state    = GetByteValue(datas, 88 + 8);
            rd._datetime = DateTime.Now;

            rd._twoPressCha = rd._twoGivePress - rd._twoBackPress;
            rd._grPumpState = GRPumpState.Parse(rd._state);
            rd._fromAddress = fromAddress;

            //int fromAddr=99;
            rd._grAlarmData = GRAlarmData.Parse(
                new byte[] { rd._warn1, rd._warn2 },
                fromAddress);

            return(rd);
        }
Example #4
0
        public void t_grRealDataParse()
        {
            string s = "21 58 44 00 A0 1E 68 00 07 03 0F 10 24 17 03 00 00 34 42 8F C2 F5 3D E1 7A 94 3E A6 D9 FA 40 AF 03 A7 42 AE 62 7A 42 40 D5 37 42 15 A0 22 42 E2 35 0C 3F 4B 5C EA 3E DC 12 DF 3E 63 D5 A9 3E 5A 00 00 00 00 2C A3 8E 43 00 00 00 00 00 00 00 00 00 00 00 00 B9 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 31 42 45";

            byte[]           bs  = CT.StringToBytes(s, null, StringFormat.Hex);
            GrRealDataParser t   = new GrRealDataParser(bs);
            object           obj = t.ToValue();

            Assert.IsNotNull(obj);
            GRRealData rd = obj as GRRealData;

            Assert.AreEqual(CFW.CommResultState.Correct, t.CommResultState);
            //Assert.AreEqual( rd.DT, DateTime.Parse("2007-09-09 1:2:3"));

            t.Bytes = null;
            obj     = t.ToValue();
            Assert.IsNull(obj);
            Assert.AreEqual(CFW.CommResultState.NullData, t.CommResultState);
        }
Example #5
0
        static public GRRealData Parse(DataRow r)
        {
            if (r == null)
            {
                return(null);
            }
            try
            {
                GRRealData rd = new GRRealData();
                rd._datetime        = Convert.ToDateTime(r["time"]);
                rd._oneGiveTemp     = Convert.ToSingle(r["oneGiveTemp"]);
                rd._oneBackTemp     = Convert.ToSingle(r["oneBackTemp"]);
                rd._twoGiveTemp     = Convert.ToSingle(r["twoGiveTemp"]);
                rd._twoBackTemp     = Convert.ToSingle(r["twoBackTemp"]);
                rd._outsideTemp     = Convert.ToSingle(r["outsideTemp"]);
                rd._twoGiveBaseTemp = Convert.ToSingle(r["twoGiveBaseTemp"]);
                rd._oneGivePress    = Convert.ToSingle(r["oneGivePress"]);
                rd._oneBackPress    = Convert.ToSingle(r["oneBackPress"]);
                rd._WatBoxLevel     = Convert.ToSingle(r["WatBoxLevel"]);
                rd._twoGivePress    = Convert.ToSingle(r["twoGivePress"]);
                rd._twoBackPress    = Convert.ToSingle(r["twoBackPress"]);
                rd._oneInstant      = Convert.ToSingle(r["oneInstant"]);
                rd._twoInstant      = Convert.ToSingle(r["twoInstant"]);
                rd._oneAccum        = (uint)Convert.ToInt32(r["oneAccum"]);
                rd._twoAccum        = (uint)Convert.ToInt32(r["twoAccum"]);
                rd._openDegree      = Convert.ToByte(r["openDegree"]);
                rd._twoPressCha     = Convert.ToSingle(r["twoPressCha"]);

                GRPumpState pumpState = GRPumpState.Parse(r);

                rd._grPumpState = pumpState;
                rd._grAlarmData = null;

                return(rd);
            }
            catch (Exception ex)
            {
                MsgBox.Show(ex.ToString());
                return(null);
            }
//            return null;
        }