/// <summary> /// /// </summary> /// <param name="cfg"></param> /// <param name="success"></param> /// <param name="cp"></param> /// <param name="ex"></param> public CommuniPortCreatedEventArgs(ICommuniPortConfig cfg, bool success, ICommuniPort cp, Exception ex) { this._communiPortConfig = cfg; this._success = success; this._communiPort = cp; this._exception = ex; }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> public bool Remove(ICommuniPort cp) { if (cp == null) { throw new ArgumentNullException("cp"); } // remove cp event handler // cp.Determined -= new EventHandler(cp_Determined); cp.Closed -= new EventHandler(cp_Closed); //Hardware hd = this.Soft.Hardware; //StationCommuniPortBinder.Unbind(cp, hd); bool r = this.CommuniPorts.Remove(cp); // // if (RemovedCommuniPort != null) { RemovedCommuniPort(this, new CommuniPortEventArgs(cp)); } return(r); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void Begin(ICommuniPort cp) { if (this.Status == TaskStatus.Ready) { OnBegining(EventArgs.Empty); byte[] bytes = this.Opera.CreateSendBytes(this.Device); this.LastSendBytes = bytes; this.LastSendDateTime = DateTime.Now; this.LastExecute = DateTime.Now; bool success = cp.Write(bytes); if (success) { cp.Occupy(this.Timeout); this.SetStatus(TaskStatus.Executing); } else { ICommuniDetail sendFailCommuniDetail = new SendFailCommuniDetail( this.Opera.Text, this.LastSendDateTime, this.LastSendBytes); this.Device.CommuniDetails.Add(sendFailCommuniDetail); this.SetStatus(TaskStatus.Executed); } OnBegined(EventArgs.Empty); } else { throw new InvalidOperationException("status must be 'Ready' when call Begin(...)"); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _socketListenerManager_NewCommuniPortEvent(object sender, EventArgs e) { SocketListenerManager sckListenMan = sender as SocketListenerManager; ICommuniPort cp = sckListenMan.NewCommuniPort; this.CommuniPortManager.Add(cp); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ProcessReceived(ICommuniPort cp) { //ICommuniPort cp = (ICommuniPort)sender; byte[] bs = cp.Read(); // TODO: cp.stations // StationCollection stations = new StationCollection(); foreach (IStation st in this.Soft.Hardware.Stations) { if (st.CommuniPortConfig.IsMatch(cp)) { stations.Add(st); } } foreach (IStation st in stations) { foreach (IDevice d in st.Devices) { if (bs.Length > 0) { //ITaskProcessor processor = d.Dpu.Processor; //IUploadParseResult parseResult = processor.ProcessUpload(d, bs); //bs = parseResult.Remain; d.ProcessUpload(bs); } } } }
/// <summary> /// /// </summary> /// <param name="cpCfg"></param> /// <returns></returns> public ICommuniPort GetOrCreateCommuniPort(ICommuniPortConfig cpCfg) { if (cpCfg == null) { throw new ArgumentNullException("cpCfg"); } ICommuniPort r = null; foreach (ICommuniPort cp in this.CommuniPorts) { if (cpCfg.IsMatch(cp)) { r = cp; break; } } if (r == null) { if (cpCfg.CanCreate) { CommuniPortFactory f = CommuniPortFactory.Default; bool added = f.Add(cpCfg); _log.Info("add " + cpCfg + " to communiport factory: " + added); } } return(r); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void Add(ICommuniPort cp) { if (cp == null) { throw new ArgumentNullException("cp"); } // TODO: exist cp remove // this.CommuniPorts.Add(cp); // // cp.Filters = this.Filters; cp.IdentityParsers = this.IdentityParsers; // register cp event // cp.Received += new EventHandler(cp_Received); cp.Determined += new EventHandler(cp_Determined); cp.Closed += new EventHandler(cp_Closed); //StationCommuniPortBinder.Bind(cp, this.Soft.Hardware); // // if (AddedCommuniPort != null) { AddedCommuniPort(this, new CommuniPortEventArgs(cp)); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void CommuniPort_Received(object sender, EventArgs e) { ICommuniPort cp = (ICommuniPort)sender; byte[] bs = cp.Read(); RequestProcessManager.Default.Process(this, bs); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public CommuniPortEventArgs(ICommuniPort cp) { if (cp == null) { throw new ArgumentNullException("cp"); } this._cp = cp; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _socketListenerManager_NewCommuniPortEvent(object sender, EventArgs e) { SocketListenerManager slMan = sender as SocketListenerManager; ICommuniPort cp = slMan.NewCommuniPort; Debug.Assert(cp != null); this.CommuniPortManager.Add(cp); }
/// <summary> /// /// </summary> /// <param name="task"></param> /// <param name="cp"></param> /// <returns></returns> private bool IsHighestLevel(ITask task, ICommuniPort cp) { bool r = false; StationCollection stations = GetStations(cp); TaskCollection tasks = GetNeedExecuteTasks(stations); r = IsHighestLevel(task, tasks); return(r); }
private void ExecutingTask(ITask headTask) { ICommuniPort cp = GetCommuniPort(headTask); IDevice device = headTask.Device; headTask.Begin(cp); //device.TaskManager.Current = headTask; device.TaskManager.CaptureCurrent(headTask); }
public bool IsMatch(ICommuniPort cp) { bool r = false; SocketCommuniPort scp = cp as SocketCommuniPort; if (scp != null) { r = this.LocalPort == ((IPEndPoint)scp.LocalEndPoint).Port; } return r; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void cp_Closed(object sender, EventArgs e) { if (this.ClosedCommuniPort != null) { this.ClosedCommuniPort(this, new CommuniPortEventArgs((ICommuniPort)sender)); } ICommuniPort cp = sender as ICommuniPort; this.Remove(cp); }
override public bool IsMatch(ICommuniPort cp) { bool r = false; SocketCommuniPort scp = cp as SocketCommuniPort; if (scp != null) { r = this.LocalPort == ((IPEndPoint)scp.LocalEndPoint).Port; } return(r); }
/// <summary> /// /// </summary> /// <returns></returns> private bool IsDeviceConnected() { bool r = false; ICommuniPort cp = this._device.Station.CommuniPort; if (cp != null) { r = cp.IsOpened; } return(r); }
internal void RemoveByCommuniPort(ICommuniPort cp) { for (int i = this.Clients.Count - 1; i >= 0; i--) { Client c = this.Clients[i]; if (c.CommuniPort == cp) { this.Remove(c); } } }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> private StationCollection GetStations(ICommuniPort cp) { StationCollection r = new StationCollection(); foreach (IStation st in Soft.Hardware.Stations) { if (st.CommuniPort == cp) { r.Add(st); } } return(r); }
/// <summary> /// /// </summary> /// <param name="current"></param> /// <returns></returns> private byte[] GetReceived(ITask current) { IDevice device = current.Device; IStation station = device.Station; ICommuniPort cp = station.CommuniPort; byte[] received = new byte[0]; if (cp != null) { received = cp.Read(); } return(received); }
private void Default_CommuniPortCreated(object sender, CommuniPortCreatedEventArgs e) { if (e.Success) { ICommuniPort cp = e.CommuniPort; this.Add(cp); } this.CreateCommuniPortResults.Add(new CreateCommuniPortResult( e.Success, e.CommuniPortConfig, "", e.Exception)); _log.Info(string.Format("CreateCommuniPort '{0}' is '{1}'", e.CommuniPortConfig, e.Success)); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void End(ICommuniPort cp) { if (this.Status == TaskStatus.Timeout) { OnEnding(EventArgs.Empty); byte[] bytes = new byte[0]; if (cp != null) { bytes = cp.Read(); } // filte bytes by device // bytes = this.Device.Filters.Filtrate(bytes); this.LastReceivedBytes = bytes; this.LastReceivedDateTime = DateTime.Now; IParseResult pr = this.Opera.ParseReceivedBytes(this.Device, bytes); this.LastParseResult = pr; // // CommuniDetail cd = new CommuniDetail( this.Opera.Text, LastSendBytes, LastExecute, LastReceivedBytes, LastReceivedDateTime, //parseResult.ToString(), //parseResult.IsSuccess pr ); this.Device.CommuniDetails.Add(cd); DeviceCommuniLogger.Log(this.Device, cd); //this.device // // // this.SetStatus(TaskStatus.Executed); OnEnded(EventArgs.Empty); } else { throw new InvalidOperationException("status must be 'Timeout' when call End(...)"); } }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <param name="hardware"></param> /// <returns></returns> static public StationCollection Unbind(ICommuniPort cp, Hardware hardware) { StationCollection unbinded = new StationCollection(); foreach (IStation station in hardware.Stations) { if (station.CommuniPort == cp) { station.CommuniPort = null; unbinded.Add(station); } } return(unbinded); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> override public bool IsMatch(ICommuniPort cp) { bool r = false; SerialCommuniPort scp = cp as SerialCommuniPort; if (scp != null) { bool isSameName = StringHelper.Equal( scp.SerialPort.PortName, this.SerialPortSetting.PortName); r = isSameName; } return(r); }
/// <summary> /// /// </summary> void Target() { while (this._startFlag) { for (int i = _cpCfgs.Count - 1; i >= 0; i--) { ICommuniPortConfig cfg = _cpCfgs[i]; if (cfg.CanCreate) { ICommuniPort cp = null; bool success = false; Exception ex = null; try { cp = cfg.Create(); success = true; CPCreateLog cpclog = new CPCreateLog(DateTime.Now, string.Format("创建 '{0}' 成功", cfg)); this.CPCreateLogs.Add(cpclog); } catch (Exception e) { ex = e; success = false; CPCreateLog cpclog = new CPCreateLog(DateTime.Now, string.Format("创建 '{0}' 失败, {1}", cfg, ex.Message)); this.CPCreateLogs.Add(cpclog); } if (success) { this._cpCfgs.Remove(cfg); } if (CommuniPortCreated != null) { CommuniPortCreated(this, new CommuniPortCreatedEventArgs( cfg, success, cp, ex)); } } } Thread.Sleep(SLEEP_TIME); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void station_CommuniPortChanged(object sender, EventArgs e) { IStation station = sender as IStation; Debug.Assert(station != null, "station != null"); ICommuniPort cp = station.CommuniPort; if (cp != null) { SetImageKey(IconNames.Connect); } else { SetImageKey(IconNames.Disconnect); } }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> private string GetStationNames(ICommuniPort cp) { string r = string.Empty; StationCollection stations = SoftManager.GetSoft().Hardware.Stations; foreach (IStation st in stations) { if (st.CommuniPort == cp) { if (r.Length > 0) { r += ","; } r += st.Name; } } return(r); }
/// <summary> /// /// </summary> /// <param name="headTask"></param> /// <returns></returns> //private bool DoNotExecutingTask(ITask headTask) private bool CanExecutingTask(ITask headTask) { TaskStatus status = headTask.Check(); if (status == TaskStatus.Ready) { ICommuniPort cp = GetCommuniPort(headTask); if ((cp != null) && (!cp.IsOccupy) && IsHighestLevel(headTask, cp)) { //IDevice device = headTask.Device; //headTask.Begin(cp); ////device.TaskManager.Current = headTask; //device.TaskManager.CaptureCurrent(headTask); return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> override public bool IsMatch(ICommuniPort cp) { if (cp == null) { return(false); } bool r = false; if (cp is SocketCommuniPort) { SocketCommuniPort scp = cp as SocketCommuniPort; EndPoint ep = scp.RemoteEndPoint; IPEndPoint ipep = ep as IPEndPoint; IPAddress ipAddress = ipep.Address; r = ipAddress.Equals(RemoteIPAddress); } return(r); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <param name="hardware"></param> static public StationCollection Bind(ICommuniPort cp, Hardware hardware) { StationCollection binded = new StationCollection(); foreach (IStation station in hardware.Stations) { ICommuniPortConfig cpConfig = station.CommuniPortConfig; if (cpConfig.IsMatch(cp)) { ICommuniPort old = station.CommuniPort; if (old != cp) { if (old != null) { old.Close(); } station.CommuniPort = cp; binded.Add(station); } } } return(binded); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public CommuniPortEventArgs(ICommuniPort cp) { if (cp == null) throw new ArgumentNullException("cp"); this._cp = cp; }
public void Add(ICommuniPort cp) { if (cp == null) { throw new ArgumentNullException("cp"); } // TODO: exist cp remove // this.CommuniPorts.Add(cp); // // cp.Filters = this.Filters; cp.IdentityParsers = this.IdentityParsers; // register cp event // cp.Received += new EventHandler(cp_Received); cp.Determined += new EventHandler(cp_Determined); cp.Closed += new EventHandler(cp_Closed); StationCommuniPortBinder.Bind(cp, this.Soft.Hardware); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> public bool IsMatch(ICommuniPort cp) { if (cp == null) { return false; } bool r = false; if (cp is SocketCommuniPort) { SocketCommuniPort scp = cp as SocketCommuniPort; EndPoint ep = scp.RemoteEndPoint; IPEndPoint ipep = ep as IPEndPoint; IPAddress ipAddress = ipep.Address; r = ipAddress.Equals(RemoteIPAddress); } return r; }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> override public bool IsMatch(ICommuniPort cp) { return(false); }
void _cpManager_ReceivedCommuniPort(object sender, CommuniPortEventArgs e) { ICommuniPort cp = e.CommuniPort; ProcessReceived(cp); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> public bool IsMatch(ICommuniPort cp) { bool r = false; SerialCommuniPort scp = cp as SerialCommuniPort; if (scp != null) { bool isSameName = StringHelper.Equal( scp.SerialPort.PortName, this.SerialPortSetting.PortName); r = isSameName; } return r; }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> private StationCollection GetStations(ICommuniPort cp) { StationCollection r = new StationCollection(); foreach (IStation st in Soft.Hardware.Stations) { if (st.CommuniPort == cp) { r.Add(st); } } return r; }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <returns></returns> public bool Remove(ICommuniPort cp) { if (cp == null) { throw new ArgumentNullException("cp"); } // remove cp event handler // cp.Determined -= new EventHandler(cp_Determined); cp.Closed -= new EventHandler(cp_Closed); Hardware hd = this.Soft.Hardware; StationCommuniPortBinder.Unbind(cp, hd); return this.CommuniPorts.Remove(cp); }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void End(ICommuniPort cp) { if (this.Status == TaskStatus.Timeout) { OnEnding(EventArgs.Empty); byte[] bytes = new byte[0]; if (cp != null) { bytes = cp.Read(); } // filte bytes by device // bytes = this.Device.Filters.Filtrate(bytes); this.LastReceivedBytes = bytes; this.LastReceivedDateTime = DateTime.Now; IParseResult pr = this.Opera.ParseReceivedBytes(this.Device, bytes); this.LastParseResult = pr; // // CommuniDetail cd = new CommuniDetail( this.Opera.Text, LastSendBytes, LastExecute, LastReceivedBytes, LastReceivedDateTime, pr.ToString(), pr.IsSuccess ); this.Device.CommuniDetails.Add(cd); DeviceCommuniLogger.Log(this.Device, cd); //this.device // // // this.SetStatus(TaskStatus.Executed); OnEnded(EventArgs.Empty); } else { throw new InvalidOperationException("status must be 'Timeout' when call End(...)"); } }
/// <summary> /// /// </summary> /// <param name="task"></param> /// <param name="cp"></param> /// <returns></returns> private bool IsHighestLevel(ITask task, ICommuniPort cp) { bool r = false; StationCollection stations = GetStations(cp); TaskCollection tasks = GetNeedExecuteTasks(stations); r = IsHighestLevel(task, tasks); return r; }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void Begin(ICommuniPort cp) { if (this.Status == TaskStatus.Ready) { OnBegining(EventArgs.Empty); byte[] bytes = this.Opera.CreateSendBytes(this.Device); this.LastSendBytes = bytes; this.LastExecute = DateTime.Now; bool success = cp.Write(bytes); if (success) { cp.Occupy(this.Timeout); this.SetStatus(TaskStatus.Executing); } else { this.SetStatus(TaskStatus.Executed); } OnBegined(EventArgs.Empty); } else { throw new InvalidOperationException("status must be 'Ready' when call Begin(...)"); } }