Example #1
0
        /// <summary>
        /// 立即采集供热控制器实时数据
        /// </summary>
        private void CollGRRealData()
        {
            string stName = GetSelectStationName();

            if (stName == null || stName.Length == 0)
            {
                return;
            }
            GRStation grSt = Singles.S.GRStsCollection.GetGRStation(stName);

            if (grSt != null)
            {
                string remoteIP = grSt.DestinationIP;
                string serverIP = grSt.ServerIP;
                if (serverIP == XGConfig.Default.ServerIP)
                {
                    if (IsConnected(remoteIP))
                    {
                        GRRealDataCommand cmd = new GRRealDataCommand(grSt);
                        Task t = new Task(cmd, new ImmediateTaskStrategy());
                        Singles.S.TaskScheduler.Tasks.Add(t);
                        frmControlProcess f = new frmControlProcess(t);
                        f.ShowDialog();
                    }
                    else
                    {
                        MsgBox.Show(string.Format("站点 {0} 尚未与中心建立连接", grSt.StationName));
                    }
                }
                else
                {
                    MsgBox.Show(string.Format("站点 {0} 不连接到本台服务器,不能执行操作", grSt.StationName));
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="remoteIP"></param>
        /// <param name="address"></param>
        private void GRCollRealData(string remoteIP, int address)
        {
            GRStation st = GetGRStation(remoteIP, address);

            if (st != null)
            {
                GRRealDataCommand cmd = new GRRealDataCommand(st);
//                Task t = new Task( cmd, new ImmediateTaskStrategy () );
////                t.BeforeExecuteTask += new EventHandler(t_BeforeExecuteTask);
////                t.AfterExecuteTask  += new EventHandler(t_AfterExecuteTask);
//                Singles.S.TaskScheduler.Tasks.Add( t );
//
//                frmControlProcess f = new frmControlProcess( t );
//                f.ShowDialog();
                this.CreateImmediateTaskAndExecute(cmd);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="task"></param>
//        private void Process( string remoteIP, Task task )
        private void Process(Task task)
        {
            ArgumentChecker.CheckNotNull(task);

            string      remoteIP = task.CommCmd.Station.DestinationIP;
            CommCmdBase cmd      = task.CommCmd;
            Station     st       = cmd.Station;

            CommResultState commResultState = task.LastCommResultState;
            string          s = null;

            if (XGConfig.Default.LogCommIO)
            {
                if (s == null)
                {
                    //s = GetLogString( commPort, task );
                    s = GetLogString(remoteIP, task);
                }

                FileLog.CommIO.Add(s);
                if (XGConfig.Default.ShowLogForm)
                {
                    frmLogs.Default.AddLog(s);
                }
            }

            // log fail comm
            // 所有通讯失败情况在此处理
            //
            if (commResultState != CommResultState.Correct)
            {
                if (XGConfig.Default.LogCommFail)
                {
                    if (s == null)
                    {
                        s = GetLogString(remoteIP, task);
                    }

                    if (XGConfig.Default.LogCommFail)
                    {
                        FileLog.CommFail.Add(s);
                    }

                    if (XGConfig.Default.ShowLogForm)
                    {
                        //frmLogs.FailForm.AddLog( s );
                        frmLogs.Default.AddLogCommFail(s);
                    }
                }

                ProcessFreeData(task.CommCmd.Station.DestinationIP, task.LastReceived);  //, task);
                return;
            }

            // 以下只是处理通讯成功的情况
            //

            // 4. XG real total count command
            //
            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand readCountCmd = cmd as ReadTotalCountCommand;
                ProcessReadTotalCountCmd(readCountCmd, task);
            }

            // 5. XG real record
            //
            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand readRecordCmd = cmd as ReadRecordCommand;
                ProcessReadRecordCmd(readRecordCmd);
            }

            // 6. XG clear record command
            //

            // 读取供热控制器实时数据
            // 1. GR real data command
            //
            if (cmd is GRRealDataCommand)
            {
                GRRealDataCommand realDataCmd = ( GRRealDataCommand )cmd;
                //ProcessGRRealDataCmd( commPort, realDataCmd );
                ProcessGRRealDataCmd(remoteIP, realDataCmd);
            }

            // 2. GR set out side temperature command
            //
            if (cmd is GRSetOutSideTempCommand)
            {
                GRSetOutSideTempCommand c = (GRSetOutSideTempCommand)cmd;
                ProcessGRSetOutSideTempCmd(c);
            }

            // 3. GR remote set control params
            //
        }
Example #4
0
        /// <summary>
        /// 解析采集供热实时数据命令,
        /// parse xgdata read
        /// </summary>
        /// <returns></returns>
        private static TasksCollection  ResolveGRRealDataTaskFromDB()
        {
            string FailMsg = "Fail list:\r\n";
            //TODO: ResolveGRRealDataTaskFromDB
            //
            // 2007.03.10 Modify not use client flag, use serverIP diff local or remote gprs module,
            //
            //            string sql = string.Format(
            //                "select * from v_gprs_gr_xg where client = {0}",
            //                XGConfig.Default.ClientAorB  );
            string sql = "select * from v_gprs_gr_xg";

            DataSet         ds    = XGDB.DbClient.Execute(sql);
            DataTable       tbl   = ds.Tables[0];
            TasksCollection tasks = new TasksCollection();

            foreach (DataRow r in tbl.Rows)
            {
                string name   = r["name"].ToString();
                int    grAddr = int.Parse(r["gr_address"].ToString());
                int    xgAddr = int.Parse(r["xg_address"].ToString());

                string ip       = r["ip"].ToString();
                string serverIP = r["serverIP"].ToString();
                string team     = r["team"].ToString().Trim();

                //GRStation grst = new GRStation(name, grAddr, ip);
                GRStation grst = CreateGrStation(name, grAddr, ip, team);
                grst.ServerIP = serverIP;

                if (grst != null)
                {
                    // 2007.03.07 Added grstation to singles.grstationsCollection
                    //
                    Singles.S.GRStsCollection.Add(grst);

                    // 2007.03.01 Added gtstation last grRealdata
                    //
                    if (Singles.S.GRStRds == null)
                    {
                        Singles.S.GRStRds = new GRStationLastRealDatasCollection();
                    }

                    // create and add a new grstation last read data object to Singles.GRStRds
                    //
                    GRStationLastRealData grstLastRd = new GRStationLastRealData(grst);

                    Singles.S.GRStRds.Add(grstLastRd);

                    // 2007.03.10 Added check grstation(gprsstation).serverIP is the localhost ip
                    //
                    if (serverIP == XGConfig.Default.ServerIP)
                    {
                        // create a new grrealdata task for grStation
                        //
                        GRRealDataCommand cmd      = new GRRealDataCommand(grst);
                        TimeSpan          timeSp   = new TimeSpan(0, 0, XGConfig.Default.GrRealDataCollCycle, 0, 0);
                        CycleTaskStrategy strategy = new CycleTaskStrategy(timeSp);
                        Task t = new Task(cmd, strategy);
                        tasks.Add(t);
                    }
                }
                else
                {
                    FailMsg += name + Environment.NewLine;
                }

                // 2007.03.12 Added xg data task
                //
                XGStation xgst = CreateXgStation(name, xgAddr, ip);
                //TODO: ? xgst.serverIP = serverip
                //
                xgst.ServerIP = serverIP;

                if (xgst != null)
                {
                    Singles.S.XGStsCollection.Add(xgst);
                    if (serverIP == XGConfig.Default.ServerIP)
                    {
                        ReadTotalCountCommand xgCountCmd = new ReadTotalCountCommand(xgst);
                        TimeSpan          ts             = new TimeSpan(0, 0, XGConfig.Default.XgReadCountCycle, 0, 0);
                        CycleTaskStrategy strategy       = new CycleTaskStrategy(ts);
                        Task t = new Task(xgCountCmd, strategy);
                        tasks.Add(t);
                        //                        t.AfterProcessReceived +=new EventHandler(t_AfterProcessReceived);
                    }
                }
                else
                {
                }
            }

            if (FailMsg.Length >= 13)
            {
                MsgBox.Show(FailMsg);
            }
            return(tasks);
        }