/// <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="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="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); }
/// <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> 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(...)"); } }