protected override void ProcessTryPauseResult(DirectiveData data, CommunicationEventArgs comEventArgs) { CurrentStatus = DeviceStatusEnum.Pausing; comEventArgs.DeviceStatus = DeviceStatusEnum.Pausing; OnCommunicationChangeEvent(comEventArgs); StartPauseLoop(); }
public void Handle(DirectiveTypeEnum type, DirectiveData data, CommunicationEventArgs comEventArgs) { OldStatus = Controller.CurrentStatus; switch (type) { case DirectiveTypeEnum.Idle: HandleIdle(data, comEventArgs); break; case DirectiveTypeEnum.TryStart: HandleTryStart(data, comEventArgs); break; case DirectiveTypeEnum.Running: HandleRunning(data, comEventArgs); break; case DirectiveTypeEnum.TryPause: HandleTryPause(data, comEventArgs); break; case DirectiveTypeEnum.Pausing: HandlePausing(data, comEventArgs); break; case DirectiveTypeEnum.Close: HandleClose(data, comEventArgs); break; default: HandleError(data, comEventArgs); break; } }
public override void ProcessTryPauseResult(DirectiveData data, CommunicationEventArgs comEventArgs) { SetStatus(DeviceStatusEnum.Pausing); comEventArgs.DeviceStatus = DeviceStatusEnum.Pausing; OnCommunicationChange(comEventArgs); StartPauseLoop(); }
/// <summary> /// Called when rollbar internal event is detected. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RollbarEventArgs"/> instance containing the event data.</param> private static void OnRollbarInternalEvent(object sender, RollbarEventArgs e) { Console.WriteLine(e.TraceAsString()); RollbarApiErrorEventArgs apiErrorEvent = e as RollbarApiErrorEventArgs; if (apiErrorEvent != null) { //TODO: handle/report Rollbar API communication error event... return; } CommunicationEventArgs commEvent = e as CommunicationEventArgs; if (commEvent != null) { //TODO: handle/report Rollbar API communication event... return; } CommunicationErrorEventArgs commErrorEvent = e as CommunicationErrorEventArgs; if (commErrorEvent != null) { //TODO: handle/report basic communication error while attempting to reach Rollbar API service... return; } InternalErrorEventArgs internalErrorEvent = e as InternalErrorEventArgs; if (internalErrorEvent != null) { //TODO: handle/report basic internal error while using the Rollbar Notifier... return; } }
public override void OnCommunication(CommunicationEventArgs e) { base.OnCommunication(e); if (e.Data.DirectiveType == DirectiveTypeEnum.Running) { HandleDeviceStatusChange(new IoStatusChangeEventArgs() { DeviceId = e.DeviceId, DeviceType = e.DeviceType, IoStatus = e.DeviceStatus, Delta = 0, Feedback = e.Data }); var x = e.Data as TemperatureDirectiveData; if (x != null) { DeviceService.SaveTemperatureRecord(new TemperatureRecord() { CellCultivationId = CultivationService.GetLastCultivationId(), Temperature = x.CenterTemperature, CreatedAt = DateTime.Now }); } Center.SyncTemperatureWithServer(); } }
public override void ProcessRunningDirectiveResult(DirectiveData data, CommunicationEventArgs comEventArgs) { var ret = data as RockerDirectiveData; if (CurrentStatus == DeviceStatusEnum.Startting) { //从tryStart变为running(真的开始) if (ret?.Speed > 0) { CurrentStatus = DeviceStatusEnum.Running; comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartEvent.TrySetResult(new DeviceIOResult(true)); OnCommunicationChange(comEventArgs); StartRunningLoop(); } else { comEventArgs.DeviceStatus = CurrentStatus; StartRunningLoop(); } } else if (CurrentStatus == DeviceStatusEnum.Running) { comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartRunningLoop(); } else { comEventArgs.DeviceStatus = DeviceStatusEnum.Error; } }
private void Instance_InternalEvent(object sender, RollbarEventArgs e) { //Console.WriteLine(e.TraceAsString()); RollbarApiErrorEventArgs apiErrorEvent = e as RollbarApiErrorEventArgs; if (apiErrorEvent != null) { _apiErrorsCount++; return; } CommunicationEventArgs commEvent = e as CommunicationEventArgs; if (commEvent != null) { _commSuccessCount++; return; } CommunicationErrorEventArgs commErrorEvent = e as CommunicationErrorEventArgs; if (commErrorEvent != null) { _commErrorsCount++; return; } InternalErrorEventArgs internalErrorEvent = e as InternalErrorEventArgs; if (internalErrorEvent != null) { _internalErrorsCount++; return; } }
public override void HandleTryPause(DirectiveData data, CommunicationEventArgs comEventArgs) { Controller.ProcessTryPauseResult(data, comEventArgs); LogFactory.Create() .Info( $"device{Controller.Device.DeviceId} {OldStatus} status receive TryPause feedback convert to {comEventArgs.DeviceStatus}"); }
public virtual void OnCommunicationChange(CommunicationEventArgs e) { if (e == null) { return; } LogFactory.Create().Info($"****************************{e.DeviceId}->{e.DeviceStatus}***********************"); }
protected void HandleDeviceStatusChange(CommunicationEventArgs e) { var deviceId = e.DeviceId; var type = e.DeviceStatus; var feedback = e.Data; var delta = CalcVolume(e.Description); var ftime = PumpCultivation.Schedules.FirstOrDefault(); var ltime = PumpCultivation.Schedules.LastOrDefault(); var stime = StartTime; var etime = Flowrate <= 0 ? DateTime.MinValue : StartTime.AddMinutes((PreUnfinishedVolume > 0 ? PreUnfinishedVolume : Volume) / Flowrate); var ntime = PumpCultivation.Schedules.FirstOrDefault(each => each > DateTime.Now); switch (type) { case DeviceStatusEnum.Startting: CurrentContext.SysCache.SystemRealTimeStatus.Update(deviceId, true, Volume, 0, this.AlreadyRunTimes, PumpCultivation.Schedules.Count, ftime, ltime, stime, etime, ntime); break; case DeviceStatusEnum.Running: var data = feedback as PumpDirectiveData; if (data != null) { CurrentContext.SysCache.SystemRealTimeStatus.Update(deviceId, true, Volume, data.FlowRate, AlreadyRunTimes); } break; //case DeviceStatusEnum.Pausing: case DeviceStatusEnum.Idle: if (CurrentContext.SysCache.SystemRealTimeStatus.In.DeviceId == deviceId) { CurrentContext.SysCache.SystemRealTimeStatus.CurrVolume += Convert.ToInt32(delta); } else { CurrentContext.SysCache.SystemRealTimeStatus.CurrVolume -= Convert.ToInt32(delta); } HandleSystemStatusChange(e); CurrentContext.SysCache.SystemRealTimeStatus.Update(deviceId, false, Volume, 0, AlreadyRunTimes); break; default: break; } //涉及到动画, starting Running都会启动动画 只需要触发一次 if (type == DeviceStatusEnum.Running || type == DeviceStatusEnum.Idle) { Center.OnDeviceStatusChange(new IoStatusChangeEventArgs() { DeviceId = e.DeviceId, DeviceType = e.DeviceType, IoStatus = e.DeviceStatus, Delta = delta, Feedback = e.Data }); } }
private void Instance_InternalEvent(object sender, RollbarEventArgs e) { CommunicationEventArgs communicationEventArgs = e as CommunicationEventArgs; if (e != null) { _rollbarCommunicationEventsCount++; } }
protected virtual void ProcessTryStartResult(DirectiveData data, CommunicationEventArgs comEventArgs) { CurrentStatus = DeviceStatusEnum.Startting; comEventArgs.DeviceStatus = DeviceStatusEnum.Startting; //记录泵的开始时间 // 拿到TryStart反馈指令后启动running状态轮询 OnCommunicationChangeEvent(comEventArgs); StartRunningLoop(); }
private Tuple <double, double, double> PreStart() { var interval = 0; var flowrate = 0D; var volume = 0D; //TODO 如果上次未完成 则立即开始运行 if (PreUnfinishedVolume > 0) { flowrate = Flowrate; volume = PreUnfinishedVolume; LogFactory.Create().Info($"pump{PumpCultivation.Device.DeviceId} pre unfinished {PreUnfinishedVolume:##.###}, starttime{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); //清理数据 防止影响下一个流程 PreUnfinishedVolume = 0; } else { var currentDateTime = DateTime.Now; var next = PumpCultivation.GetNextRunParams(AlreadyRunTimes == 0); //暂停的时候泵还在运行, 但重新开始后由于需要加入的量很少(<1)所以认为上次已经加完,此时需要重新判断泵的流程是否全部完成 if (null == next) { LogFactory.Create().Info($"DEVICE{Device.DeviceId} cultivate process finished"); if (CurrentStatus != DeviceStatusEnum.AllFinished) { var comEventArgs = new CommunicationEventArgs { DeviceType = TargetDeviceTypeEnum.Pump, DeviceId = PumpCultivation.Device.DeviceId, DeviceStatus = DeviceStatusEnum.Idle, Description = IdleDesc.Completed.ToString() }; OnCommunicationChange(comEventArgs); } //整个流程已完成 return(null); } var nextTime = next.Item1; var timeSpan = nextTime > currentDateTime ? (DateTime)nextTime - currentDateTime : TimeSpan.FromSeconds(0); interval = (int)timeSpan.TotalMilliseconds; flowrate = next.Item2; volume = next.Item3; LogFactory.Create().Info($"pump{Device.DeviceId} prev is finished, next starttime{nextTime:yyyy-MM-dd HH:mm:ss}, interval{timeSpan.TotalMilliseconds}"); } if (interval < 0) { interval = 0; } return(new Tuple <double, double, double>(interval, flowrate, volume)); }
public override void ProcessPausingResult(DirectiveData data, CommunicationEventArgs comEventArgs) { comEventArgs.DeviceStatus = DeviceStatusEnum.Running; comEventArgs.Description = IdleDesc.Paused.ToString();; SetStatus(DeviceStatusEnum.Running); StopEvent.TrySetResult(new DeviceIOResult(true)); OnCommunicationChange(comEventArgs); }
public override void HandleIdle(DirectiveData data, CommunicationEventArgs comEventArgs) { Controller.SetStatus(DeviceStatusEnum.Idle); comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; Controller.StartIdleLoop(); LogFactory.Create() .Info( $"device{Controller.Device.DeviceId} {OldStatus} status receive Idle feedback convert to {comEventArgs.DeviceStatus}"); }
public virtual void OnCommunication(CommunicationEventArgs args) { if (CurrentContext.Status == SysStatusEnum.Starting) { Center.OnSystemStatusChange(new RunStatusChangeEventArgs() { SysStatus = SysStatusEnum.Running }); Center.SyncSysStatusWithServer(); } }
/// <summary> /// Handles the InternalEvent event of the Instance control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RollbarEventArgs"/> instance containing the event data.</param> private void Instance_InternalEvent(object sender, RollbarEventArgs e) { //string eventTrace = $"##################{Environment.NewLine}{e.TraceAsString()}{Environment.NewLine}"; //Console.WriteLine(eventTrace); //System.Diagnostics.Trace.WriteLine(eventTrace); CommunicationEventArgs communicationEventArgs = e as CommunicationEventArgs; if (e != null) { this._rollbarCommEvents.Add(communicationEventArgs); } }
private void RunCommandsLoop() { _messageThread = new Thread(() => { _serverStopped = false; while (!_serverStopped) { try { var data = _protocolChannel.Read <TMessage>(); var eventData = new CommunicationEventArgs { Data = data, Channel = _protocolChannel, }; DataReceived?.Invoke(this, eventData); } catch (ChannelException e) { var eventData = new CommunicationEventArgs { Data = null, Channel = _protocolChannel, Exception = e }; try { DataReceived?.Invoke(this, eventData); } catch { // один из обработчиков выбросил исключение // мы все равно не знаем что с ним делать. // Считаем, что факап подписчика - его проблемы. } // свойство в исключении может быть утановлено в обработчике евента _serverStopped = e.StopChannel; } catch (Exception) { _serverStopped = true; } } }); _messageThread.Start(); }
private void OnDataReceived(object sender, CommunicationEventArgs e) { if (e.Exception == null) { ProcessSuccess((RpcCall)e.Data, e.Channel); } else { if (e.Exception.StopChannel) { Stop(); } } }
protected virtual void ProcessIdleResult(DirectiveData data, CommunicationEventArgs comEventArgs) { if (CurrentStatus == DeviceStatusEnum.Idle) { comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; } else { // 进入普通轮询状态 CurrentStatus = DeviceStatusEnum.Idle; comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; } StartIdleLoop(data.DirectiveId); }
public override void Next(SerialPortEventArgs args) { var comEventArgs = new CommunicationEventArgs { Command = args.Command, DirectiveId = args.Result.Data.DirectiveId, DeviceType = args.Result.Data.DeviceType, DeviceId = args.Result.Data.DeviceId, Description = args.Message, Data = args.Result.Data }; this.Status.Handle(args.Result.SourceDirectiveType, args.Result.Data, comEventArgs); OnCommunication(comEventArgs); }
public virtual void ProcessIdleResult(DirectiveData data, CommunicationEventArgs comEventArgs) { if (CurrentStatus == DeviceStatusEnum.Idle) { comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; } else { // 进入普通轮询状态 SetStatus(DeviceStatusEnum.Idle); comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; } StartIdleLoop(); }
private void ServerOnDataReceived(object sender, CommunicationEventArgs e) { SessionLog.WriteLine("Data received " + e.Data); if (e.Exception == null) { DispatchMessage((TcpProtocolDtoBase)e.Data, e.Channel); } else { SessionLog.WriteLine("RPC Exception " + e.Exception + " critical: " + e.Exception.StopChannel); if (e.Exception.StopChannel) { Stop(); } } }
public override void OnCommunicationChange(CommunicationEventArgs e) { base.OnCommunicationChange(e); //HandleSystemStatusChange(e); HandleDeviceStatusChange(e); if (e.DeviceStatus != DeviceStatusEnum.Startting && e.DeviceStatus != DeviceStatusEnum.Pausing) { var data = e.Data as PumpDirectiveData; if (data != null) { Center.SyncPumpWithServer(data.DeviceId); } } }
//传感器只收发普通轮询指令 public override void ProcessRunningDirectiveResult(DirectiveData data, CommunicationEventArgs comEventArgs) { if (CurrentStatus == DeviceStatusEnum.Startting) { SetStatus(DeviceStatusEnum.Running); comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartEvent.TrySetResult(new DeviceIOResult(true)); OnCommunicationChange(comEventArgs); StartRunningLoop(); } else if (CurrentStatus == DeviceStatusEnum.Running) { comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartRunningLoop(); } }
//监听触发状态改变的指令 private void CommunicationChange(object sender, CommunicationEventArgs e) { if (e == null) { return; } if (e.DeviceStatus == DeviceStatusEnum.Idle) { App.Status = SysStatusEnum.Discarded; } else { if (App.Status == SysStatusEnum.Starting) { App.Status = SysStatusEnum.Running; } } Debug.WriteLine($"****************************{e.DeviceId}->{e.DeviceStatus}***********************"); }
protected override void ProcessPausingResult(DirectiveData data, CommunicationEventArgs comEventArgs) { var ret = data as PumpDirectiveData; if (ret != null && ret.FlowRate <= 0) { comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; comEventArgs.Description = IdleDesc.Paused.ToString();; CurrentStatus = DeviceStatusEnum.Idle; stopEvent.Set(new DeviceIOResult(true)); OnCommunicationChangeEvent(comEventArgs); } else { comEventArgs.DeviceStatus = DeviceStatusEnum.Pausing; StartPauseLoop(data.DirectiveId); } }
public override void OnCommunication(CommunicationEventArgs e) { base.OnCommunication(e); if (e.Data.DirectiveType == DirectiveTypeEnum.Running || e.Data.DirectiveType == DirectiveTypeEnum.Idle || e.Data.DirectiveType == DirectiveTypeEnum.Pausing) { HandleDeviceStatusChange(new IoStatusChangeEventArgs() { DeviceId = e.DeviceId, DeviceType = e.DeviceType, IoStatus = e.DeviceStatus, Delta = 0, Feedback = e.Data }); Center.SyncRockerWithServer(); } }
protected override void ProcessRunningDirectiveResult(DirectiveData data, CommunicationEventArgs comEventArgs) { var ret = data as PumpDirectiveData; if (CurrentStatus == DeviceStatusEnum.Startting) { if (ret?.FlowRate > 0) { CurrentStatus = DeviceStatusEnum.Running; comEventArgs.DeviceStatus = DeviceStatusEnum.Running; OnCommunicationChangeEvent(comEventArgs); StartRunningLoop(); } else { comEventArgs.DeviceStatus = CurrentStatus; StartRunningLoop(data.DirectiveId); } } else if (CurrentStatus == DeviceStatusEnum.Running) { if (ret != null && ret.FlowRate <= 0) { CurrentStatus = DeviceStatusEnum.Idle; comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; var diResult = new DeviceIOResult(true, comEventArgs); startEvent.Set(diResult); } else { comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartRunningLoop(data.DirectiveId); } } else { StartRunningLoop(); } }
public override void ProcessRunningDirectiveResult(DirectiveData data, CommunicationEventArgs comEventArgs) { var ret = data as PumpDirectiveData; if (CurrentStatus == DeviceStatusEnum.Startting) { //从tryStart变为running(真的开始) if (ret?.FlowRate > 0) { this.SetStatus(DeviceStatusEnum.Running); comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartEvent.TrySetResult(new DeviceIOResult(true)); OnCommunicationChange(comEventArgs); } else//泵收到开始命令 但还未运行 { comEventArgs.DeviceStatus = CurrentStatus; } StartRunningLoop(); } else if (CurrentStatus == DeviceStatusEnum.Running) { //泵输入/输出指定流量后停止 if (ret != null && ret.FlowRate <= 0) { this.SetStatus(DeviceStatusEnum.Idle); comEventArgs.DeviceStatus = DeviceStatusEnum.Idle; comEventArgs.Description = IdleDesc.Completed.ToString(); OnCommunicationChange(comEventArgs); } else//泵正在运行 { comEventArgs.DeviceStatus = DeviceStatusEnum.Running; StartRunningLoop(); } } }
static void CommandSend(object communication, CommunicationEventArgs arg) { _lastcmd = arg.Info; }
static void CommandError(object communication, CommunicationEventArgs arg) { Console.WriteLine(_lastcmd + ": " + arg.Info); }