public void setup() { rd = new A_Task_Rd(T.station, new A_Cmd_Coll_Rd()); rd2 = new A_Task_Rd(T.station, new A_Cmd_Coll_Rd()); tasks = new A_Task_Collection(); cpp = new CommPortProxy(1, "19200,n,8,1"); //cpp.Open(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Process(object sender, EventArgs e) { WSListen listen = (WSListen)sender; CommPortProxy cpp = listen.LastConnection; string remoteIP = cpp.RemoteHostIP; RemoveExist(Singles.S.TaskScheduler.CppsCollection, remoteIP); Singles.S.TaskScheduler.CppsCollection.Add(cpp); // frmLogs.Default.AddLog( "accept conn " + remoteIP ); frmLogs.Default.AddLogRemoteIP( DateTime.Now.ToString() + " accept conn : " + remoteIP); }
//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); }
public void serialize() { c_serializer c = new c_serializer(_filename, false); c.Open(); c.Serialize(new CommPortProxy()); c.Close(); c = new c_serializer(_filename, true); c.Open(); CommPortProxy p = c.Deserialize() as CommPortProxy; c.Close(); Assert.IsNotNull(p); Assert.AreEqual(1, p.ComPort); Assert.AreEqual("9600,n,8,1", p.Settings); Assert.IsFalse(p.IsOpen); p.Open(); Assert.IsTrue(p.IsOpen); }
/// <summary> /// 判断该巡更站点是否已连接 /// </summary> /// <param name="xgName"></param> /// <returns></returns> private bool IsGprsConnected(XGStation xgst) { CommPortProxysCollection cpps = Singles.S.TaskScheduler.CppsCollection; for (int i = 0; i < cpps.Count; i++) { CommPortProxy cpp = cpps[i]; if (cpp.RemoteIP == xgst.DestinationIP) { if (cpp.IsConnected) { return(true); } else { return(false); } } } return(false); }
//private void CollRealData() //{ // GRRealDataCommand realCmd = new GRRealDataCommand(_defGrStation); // Task realTask = new Task(realCmd, new ImmediateTaskStrategy() ); // _grTaskSch.Tasks.Add( realTask ); //} //private void SetTemp() //{ // GRSetOutSideTempCommand c = new GRSetOutSideTempCommand( _defGrStation, 21.9F ); // Task t = new Task( c, new ImmediateTaskStrategy() ); // _grTaskSch.Tasks.Add( t ); //} //private void SetOutSideMode() //{ // GRSetOutSideTempModeCommand c = new GRSetOutSideTempModeCommand( _defGrStation, OutSideTempWorkMode.SetByComputer ); // Task t = new Task( c, new ImmediateTaskStrategy() ); // _grTaskSch.Tasks.Add( t ); //} private void CommPortProxy_ReceiveAutoReport(object sender, EventArgs e) { //try //{ CommPortProxy cpp = (CommPortProxy)sender; byte[] bs = cpp.AutoReportData; string s = CT.BytesToString(bs) + Environment.NewLine + bs.Length; //MsgBox.Show (s );o AddLog(s); GRAlarmData ad; if (GRAlarmData.ProcessAutoReport(bs, out ad) == CommResultState.Correct) { frmPropertiesGrid f = new frmPropertiesGrid(); f.ShowMe(ad, ""); } //} //catch(Exception ex) //{ // MsgBox.Show( ex.ToString() ); //} }
/// <summary> /// /// </summary> /// <param name="cpps"></param> /// <param name="remoteIP"></param> private void RemoveExist(CommPortProxysCollection cpps, string remoteIP) { ArgumentChecker.CheckNotNull(cpps); //foreach( CommPortProxy c in cpps ) bool removed = true; while (removed) { removed = false; for (int i = 0; i < cpps.Count; i++) { CommPortProxy c = cpps[i]; if (c.RemoteHostIP == remoteIP) { c.Close(); cpps.RemoveAt(i); removed = true; break; } } } }
//public void Process(object sender, EventArgs e) //TODO: process with freedata // public void Process(object sender, ReceiveARDEventArgs e) { // 2007.02.24 // //CommPortProxy cpp = (CommPortProxy) sender; //int commPort = cpp.ComPort; //byte[] bs = cpp.AutoReportData; CommPortProxy cpp = e.Source; string remoteIP = cpp.RemoteHostIP; byte[] bs = e.ARDDatas; // Log auto report datas // string s = GetArdLogString(remoteIP, bs); if (XGConfig.Default.LogCommIO) { FileLog.CommARD.Add(s); } if (XGConfig.Default.ShowLogForm) { frmLogs.Default.AddLogARD(s); } int address, devType, fcType; byte[] innerDatas; // 2007.03.09 Added comment 检查是否为有效的自动上报数据或供热实时数据 // bool valid = IsValidARD(bs, out address, out devType, out fcType, out innerDatas); if (valid) { // is xg ard // if (devType == XGDefinition.DEVICE_TYPE) { if (fcType == XGDefinition.FC_AUTO_REPORT) { this.ProcessXGARD(remoteIP, address, innerDatas); } } // is gr data type // if (devType == GRDef.DEVICE_TYPE) { if (fcType == GRDef.FC_AUTO_ALARMDATA) { this.ProcessGRARD(remoteIP, address, innerDatas); } else { //TODO: ??: Process read timeout, and return as ARD data // } // 2007.03.09 Added check is grRealData // if (fcType == GRDef.FC_READ_REALDATA) { this.ProcessGrRealData(remoteIP, address, innerDatas); } } } }