예제 #1
0
파일: PumpReader.cs 프로젝트: leadscloud/lx
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dataLength"></param>
        /// <param name="refValue"></param>
        public PumpProcessor(byte[] data, int Len, ref object oPars)
        {
            //进行校验
            //
            if (Len <= 2)
            {
                oPars     = null;
                _dataFlag = DataFlag.LENGTH_ERROR;
                return;
            }

            //进行校验
            byte[] DataVal = new byte[Len - 2];
            for (int i = 0; i < Len - 2; i++)
            {
                DataVal[i] = data[i];
            }
            crc = CRC.CRC16(DataVal);

            //分析数据
            if (data[Len - 2] == crc[0] && data[Len - 1] == crc[1])
            {
                address = (int)data[3];//得到站号
                switch (data[5])
                {
                //实时数据
                case PumpDefine.FCDefine.FC_READREAL:
                {
                    // 正常数据长度应该为46
                    // 有可能上传长度为28且CRC校验正确的数据
                    //
                    if (data.Length == 46)
                    {
                        //Read_Rlt(data, ref refValue);
                        PumpRealData prd = ParseRealData(data);
                        oPars = prd;
                    }
                    else
                    {
                        _dataFlag = DataFlag.LENGTH_ERROR;
                        oPars     = null;
                        return;
                    }
                }
                break;
                }
                this._dataFlag = DataFlag.OK;
            }
            else
            {
                this._dataFlag = DataFlag.CRC_ERROR;
                oPars          = null;
            }
        }
예제 #2
0
파일: frmMain.cs 프로젝트: hkiaipc/lx
        /// <summary>
        /// 
        /// </summary>
        /// <param name="readpar"></param>
        /// <param name="pump_view"></param>
        private void UpdatePumpListView(PumpRealData readpar, ListView listView)
        {
            //��ȡ����
            //
            PumpRealData pump_rlt = (PumpRealData)readpar;

            //��ȡ��վ����
            //
            string Address = string.Empty;

            for (int i = 0; i < InfoList_All.Count; i++)
            {
                DeviceInfo info = (DeviceInfo)InfoList_All[i];
                if (info.DeviceAddress == pump_rlt.ComAdr && info.DeviceKind == "Pump")
                {
                    Address = info.Address;
                    break;
                }
            }
            if (Address == string.Empty)
                _log.AddCommon(new LogItem("Not find address", pump_rlt.ComAdr));

            //��ǰ����ʱ��
            //
            string strDateTime = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();

            //��ʾ����
            //
            for (int i = 0; i < listView.Items.Count; i++)
            {
                if (listView.Items[i].Text == Address)
                {
                    //����ʱ��, ȡDateTime.Now
                    //
                    listView.Items[i].SubItems[1].Text = strDateTime;

                    //����
                    //
                    listView.Items[i].SubItems[2].Text = pump_rlt.Flux.ToString();

                    //��
                    //
                    listView.Items[i].SubItems[3].Text = pump_rlt.Efficiency.ToString();

                    //ʣ��ˮ��
                    //
                    listView.Items[i].SubItems[4].Text = pump_rlt.RemainWater.ToString();

                    //����ˮ��
                    //
                    listView.Items[i].SubItems[5].Text = pump_rlt.TotalWater.ToString();

                    //��ǰ״̬
                    //
                    listView.Items[i].SubItems[6].Text = pump_rlt.Run;

                    //ǿ��״̬
                    //
                    listView.Items[i].SubItems[7].Text = pump_rlt.ForceRun;

                    //�񶯴�����״̬
                    //
                    listView.Items[i].SubItems[8].Text = pump_rlt.Vibrate;

                    //��Դ����״̬
                    //
                    listView.Items[i].SubItems[9].Text = pump_rlt.Power;

                    // fore color
                    //
                    if (pump_rlt.Vibrate == DeviceInfoManager.TEXT_RUNSTATE_VIBRATE)
                    {
                        listView.Items[i].ForeColor = Config.Default.PumpVibrationColor;
                        if (Config.Default.SoundFile != null)
                            WavePlayer.PlaySimple(Config.Default.SoundFile);
                    }
                    else
                    {
                        listView.Items[i].ForeColor = Config.Default.DefaultForeColor;
                    }
                    break;
                }
            }
        }
예제 #3
0
파일: frmMain.cs 프로젝트: hkiaipc/lx
 /// <summary>
 /// 
 /// </summary>
 private void TestSavePumpHis()
 {
     //PumpHistoryData d = new PumpHistoryData(1,2,
     object rd = new PumpRealData(1, 2, 3, 4, 5, "11", "force", "vib", "pow", 1, "run", "stp", 9);
     Db.SavePumpHistoryData(ref rd);
 }
예제 #4
0
파일: frmMain.cs 프로젝트: hkiaipc/lx
 /// <summary>
 /// 
 /// </summary>
 private void TestSavePumpData()
 {
     object data = new PumpRealData(79, 1, 1, 1, 1, "run", "force", "vib", "pow", 1, "2011-1-1", "2011-1-1", 1);
     Db.SavePumpHistoryData(ref data);
 }
예제 #5
0
파일: PumpReader.cs 프로젝트: hkiaipc/lx
        /// <summary>
        /// ��ȡʵʱ���ݲ���
        /// </summary>
        /// <param name="data"></param>
        /// <param name="refValue"></param>
        //private void ParseRealData(byte[] data, ref object refValue)
        private PumpRealData ParseRealData(byte[] Data)
        {
            //����״̬
            switch (Data[7])
            {
                case 0x50:
                    run = "������״̬";
                    break;
                case 0x5A:
                    run = "��������״̬";
                    break;
                case 0x5B:
                    run = "������״̬";
                    break;
                default:
                    run = string.Format("δ֪״̬(0x{0})", Data[7].ToString("X"));
                    break;
            }
            //ʣ��ˮ��
            string strReWater = "";
            for (int i = 8; i < 12; i++)//8,9,10,11
            {
                strReWater += Data[i].ToString("x2");
            }
            reWater = Convert.ToInt32(strReWater, 16);
            //����ˮ��
            string strTuWater = "";
            for (int i = 12; i < 16; i++)//12,13,14,15
            {
                strTuWater += Data[i].ToString("x2");
            }
            tuWater = Convert.ToInt32(strTuWater, 16);
            //����
            flux = (Data[16] * 256 + Data[17]);
            //��
            efficiency = (int)Data[18];

            // 2007-09-18 Modify data[19] == 0x38
            //
            //ǿ��״̬
            //			if(data[19]==0x0){forceRun="����ǿ��";}
            //			if(data[19]==0x1){forceRun="��ֹǿ��";}
            byte forceRunByte = Data[19];
            if (forceRunByte == 0x00)
                forceRun = "����ǿ��";
            else if (forceRunByte == 0x01)
                forceRun = "��ֹǿ��";
            else
                forceRun = string.Format("δ֪(0x{0})", forceRunByte.ToString("X2"));

            //�񶯴�����״̬
            if (Data[20] == 0x1) { vibrate = "��״̬"; }
            if (Data[20] == 0x0) { vibrate = "����״̬"; }
            //����״̬
            if (Data[21] == 0x0) { power = "�е�״̬"; }
            if (Data[21] == 0x1) { power = "���״̬"; }
            //��¼��
            recordNO = (int)(Data[22] * 256 + Data[23]);
            //�ܼ�¼��
            totalRecordCount = (int)(Data[24] * 256 + Data[25]);

            //			//��¼��
            //			noRec=(int)(data[26] * 256 + data[27]);
            if (Data.Length > 30)
            {
                //�������ʱ��
                string RunDate = "20" + Data[30].ToString("x2") + "-" + Data[29].ToString("x") + "-" + Data[28].ToString("x");
                string RunTime = Data[33].ToString("x") + ":" + Data[32].ToString("x2") + ":" + Data[31].ToString("x2");
                runDateTime = RunDate + " " + RunTime;
                //ͣ������ʱ��
                string stopDate = "20" + Data[36].ToString("x2") + "-" + Data[35].ToString("x") + "-" + Data[34].ToString("x");
                string stopTime = Data[39].ToString("x") + ":" + Data[38].ToString("x2") + ":" + Data[37].ToString("x2");
                stpDateTime = stopDate + " " + stopTime;
                //�ڼ���ˮ��
                string strUsWater = "";
                for (int i = 40; i < 44; i++)//40,41,42,43
                {
                    strUsWater += Data[i].ToString("x2");
                }
                usWater = Convert.ToInt32(strUsWater, 16);
            }
            PumpRealData rlt = new PumpRealData(address, flux, efficiency, reWater, tuWater, run, forceRun, vibrate,
                power, recordNO, runDateTime, stpDateTime, usWater);
            rlt.OriginalData = (byte[])Data.Clone();
            //refValue = rlt;
            return rlt;
        }
예제 #6
0
파일: PumpReader.cs 프로젝트: leadscloud/lx
        /// <summary>
        /// 读取实时数据部分
        /// </summary>
        /// <param name="data"></param>
        /// <param name="refValue"></param>
        //private void ParseRealData(byte[] data, ref object refValue)
        private PumpRealData ParseRealData(byte[] Data)
        {
            //运行状态
            switch (Data[7])
            {
            case 0x50:
                run = "无运行状态";
                break;

            case 0x5A:
                run = "正常运行状态";
                break;

            case 0x5B:
                run = "振动运行状态";
                break;

            default:
                run = string.Format("未知状态(0x{0})", Data[7].ToString("X"));
                break;
            }
            //剩余水量
            string strReWater = "";

            for (int i = 8; i < 12; i++)//8,9,10,11
            {
                strReWater += Data[i].ToString("x2");
            }
            reWater = Convert.ToInt32(strReWater, 16);
            //已用水量
            string strTuWater = "";

            for (int i = 12; i < 16; i++)//12,13,14,15
            {
                strTuWater += Data[i].ToString("x2");
            }
            tuWater = Convert.ToInt32(strTuWater, 16);
            //流量
            flux = (Data[16] * 256 + Data[17]);
            //效率
            efficiency = (int)Data[18];

            // 2007-09-18 Modify data[19] == 0x38
            //
            //强启状态
            //			if(data[19]==0x0){forceRun="允许强启";}
            //			if(data[19]==0x1){forceRun="禁止强启";}
            byte forceRunByte = Data[19];

            if (forceRunByte == 0x00)
            {
                forceRun = "允许强启";
            }
            else if (forceRunByte == 0x01)
            {
                forceRun = "禁止强启";
            }
            else
            {
                forceRun = string.Format("未知(0x{0})", forceRunByte.ToString("X2"));
            }

            //振动传感器状态
            if (Data[20] == 0x1)
            {
                vibrate = "振动状态";
            }
            if (Data[20] == 0x0)
            {
                vibrate = "无振状态";
            }
            //供电状态
            if (Data[21] == 0x0)
            {
                power = "市电状态";
            }
            if (Data[21] == 0x1)
            {
                power = "电池状态";
            }
            //记录号
            recordNO = (int)(Data[22] * 256 + Data[23]);
            //总记录数
            totalRecordCount = (int)(Data[24] * 256 + Data[25]);

            //			//记录号
            //			noRec=(int)(data[26] * 256 + data[27]);
            if (Data.Length > 30)
            {
                //启泵日期时间
                string RunDate = "20" + Data[30].ToString("x2") + "-" + Data[29].ToString("x") + "-" + Data[28].ToString("x");
                string RunTime = Data[33].ToString("x") + ":" + Data[32].ToString("x2") + ":" + Data[31].ToString("x2");
                runDateTime = RunDate + " " + RunTime;
                //停泵日期时间
                string stopDate = "20" + Data[36].ToString("x2") + "-" + Data[35].ToString("x") + "-" + Data[34].ToString("x");
                string stopTime = Data[39].ToString("x") + ":" + Data[38].ToString("x2") + ":" + Data[37].ToString("x2");
                stpDateTime = stopDate + " " + stopTime;
                //期间用水量
                string strUsWater = "";
                for (int i = 40; i < 44; i++)//40,41,42,43
                {
                    strUsWater += Data[i].ToString("x2");
                }
                usWater = Convert.ToInt32(strUsWater, 16);
            }
            PumpRealData rlt = new PumpRealData(address, flux, efficiency, reWater, tuWater, run, forceRun, vibrate,
                                                power, recordNO, runDateTime, stpDateTime, usWater);

            rlt.OriginalData = (byte[])Data.Clone();
            //refValue = rlt;
            return(rlt);
        }