Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ccmd"></param>
        /// <param name="ccpd"></param>
        private void Exe(CommCmdMakerDelegate ccmd, CommCmdProcessDelegate ccpd)
        {
            System.Diagnostics.Debug.Assert(ccmd != null &&
                                            ccpd != null);

            if (IsSelectedXgStation())
            {
                XGStation xgst = GetSelectedXg();
                if (IsGprsConnected(xgst))
                {
                    CommCmdBase  cmd      = ccmd(xgst);
                    TaskStrategy strategy = new ImmediateTaskStrategy();

                    Task t = new Task(cmd, strategy);
                    frmControlProcess f = new frmControlProcess(t);
                    Singles.S.TaskScheduler.Tasks.AddFirstExectueTask(t);
                    f.ShowDialog();

                    if (t.LastCommResultState == CommResultState.Correct)
                    {
                        ccpd(cmd);
                    }
                }
                else
                {
                    ShowNotConnect();
                }
            }
            else
            {
                ShowNoStationSelected();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void Process ( object sender, EventArgs e )
 {
     TaskScheduler sch = sender as TaskScheduler;
     Task actTask = sch.ActiveTask ;
     CommCmdBase cmd = actTask.CommCmd;
     if ( Singles.S.CollStateDisPlay != null )
         Singles.S.CollStateDisPlay.Text = GetDisplayText( cmd );
     
 }
Esempio n. 3
0
        private void CreateImmediateTaskAndExecute(CommCmdBase cmd)
        {
            Task t = new Task(cmd, new ImmediateTaskStrategy());

            Singles.S.TaskScheduler.Tasks.Add(t);
            frmControlProcess f = new frmControlProcess(t);

            f.ShowDialog();
        }
Esempio n. 4
0
        private bool SaveCollSettings()
        {
            int newGrCollCycle;

            try
            {
                newGrCollCycle = int.Parse(this.txtGRCollCycle.Text.Trim());
            }
            catch
            {
                MsgBox.Show("采集周期必须输入数字");
                return(false);
            }

            if (newGrCollCycle < MIN_COLL_CYCLE)
            {
                MsgBox.Show("采集周期不能小于" + MIN_COLL_CYCLE + "分钟");
                return(false);
            }
            if (newGrCollCycle > MAX_COLL_CYCLE)
            {
                MsgBox.Show("采集周期不能大于" + MIN_COLL_CYCLE + "分钟");
                return(false);
            }

            XGConfig.Default.GrRealDataCollCycle = newGrCollCycle;

            // refresh task coll cycle
            //
            TasksCollection tasks = Singles.S.TaskScheduler.Tasks;

            foreach (Task t in tasks)
            {
                TaskStrategy s   = t.TaskStrategy;
                CommCmdBase  cmd = t.CommCmd;


                if (s is CycleTaskStrategy && cmd is GRCtrl.GRRealDataCommand)
                {
                    CycleTaskStrategy cyc = s as CycleTaskStrategy;
                    cyc.Cycle = GetCycle(newGrCollCycle);
                }
            }

            // TODO: update app.config file
            //


            return(true);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        private void ProcessReadDateCmd(CommCmdBase cmd)
        {
            ReadDateCommand rdcmd = cmd as ReadDateCommand;

            Debug.Assert(rdcmd != null);

            ListViewItem lvi = this.lvXg.SelectedItems[0];

            lvi.SubItems[1].Text = string.Format(
                "20{0}-{1}-{2}",
                rdcmd.Year.ToString("d2"),
                rdcmd.Month,
                rdcmd.Day
                );
        }
Esempio n. 6
0
        //public override void Execute(CommPortProxy commPortProxy)
        protected override void OnExecute(CommPortProxy commPortProxy, CommCmdBase cmd)
        {
            //base.OnExecute (commPortProxy, station, cmd, parameters);
            //}
            //
            //{

            byte[] bytescmd = CommCmd.MakeCommand( );
            int    late     = CommCmd.LatencyTime;

            if (!commPortProxy.IsOpen)
            {
                commPortProxy.Open();
            }

            commPortProxy.Send(bytescmd, late);
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        private void ProcessReadTimeCmd(CommCmdBase cmd)
        {
            ReadTimeCommand rtcmd = cmd as ReadTimeCommand;

            Debug.Assert(rtcmd != null);

            ListViewItem lvi = lvXg.SelectedItems[0];

            lvi.SubItems[2].Text = string.Format(
                "{0}:{1}:{2}",
                rtcmd.Hour,
                rtcmd.Minute,
                rtcmd.Second
                );

            lvi.SubItems[3].Text = DateTime.Now.ToString();
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ccmd"></param>
        /// <param name="ccmp"></param>
        private void ExeAll(CommCmdMakerDelegate ccmd)          //, CommCmdProcessDelegate ccmp )
        {
            XGStationsCollection xgstColl = Singles.S.XGStsCollection;

            for (int i = 0; i < xgstColl.Count; i++)
            {
                XGStation xgst = xgstColl[i];
                if (xgst.ServerIP == XGConfig.Default.ServerIP)
                {
                    // CommCmdBase cmd = new ReadDateCommand( xgst );
                    CommCmdBase cmd = ccmd(xgst);
                    Task        t   = new Task(cmd, new ImmediateTaskStrategy());
                    t.AfterProcessReceived += new EventHandler(t_AfterProcessReceived);
                    Singles.S.TaskScheduler.Tasks.Add(t);
                }
            }
            MsgBox.Show("命令已提交!");
        }
Esempio n. 9
0
        //private string getlogstring( int commport, task task )
        private string GetLogString(string remoteIP, Task task)
        {
            CommCmdBase     cmd             = task.CommCmd;
            CommResultState commResultState = task.LastCommResultState;
            string          sLastReceive    = string.Empty;

            if (task.LastReceived != null)
            {
                sLastReceive = CT.BytesToString(task.LastReceived);
            }

            string s = string.Format("Send\t\t: {0}, {1}\r\nReceived\t: {2}, {3}\r\nCommResult\t: {4}\r\nCmdType\t\t: {5}\r\nRemoteIP\t: {6}\r\n",
                                     task.LastSendDateTime, CT.BytesToString(task.LastSendDatas),
                                     //task.LastReceivedDateTime, CT.BytesToString( task.LastReceived),
                                     task.LastReceivedDateTime, sLastReceive,
                                     commResultState.ToString(), cmd.GetType().Name, remoteIP);

            return(s);
        }
Esempio n. 10
0
        public void Process(object sender, EventArgs e)
        {
            TaskScheduler sch      = (TaskScheduler)sender;
            Task          act      = sch.ActiveTask;
            CommCmdBase   cmd      = act.CommCmd;
            Station       st       = cmd.Station;
            string        remoteIP = st.DestinationIP;
            string        s        = "DateTime   : " + DateTime.Now + Environment.NewLine;

            s += "Not find IP: " + remoteIP + Environment.NewLine;
            s += "cmd        : " + cmd.GetType().Name + Environment.NewLine;
            s += "stationName: " + st.StationName + Environment.NewLine;
            s += Environment.NewLine;

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

            // refreash run state
            //
            frmGprsCollState.Default.RunState = s;
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Process(object sender, EventArgs e)
        {
            ArgumentChecker.CheckNotNull(sender);
            TaskScheduler sch  = (TaskScheduler)sender;
            Task          task = sch.ActiveTask;

            ArgumentChecker.CheckNotNull(task);

            CommCmdBase     cmd             = task.CommCmd;
            CommResultState commResultState = task.LastCommResultState;

            if (commResultState != CommResultState.Correct)
            {
                if (XGConfig.Default.LogCommFail)
                {
                    string s = string.Format("Send\t\t: {0}, {1}\r\nReceived\t: {2}, {3}\r\nCommResult\t: {4}\r\nCmdType\t\t: {5}\r\n",
                                             task.LastSendDateTime, CT.BytesToString(task.LastSendDatas),
                                             task.LastReceivedDateTime, CT.BytesToString(task.LastReceived),
                                             commResultState.ToString(), cmd.GetType().Name);
                    FileLog.CommFail.Add(s);
                }
                return;
            }

            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand readRecordCmd = cmd as ReadRecordCommand;
                ProcessReadRecordCmd(readRecordCmd);
            }

            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand readCountCmd = cmd as ReadTotalCountCommand;
                ProcessReadTotalCountCmd(readCountCmd, task);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stName"></param>
        /// <returns></returns>
        private string GetCommCmdName(string stName)
        {
            CommCmdBase cmd = _task.CommCmd;

            return(CommCmdText.GetCommCmdText(cmd));
        }
Esempio n. 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cmd"></param>
 private void ProcessSetDateCmd(CommCmdBase cmd)
 {
     // Do nothing
 }
Esempio n. 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 private string GetDisplayText ( CommCmdBase cmd )
 {
     return CommCmdText.GetCommCmdText( cmd );
 }
Esempio n. 15
0
        /// <summary>
        /// 处理执行完毕的命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskScheduler_Executed(object sender, EventArgs e)
        {
            TaskScheduler sch = sender as TaskScheduler;

            if (sch == null)
            {
                Debug.Fail("TaskScheduler_Executed(), sender == null");
            }
            AddLog("TC: " + sch.Tasks.Count);
            Task   at = sch.ActiveTask;
            string s  = string.Format("send: {0}, {1}\r\nrece: {2}, {3}",
                                      at.LastSendDateTime, CT.BytesToString(at.LastSendDatas),
                                      at.LastReceivedDateTime, CT.BytesToString(at.LastReceived));

            AddLog(s);
            s = at.LastCommResultState.ToString();
            AddLog(s);
            CommCmdBase cmd = sch.ActiveTask.CommCmd;

            // read total count cmd
            //
            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand c = cmd as ReadTotalCountCommand;

                AddLog("LocalTotalCount: " + c.TotalCount);
                AddLog(c.Station.StationName + c.Station.Address);

                // need read all record and clear xg ctrler data
                //
                if (at.Tag != null)
                {//&&
                    // (string)at.Tag == TagType.OP_ReadAndClearXgData.ToString() )
                    //{
                    object[] tags    = (object[])at.Tag;
                    TagType  tagType = (TagType)tags[0];
                    XGTask   xgtask  = (XGTask)tags[1];

                    RemoveAllCommand clearCmd  = new RemoveAllCommand(c.Station as XGStation);
                    Task             clearTask = new Task(clearCmd, new ImmediateTaskStrategy());
                    Singles.S.TaskScheduler.Tasks.Add(clearTask);

                    for (int i = 0; i < c.TotalCount; i++)
                    {
                        ReadRecordCommand rdcmd = new ReadRecordCommand(c.Station as XGStation, i + 1);
                        Task t = new Task(rdcmd, new ImmediateTaskStrategy());
                        Singles.S.TaskScheduler.Tasks.Add(t);
                    }

                    // ???
                    //
                    //RemoveAllCommand rac = new RemoveAllCommand( c.Station as XGStation );
                    //Task trac = new Task( "rdall", rac, new ImmediateTaskStrategy() );
                    //trac.Tag = xgtask;
                    //trac.BeforeExecuteTask +=new EventHandler(trac_BeforeExecuteTask);
                    //Singles.S.TaskScheduler.Tasks.Add( trac );
                }
            }

            // read record cmd
            //
            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand rdcmd = cmd as ReadRecordCommand;
                AddLog("record index: " + rdcmd.RecordIndex);

                if (rdcmd.XGData != null)
                {
                    // 2007.03.11 Modify
                    //
                    //XGDB.InsertXGData( rdcmd.XGData );
                    XGDB.InsertXGData(cmd.Station.DestinationIP, rdcmd.XGData);
                }

                XGTask[] tasks = Singles.S.XGScheduler.Tasks.MatchXGData(rdcmd.XGData);
                foreach (XGTask task in tasks)
                {
                    task.IsComplete = true;
                }
            }
        }
Esempio n. 16
0
        static public string GetCommCmdText(CommCmdBase cmd)
        {
            string r      = string.Empty;
            string stName = cmd.Station.StationName;
            string ip     = cmd.Station.DestinationIP;

            if (!Singles.S.CommPortProxyCollection.IsConnected(ip))
            {
                r = string.Format("同 {0}({1}) 尚未建立连接!", stName, ip);
            }
            else
            {
                if (cmd is GRRealDataCommand)
                {
                    r = string.Format("正在采集 {0}({1}) 供热实时数据...", stName, ip);
                }
                else if (cmd is ReadTotalCountCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更记录总数...", stName, ip);
                }
                else if (cmd is ReadRecordCommand)
                {
                    ReadRecordCommand c = (ReadRecordCommand)cmd;
                    r = string.Format("正在读取 {0}({1}) 第{2}条巡更记录...", stName, ip, c.RecordIndex);
                }
                else if (cmd is AutoReportCommand)
                {
                    r = string.Format("正在清除 {0}({1}) 最新巡更数据...", stName, ip);
                }
                else if (cmd is GRReadPressAlarmSetCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 压力报警设定...", stName, ip);
                }
                else if (cmd is GRWritePressAlarmSetCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 压力报警设定...", stName, ip);
                }
                else if (cmd is GRReadTempWLAlarmSetCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 温度报警设定...", stName, ip);
                }
                else if (cmd is GRWriteTempWLAlarmSetCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 温度报警设定...", stName, ip);
                }
                else if (cmd is GRCyclePumpOpCmd)
                {
                    GRCyclePumpOpCmd tc = cmd as GRCyclePumpOpCmd;
                    string           s;
                    if (tc.OP == PumpOP.Stop)
                    {
                        s = "正在停止";
                    }
                    else
                    {
                        s = "正在启动";
                    }
                    r = string.Format(s + " {0}({1}) 循环泵...", stName, ip);
                }
                else if (cmd is GRRePumpOpCmd)
                {
                    GRRePumpOpCmd tc = cmd as GRRePumpOpCmd;
                    string        s;
                    if (tc.OP == PumpOP.Stop)
                    {
                        s = "正在停止";
                    }
                    else
                    {
                        s = "正在启动";
                    }

                    r = string.Format(s + " {0}({1}) 补水泵...", stName, ip);
                }
                else if (cmd is GRReadTLCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 温度控制曲线...", stName, ip);
                }
                else if (cmd is GRSetOutSideTempCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 室外温度...", stName, ip);
                }
                else if (cmd is GRSetOutSideTempModeCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 室外温度模式...", stName, ip);
                }
                else if (cmd is ReadDateCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更控制器日期...", stName, ip);
                }
                else if (cmd is ReadTimeCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更控制器时间...", stName, ip);
                }
                else if (cmd is ModifyDateCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 巡更控制器日期...", stName, ip);
                }
                else if (cmd is ModifyTimeCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 巡更控制器时间...", stName, ip);
                }
                else if (cmd is RemoveAllCommand)
                {
                    r = string.Format("正在删除 {0}({1}) 巡更控制器记录...", stName, ip);
                }
                //		public override string ToString()
                else if (cmd is GRWriteOTGT2Line)
                {
                    r = string.Format("正在设置 {0}({1}) 温度控制曲线...", stName, ip);
                }
                else if (cmd is GRWriteTimeTempLine)
                {
                    r = string.Format("正在设置 {0}({1}) 分时供热曲线...", stName, ip);
                }
                else if (cmd is GRReadTwoPressChaCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 循环泵参数...", stName, ip);
                }
                else if (cmd is GRWriteTwoPressChaCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 循环泵参数...", stName, ip);
                }
                else if (cmd is GRReadRepumpPressSettings)
                {
                    r = string.Format("正在读取 {0}({1}) 补水泵参数...", stName, ip);
                }
                else if (cmd is GRWriteRepumpPressSettings)
                {
                    r = string.Format("正在设置 {0}({1}) 补水泵参数...", stName, ip);
                }
                else
                {
                    r = string.Format("正在执行 {0}({1}) {2}...", stName, ip, cmd.ToString());
                }
            }

            return(r);
        }
Esempio n. 17
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
            //
        }