示例#1
0
        /// <summary>
        /// 读取历史数据部分
        /// </summary>
        /// <param name="data"></param>
        /// <param name="refValue"></param>
        private bool Read_His(byte[] bs, ref object refValue)
        {
            try
            {
                if (bs == null || bs.Length < 32)
                {
                    return(false);
                }
                // TODO: 2012-04-24
                // System.IndexOutOfRangeException: 索引超出了数组界限。
                //
                //

                //记录号
                noRec = bs[7] * 256 + bs[8];
                //日期时间
                string Date = "20" + bs[9].ToString("x2") + "-" + bs[10].ToString("x") + "-" + bs[11].ToString("x");
                string Time = bs[12].ToString("x") + ":" + bs[13].ToString("x2") + ":" + bs[14].ToString("x2");
                datetime = Date + " " + Time;

                //            if (datetime.
                // TODO: Added 07-07-16 datetime error
                //
                try
                {
                    DateTime dt = DateTime.Parse(datetime);
                }
                catch (Exception ex)
                {
                    SaveException(bs, ex);
                    //                System.Diagnostics.Debug.Assert( false, datetime );
                    refValue = null;
                    return(false);
                }
                //闸前水位
                beforeLevel = bs[15] * 256 + bs[16];
                //闸后水位
                behindLevel = bs[17] * 256 + bs[18];
                //实际闸高
                height = bs[19] * 256 + bs[20];
                //瞬时流量
                if (bs[21] == 0xFF && bs[22] == 0xFF)
                {
                    flux = 9999;//错误瞬时流量
                }
                else
                {
                    flux = (bs[21] * 256 + bs[22]) / 100f;//正确瞬时流量
                }
                //剩余水量
                string strReWater = "";
                for (int i = 23; i < 27; i++)//23,24,25,26
                {
                    strReWater += bs[i].ToString("x2");
                }
                reWater = Convert.ToInt32(strReWater, 16);
                //总用水量
                string strTuWater = "";
                for (int i = 27; i < 31; i++)//27,28,29,30
                {
                    strTuWater += bs[i].ToString("x2");
                }
                tuWater = Convert.ToInt32(strTuWater, 16);
                //供电状态
                if (bs[31] == 0x00)
                {
                    power = "市电状态";
                }
                if (bs[31] == 0xFF)
                {
                    power = "电池状态";
                }
                //开关锁状态
                switch (bs[32])
                {
                case 0x00:
                    lock_OC = "强关状态";
                    break;

                case 0x01:
                    lock_OC = "强开状态";
                    break;

                case 0x02:
                    lock_OC = "正常状态";
                    break;
                }
                refValue = new Gate_His(comAdr, noRec, datetime, beforeLevel, behindLevel, height, flux, reWater, tuWater, power, lock_OC);
                return(true);
            }
            catch (Exception ex)
            {
                SaveException(bs, ex);
                return(false);
            }
        }
示例#2
0
文件: GateReader.cs 项目: hkiaipc/lx
        /// <summary>
        /// ��ȡ��ʷ���ݲ���
        /// </summary>
        /// <param name="data"></param>
        /// <param name="refValue"></param>
        private bool Read_His(byte[] bs, ref object refValue)
        {
            try
            {
                if (bs == null || bs.Length < 32)
                {
                    return false;
                }
                // TODO: 2012-04-24
                // System.IndexOutOfRangeException: ����������������ޡ�
                //
                //

                //��¼��
                noRec = bs[7] * 256 + bs[8];
                //����ʱ��
                string Date = "20" + bs[9].ToString("x2") + "-" + bs[10].ToString("x") + "-" + bs[11].ToString("x");
                string Time = bs[12].ToString("x") + ":" + bs[13].ToString("x2") + ":" + bs[14].ToString("x2");
                datetime = Date + " " + Time;

                //            if (datetime.
                // TODO: Added 07-07-16 datetime error
                //
                try
                {
                    DateTime dt = DateTime.Parse(datetime);
                }
                catch (Exception ex)
                {
                    SaveException(bs, ex);
                    //                System.Diagnostics.Debug.Assert( false, datetime );
                    refValue = null;
                    return false;
                }
                //բǰˮλ
                beforeLevel = bs[15] * 256 + bs[16];
                //բ��ˮλ
                behindLevel = bs[17] * 256 + bs[18];
                //ʵ��բ��
                height = bs[19] * 256 + bs[20];
                //˲ʱ����
                if (bs[21] == 0xFF && bs[22] == 0xFF)
                {
                    flux = 9999;//����˲ʱ����
                }
                else
                {
                    flux = (bs[21] * 256 + bs[22]) / 100f;//��ȷ˲ʱ����
                }
                //ʣ��ˮ��
                string strReWater = "";
                for (int i = 23; i < 27; i++)//23,24,25,26
                {
                    strReWater += bs[i].ToString("x2");
                }
                reWater = Convert.ToInt32(strReWater, 16);
                //����ˮ��
                string strTuWater = "";
                for (int i = 27; i < 31; i++)//27,28,29,30
                {
                    strTuWater += bs[i].ToString("x2");
                }
                tuWater = Convert.ToInt32(strTuWater, 16);
                //����״̬
                if (bs[31] == 0x00) { power = "�е�״̬"; }
                if (bs[31] == 0xFF) { power = "���״̬"; }
                //������״̬
                switch (bs[32])
                {
                    case 0x00:
                        lock_OC = "ǿ��״̬";
                        break;
                    case 0x01:
                        lock_OC = "ǿ��״̬";
                        break;
                    case 0x02:
                        lock_OC = "����״̬";
                        break;
                }
                refValue = new Gate_His(comAdr, noRec, datetime, beforeLevel, behindLevel, height, flux, reWater, tuWater, power, lock_OC);
                return true;
            }
            catch (Exception ex)
            {
                SaveException(bs, ex);
                return false;
            }
        }