Exemple #1
0
        public static HistoryRecord Parse( byte[] datas )
        {
            HistoryRecord r = new HistoryRecord();

            r._fromAddress = datas[ ADDRESS_POS ];

            r._beginDateTime = new DateTime(
                BCDConvert.BCDToDec ( datas[ BEGIN_DATETIME_BEGIN_POS + 0 ] ) + 2000,
                BCDConvert.BCDToDec ( datas[ BEGIN_DATETIME_BEGIN_POS + 1 ] ),
                BCDConvert.BCDToDec ( datas[ BEGIN_DATETIME_BEGIN_POS + 2 ] ),
                BCDConvert.BCDToDec ( datas[ BEGIN_DATETIME_BEGIN_POS + 3 ] ),
                BCDConvert.BCDToDec ( datas[ BEGIN_DATETIME_BEGIN_POS + 4 ] ),
                0 );

            r._endDatetTiem = new DateTime(
                BCDConvert.BCDToDec ( datas[ END_DATETIME_BEGIN_POS + 0 ] ) + 2000,
                BCDConvert.BCDToDec ( datas[ END_DATETIME_BEGIN_POS + 1 ] ),
                BCDConvert.BCDToDec ( datas[ END_DATETIME_BEGIN_POS + 2 ] ),
                BCDConvert.BCDToDec ( datas[ END_DATETIME_BEGIN_POS + 3 ] ),
                BCDConvert.BCDToDec ( datas[ END_DATETIME_BEGIN_POS + 4 ] ),
                0 );

            // ��ȡ��ˮ��
            //
            // �磺byte[] {0x00 0x01 0xE2 0x40} ��ʾ 123456��
            // ʹ�õ��Ǹ�λ��ǰ��λ�ں󣬽���ת��Ϊ��λ��ǰ��λ�ں���ʽ��
            // ��ʹ��BitConvert����ת��
            //
            byte[] usedWQ = new byte[4];
            Array.Copy( datas, USED_WATER_QUANTITY_BEGIN_POS, usedWQ, 0, 4 );
            Array.Reverse( usedWQ );

            r._usedWaterQuantity = BitConverter.ToInt32(datas, USED_WATER_QUANTITY_BEGIN_POS );

            return r;
        }
Exemple #2
0
        static public HistoryRecord Parse(byte[] datas)
        {
            HistoryRecord r = new HistoryRecord();

            r._fromAddress = datas[ADDRESS_POS];

            r._beginDateTime = new DateTime(
                BCDConvert.BCDToDec(datas[BEGIN_DATETIME_BEGIN_POS + 0]) + 2000,
                BCDConvert.BCDToDec(datas[BEGIN_DATETIME_BEGIN_POS + 1]),
                BCDConvert.BCDToDec(datas[BEGIN_DATETIME_BEGIN_POS + 2]),
                BCDConvert.BCDToDec(datas[BEGIN_DATETIME_BEGIN_POS + 3]),
                BCDConvert.BCDToDec(datas[BEGIN_DATETIME_BEGIN_POS + 4]),
                0);

            r._endDatetTiem = new DateTime(
                BCDConvert.BCDToDec(datas[END_DATETIME_BEGIN_POS + 0]) + 2000,
                BCDConvert.BCDToDec(datas[END_DATETIME_BEGIN_POS + 1]),
                BCDConvert.BCDToDec(datas[END_DATETIME_BEGIN_POS + 2]),
                BCDConvert.BCDToDec(datas[END_DATETIME_BEGIN_POS + 3]),
                BCDConvert.BCDToDec(datas[END_DATETIME_BEGIN_POS + 4]),
                0);

            // 获取用水量
            //
            // 如:byte[] {0x00 0x01 0xE2 0x40} 表示 123456,
            // 使用的是高位在前低位在后,将其转换为低位在前高位在后形式,
            // 再使用BitConvert进行转换
            //
            byte[] usedWQ = new byte[4];
            Array.Copy(datas, USED_WATER_QUANTITY_BEGIN_POS, usedWQ, 0, 4);
            Array.Reverse(usedWQ);

            r._usedWaterQuantity = BitConverter.ToInt32(datas, USED_WATER_QUANTITY_BEGIN_POS);

            return(r);
        }