Beispiel #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);
        }
Beispiel #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);
        }