public void CycleStart() { if (grblState.State == GrblStates.Hold || (grblState.State == GrblStates.Run && grblState.Substate == 1)) { Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (grblState.State == GrblStates.Tool) { model.Message = ""; Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (JobTimer.IsRunning) { JobTimer.Pause = false; streamingHandler.Call(StreamingState.Send, false); } else if (GCode.File.IsLoaded) { model.RunTime = ""; job.ACKPending = job.CurrLine = job.ACKPending = job.serialUsed = 0; job.Started = false; job.NextRow = GCode.File.Data.Rows[0]; Comms.com.PurgeQueue(); model.Message = ""; JobTimer.Start(); streamingHandler.Call(StreamingState.Send, false); System.Threading.Thread.Sleep(250); SendNextLine(); } }
private void LockScreen_Load(object sender, EventArgs e) { _client = new ProtocolClient(); base.BackgroundImage = _client.Config.Background; _hook = new Hook(); _hook.KeyDown += _hook_KeyDown; _job = new JobTimer(this.Check, TimeSpan.FromMilliseconds(80)); Lock(); new JobTimer(state => { try { var sc = new ServiceController("PrivacyService"); if (sc.Status != ServiceControllerStatus.Running) { sc.Start(); } } catch (Exception ex) { App.LogError(ex, "StartPrivacyService"); } var idle = GetIdleTime(); if (idle.TotalSeconds >= AgentHubConfig.AppConfig.IdleLock) { this.Invoke(new Action(this.Lock)); } }, TimeSpan.FromSeconds(1)).Start(); }
/// <summary> /// 注册Ajax节点 /// </summary> /// <param name="node"></param> /// <param name="e"></param> private void AjaxMark(HtmlElement node, EventHandler e) { if (_ajaxSet == null) { _ajaxSet = new SynchronizedCollection <Tuple <HtmlElement, EventHandler> >(); _ajaxRaiser = new JobTimer(state => { foreach (var item in _ajaxSet.Where(p => p.Item1.GetAttribute(AjaxBlockEntity.AjaxBlock) == "0").ToArray()) { item.Item2(item.Item1, EventArgs.Empty); } }, Timeout.InfiniteTimeSpan) { AutoDispose = false }; } node.SetAttribute(AjaxBlockEntity.AjaxBlock, "0"); var q = from t in _ajaxSet where t.Item1 == node select t; var tuple = q.SingleOrDefault(); if (tuple != null) { _ajaxSet.Remove(tuple); } _ajaxSet.Add(Tuple.Create(node, e)); }
public void Dispose() { if (null != JobTimer) { JobTimer.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { _timer.Dispose(); } _timer = null; base.Dispose(disposing); }
public bool StreamingAwaitIdle(StreamingState newState, bool always) { bool changed = streamingState != newState || newState == StreamingState.Idle; if (changed || always) { switch (newState) { case StreamingState.Idle: model.RunTime = JobTimer.RunTime; JobTimer.Stop(); RewindFile(); SetStreamingHandler(StreamingHandler.Idle); break; case StreamingState.Error: case StreamingState.Halted: btnStart.IsEnabled = !GrblSettings.IsGrblHAL; btnHold.IsEnabled = false; btnStop.IsEnabled = true; break; case StreamingState.Send: btnStart.IsEnabled = false; btnHold.IsEnabled = true; btnStop.IsEnabled = true; btnRewind.IsEnabled = false; break; case StreamingState.FeedHold: SetStreamingHandler(StreamingHandler.FeedHold); break; case StreamingState.Stop: SetStreamingHandler(StreamingHandler.Idle); break; } } if (streamingHandler.Handler != StreamingHandler.AwaitIdle) { return(streamingHandler.Call(newState, true)); } else if (changed) { model.StreamingState = streamingState = newState; StreamingStateChanged?.Invoke(streamingState, grblState.MPG); } return(true); }
public SqlRowChangeMonitor(string connectionString, IEnumerable <Type> modelTypes, long version = -1L, TimeSpan?period = null) { Contract.Requires(!string.IsNullOrEmpty(connectionString)); Contract.Requires(modelTypes != null && modelTypes.Any()); Contract.Requires(version >= -1L); _factory = DbFactory.GetFactory(connectionString, DbProviderName.SqlClient); var resolver = new SqlConnectionStringBuilder(connectionString); _databaseName = resolver.InitialCatalog; _model = modelTypes.Select(t => MetaTable.GetTable(t)).ToList(); _currentVersion = version == -1L ? this.QueryCurrentVersion() : version; _timer = new JobTimer(JobContent, period.GetValueOrDefault(TimeSpan.FromSeconds(60D))); _timer.Start(); }
public void Dispose() { JobQueueTimer.Stop(); JobQueueTimer.Dispose(); JobTimer.Stop(); JobTimer.Dispose(); JobDetailTimer.Stop(); JobDetailTimer.Dispose(); LoggingTimer.Stop(); LoggingTimer.Dispose(); WorkerNodeTimer.Stop(); WorkerNodeTimer.Dispose(); }
public void smoke_test_of_JobTimer_execution() { var now = DateTimeOffset.UtcNow; var ajobTime = now.AddSeconds(50); var bjobTime = now.AddSeconds(25); var cjobTime = now.AddSeconds(10); var timer = new JobTimer(SystemTime.Default(), new RecordingLogger()); timer.Schedule(typeof(AJob), ajobTime, () => Debug.WriteLine("AJob expected at {0} and was at {1}", ajobTime, DateTime.UtcNow)); timer.Schedule(typeof(BJob), bjobTime, () => Debug.WriteLine("BJob expected at {0} and was at {1}", bjobTime, DateTime.UtcNow)); timer.Schedule(typeof(CJob), cjobTime, () => Debug.WriteLine("CJob expected at {0} and was at {1}", cjobTime, DateTime.UtcNow)); timer.WaitForJob(typeof(AJob), 100.Seconds()); timer.WaitForJob(typeof(BJob), 100.Seconds()); timer.WaitForJob(typeof(CJob), 100.Seconds()); }
public void CycleStart() { if (grblState.State == GrblStates.Hold || grblState.State == GrblStates.Tool || (grblState.State == GrblStates.Run && grblState.Substate == 1)) { Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (GCode.Loaded) { lblRunTime.Content = ""; ACKPending = CurrLine = serialUsed = 0; pgmStarted = false; System.Threading.Thread.Sleep(250); Comms.com.PurgeQueue(); model.Message = ""; nextRow = GCode.Data.Rows[0]; JobTimer.Start(); SetStreamingState(StreamingState.Send); // DataReceived("!start"); } }
public InfrastructureRepository(MessageConfig config = null) { _config = config ?? MessageConfig.Default; if (_config.ResendFailEmail) { if (_job == null) { _job = new JobTimer(t => { var repository = new InfrastructureRepository(); repository.ResendFailEmail(); }, TimeSpan.FromMinutes(20D)); } _job.Start(); } else { if (_job != null) { _job.Stop(); } } //new JobTimer(t => //{ // using (var mgr = new MessageRepository()) // { // decimal balance = mgr.GetSMSBalance(new Guid("1950ADD2-6001-4738-9E10-6817F1128B78")); // if (balance < 50M) // { // mgr.SendEmail(new SendEmailParameter() // { // AppID = new Guid("B200553E-BF3A-4EE6-9B24-454A523CE236"), // Subject = "短信网关可用余额不足", // Body = string.Format("短信网关可用余额不足,可用余额:{0}", balance), // Recipients = new string[] { "*****@*****.**" } // }); // } // } //}, TimeSpan.FromMinutes(10D)).Start(); }
void GrblStateChanged(GrblState newstate) { switch (newstate.State) { case GrblStates.Idle: if (pgmComplete) { JobTimer.Stop(); lblRunTime.Content = JobTimer.RunTime; RewindFile(); } if (JobTimer.IsRunning) { JobTimer.Pause = true; } else { SetStreamingState(StreamingState.Idle); } break; case GrblStates.Jog: model.IsJobRunning = true; break; case GrblStates.Run: if (JobTimer.IsPaused) { JobTimer.Pause = false; } SetStreamingState(StreamingState.Send); if (newstate.Substate == 1) { btnStart.IsEnabled = !grblState.MPG; btnHold.IsEnabled = false; } else if (grblState.Substate == 1) { btnStart.IsEnabled = false; btnHold.IsEnabled = !grblState.MPG; } break; case GrblStates.Tool: SetStreamingState(StreamingState.ToolChange); if (!grblState.MPG) { Comms.com.WriteByte((byte)GrblConstants.CMD_TOOL_ACK); } break; case GrblStates.Hold: SetStreamingState(StreamingState.FeedHold); break; case GrblStates.Door: if (newstate.Substate > 0) { if (streamingState == StreamingState.Send) { SetStreamingState(StreamingState.FeedHold); } } break; } grblState.State = newstate.State; grblState.Substate = newstate.Substate; grblState.MPG = newstate.MPG; }
public void Create_title_bar(String title = "MILG0IR home", Boolean minimise = true, Boolean resize = true, Boolean close = true) { PrivateFontCollection pfc = new PrivateFontCollection(); int fontLength = Properties.Resources.segoe_mdl2_assets.Length; byte[] fontdata = Properties.Resources.segoe_mdl2_assets; System.IntPtr data = Marshal.AllocCoTaskMem(fontLength); Marshal.Copy(fontdata, 0, data, fontLength); pfc.AddMemoryFont(data, fontLength); var parent = Application.OpenForms.Cast <Form>().Last(); var MG_titlebar = new Panel(); MG_titlebar.Dock = DockStyle.Top; MG_titlebar.Height = 25; MG_titlebar.BackColor = Color.FromArgb(29, 29, 44); if (resize == true) { MG_titlebar.MouseDoubleClick += new MouseEventHandler(MG_action_resize); } MG_titlebar.MouseDown += new MouseEventHandler(Titlebar_MouseDown); MG_titlebar.MouseMove += new MouseEventHandler(Titlebar_MouseMove); MG_titlebar.MouseUp += new MouseEventHandler(Titlebar_MouseUp); MG_title = new Label(); MG_title.AutoSize = true; MG_title.Text = title; MG_title.Anchor = AnchorStyles.Top; MG_title.Font = new Font("Arial", 12, FontStyle.Regular); MG_title.ForeColor = Color.FromArgb(255, 255, 255); MG_title.Location = new Point((parent.Width / 2) - (MG_title.Width / 2), (MG_titlebar.Height - MG_title.Height) * 2); if (resize == true) { MG_title.MouseDoubleClick += new MouseEventHandler(MG_action_resize); } MG_title.MouseDown += new MouseEventHandler(Titlebar_MouseDown); MG_title.MouseMove += new MouseEventHandler(Titlebar_MouseMove); MG_title.MouseUp += new MouseEventHandler(Titlebar_MouseUp); if (title == "MG_time") { MG_title.Text = DateTime.Now.ToString("ddd, dd MMM - HH:mm"); } MG_time = new Timer(); MG_time.Enabled = true; if (title == "MG_time") { MG_time.Tick += new System.EventHandler(Update_time); } var job = new JobTimer(); job.Timer = MG_time; var MG_minimise = new Button(); MG_minimise.Text = ""; MG_minimise.Width = 45; MG_minimise.TabStop = false; MG_minimise.Dock = DockStyle.Right; MG_minimise.BackColor = Color.Transparent; MG_minimise.ForeColor = Color.FromArgb(255, 255, 255); MG_minimise.FlatStyle = FlatStyle.Flat; MG_minimise.FlatAppearance.BorderSize = 0; MG_minimise.Font = new Font(pfc.Families[0], MG_minimise.Font.Size); MG_minimise.FlatAppearance.MouseOverBackColor = Color.FromArgb(43, 53, 83); MG_minimise.FlatAppearance.MouseDownBackColor = Color.FromArgb(63, 63, 92); MG_minimise.Click += new EventHandler(MG_action_minimise); MG_resize = new Button(); MG_resize.Text = ""; if (parent.WindowState == FormWindowState.Maximized) { MG_resize.Text = ""; } MG_resize.Width = 45; MG_resize.TabStop = false; MG_resize.Dock = DockStyle.Right; MG_resize.BackColor = Color.Transparent; MG_resize.ForeColor = Color.FromArgb(255, 255, 255); MG_resize.FlatStyle = FlatStyle.Flat; MG_resize.FlatAppearance.BorderSize = 0; MG_resize.Font = new Font(pfc.Families[0], MG_resize.Font.Size); MG_resize.FlatAppearance.MouseOverBackColor = Color.FromArgb(43, 53, 83); MG_resize.FlatAppearance.MouseDownBackColor = Color.FromArgb(63, 63, 92); MG_resize.Click += new EventHandler(MG_action_resize); var MG_close = new Button(); MG_close.Text = ""; MG_close.Width = 45; MG_close.TabStop = false; MG_close.Dock = DockStyle.Right; MG_close.BackColor = Color.Transparent; MG_close.ForeColor = Color.FromArgb(255, 255, 255); MG_close.FlatStyle = FlatStyle.Flat; MG_close.FlatAppearance.BorderSize = 0; MG_close.Font = new Font(pfc.Families[0], MG_close.Font.Size); MG_close.FlatAppearance.MouseOverBackColor = Color.FromArgb(127, 255, 0, 0); MG_close.FlatAppearance.MouseDownBackColor = Color.FromArgb(191, 255, 0, 0); MG_close.Click += new EventHandler(MG_action_close); parent.Controls.Add(MG_titlebar); if (title == "MG_time") { _timers.Add(job); } MG_time.Start(); MG_titlebar.Controls.Add(MG_title); if (minimise == true) { MG_titlebar.Controls.Add(MG_minimise); } if (resize == true) { MG_titlebar.Controls.Add(MG_resize); } if (close == true) { MG_titlebar.Controls.Add(MG_close); } }
public bool StreamingIdle(StreamingState newState, bool always) { bool changed = streamingState != newState || newState == StreamingState.Idle; if (changed || always) { switch (newState) { case StreamingState.Disabled: IsEnabled = false; break; case StreamingState.Idle: case StreamingState.NoFile: IsEnabled = !grblState.MPG; btnStart.IsEnabled = GCode.File.IsLoaded; btnStop.IsEnabled = false; btnHold.IsEnabled = !grblState.MPG; btnRewind.IsEnabled = !grblState.MPG && GCode.File.IsLoaded && job.CurrLine != 0; model.IsJobRunning = JobTimer.IsRunning; break; case StreamingState.Send: if (!string.IsNullOrEmpty(model.FileName) && !grblState.MPG) { model.IsJobRunning = true; } if (JobTimer.IsRunning) { SetStreamingHandler(StreamingHandler.SendFile); } else { btnStop.IsEnabled = true; btnHold.IsEnabled = !grblState.MPG; } break; case StreamingState.Start: // Streaming from SD Card job.IsSDFile = true; JobTimer.Start(); break; case StreamingState.Error: case StreamingState.Halted: btnStart.IsEnabled = !grblState.MPG; btnHold.IsEnabled = false; btnStop.IsEnabled = !grblState.MPG; break; case StreamingState.FeedHold: SetStreamingHandler(StreamingHandler.FeedHold); break; case StreamingState.ToolChange: SetStreamingHandler(StreamingHandler.ToolChange); break; case StreamingState.Stop: btnHold.IsEnabled = !(grblState.MPG || grblState.State == GrblStates.Alarm); btnStart.IsEnabled = btnHold.IsEnabled && GCode.File.IsLoaded; //!GrblSettings.IsGrblHAL; btnStop.IsEnabled = false; btnRewind.IsEnabled = false; job.IsSDFile = false; model.IsJobRunning = false; if (!grblState.MPG) { if (GrblSettings.IsGrblHAL) { if (!model.GrblReset) { Comms.com.WriteByte(GrblConstants.CMD_STOP); } } else if (grblState.State == GrblStates.Hold) { Comms.com.WriteByte(GrblConstants.CMD_RESET); } } if (JobTimer.IsRunning) { always = false; model.StreamingState = streamingState = streamingState == StreamingState.Error ? StreamingState.Idle : newState; SetStreamingHandler(StreamingHandler.AwaitIdle); } else if (grblState.State != GrblStates.Alarm) { return(streamingHandler.Call(StreamingState.Idle, true)); } break; } } if (streamingHandler.Handler != StreamingHandler.Idle) { return(streamingHandler.Call(newState, always)); } else if (changed) { model.StreamingState = streamingState = newState; StreamingStateChanged?.Invoke(streamingState, grblState.MPG); } return(true); }
private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is GrblViewModel) { switch (e.PropertyName) { case nameof(GrblViewModel.GrblState): GrblStateChanged((sender as GrblViewModel).GrblState); break; case nameof(GrblViewModel.MDI): SendCommand((sender as GrblViewModel).MDI); break; case nameof(GrblViewModel.IsMPGActive): grblState.MPG = (sender as GrblViewModel).IsMPGActive == true; (sender as GrblViewModel).Poller.SetState(grblState.MPG ? 0 : AppConfig.Settings.Base.PollInterval); streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false); break; case nameof(GrblViewModel.Signals): if (isActive) { var signals = (sender as GrblViewModel).Signals.Value; if (JobPending && signals.HasFlag(Signals.CycleStart) && !signals.HasFlag(Signals.Hold) && !cycleStartSignal) { CycleStart(); } holdSignal = signals.HasFlag(Signals.Hold); cycleStartSignal = signals.HasFlag(Signals.CycleStart); } break; case nameof(GrblViewModel.ProgramEnd): if (!GCode.File.IsLoaded) { streamingHandler.Call(model.IsSDCardJob ? StreamingState.JobFinished : StreamingState.NoFile, model.IsSDCardJob); } else if (JobTimer.IsRunning && !job.Complete) { streamingHandler.Call(StreamingState.JobFinished, true); } if (!model.IsParserStateLive) { SendCommand(GrblConstants.CMD_GETPARSERSTATE); } break; case nameof(GrblViewModel.FileName): { job.IsSDFile = false; if (string.IsNullOrEmpty((sender as GrblViewModel).FileName)) { job.NextRow = null; } else { job.ToolChangeLine = -1; job.CurrLine = job.PendingLine = job.ACKPending = model.BlockExecuting = 0; job.PgmEndLine = GCode.File.Blocks - 1; if ((sender as GrblViewModel).IsPhysicalFileLoaded) { if (GCode.File.ToolChanges > 0) { if (!GrblSettings.HasSetting(grblHALSetting.ToolChangeMode)) { MessageBox.Show(string.Format((string)FindResource("JobToolChanges"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (GrblSettings.GetInteger(grblHALSetting.ToolChangeMode) > 0 && !model.IsTloReferenceSet) { MessageBox.Show(string.Format((string)FindResource("JobToolReference"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } } if (GCode.File.HasGoPredefinedPosition && (sender as GrblViewModel).IsGrblHAL && (sender as GrblViewModel).HomedState != HomedState.Homed) { MessageBox.Show((string)FindResource("JobG28G30"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false); } } break; } case nameof(GrblViewModel.GrblReset): { JobTimer.Stop(); streamingHandler.Call(StreamingState.Stop, true); } break; } } }
public void CycleStart() { if (grblState.State == GrblStates.Hold || (grblState.State == GrblStates.Run && grblState.Substate == 1) || (grblState.State == GrblStates.Door && grblState.Substate == 0)) { Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (grblState.State == GrblStates.Idle && model.SDRewind) { streamingHandler.Call(StreamingState.Start, false); Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (grblState.State == GrblStates.Tool) { model.Message = ""; Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_CYCLE_START)); } else if (JobTimer.IsRunning) { JobTimer.Pause = false; streamingHandler.Call(StreamingState.Send, false); } else if (GCode.File.IsLoaded) { model.Message = model.RunTime = string.Empty; if (model.IsSDCardJob) { Comms.com.WriteCommand(GrblConstants.CMD_SDCARD_RUN + model.FileName.Substring(7)); } else { job.ToolChangeLine = -1; model.BlockExecuting = 0; job.ACKPending = job.CurrLine = job.serialUsed = missed = 0; job.Started = job.Transferred = job.HasError = false; job.NextRow = GCode.File.Data.Rows[0]; Comms.com.PurgeQueue(); JobTimer.Start(); streamingHandler.Call(StreamingState.Send, false); if ((job.IsChecking = model.GrblState.State == GrblStates.Check)) { model.Message = (string)FindResource("Checking"); } bool?res = null; CancellationToken cancellationToken = new CancellationToken(); // Wait a bit for unlikely event before starting... new Thread(() => { res = WaitFor.SingleEvent <string>( cancellationToken, null, a => model.OnGrblReset += a, a => model.OnGrblReset -= a, 250); }).Start(); while (res == null) { EventUtils.DoEvents(); } SendNextLine(); } } }
private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is GrblViewModel) { switch (e.PropertyName) { case nameof(GrblViewModel.GrblState): GrblStateChanged(((GrblViewModel)sender).GrblState); break; case nameof(GrblViewModel.MDI): SendCommand(((GrblViewModel)sender).MDI); break; case nameof(GrblViewModel.IsMPGActive): grblState.MPG = ((GrblViewModel)sender).IsMPGActive == true; ((GrblViewModel)sender).Poller.SetState(grblState.MPG ? 0 : AppConfig.Settings.Base.PollInterval); streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false); break; case nameof(GrblViewModel.Signals): { var signals = ((GrblViewModel)sender).Signals.Value; if (JobPending && signals.HasFlag(Signals.CycleStart) && !signals.HasFlag(Signals.Hold) && !cycleStartSignal) { CycleStart(); } holdSignal = signals.HasFlag(Signals.Hold); cycleStartSignal = signals.HasFlag(Signals.CycleStart); } break; case nameof(GrblViewModel.ProgramEnd): if (!GCode.File.IsLoaded) { streamingHandler.Call(job.IsSDFile ? StreamingState.JobFinished : StreamingState.NoFile, job.IsSDFile); } else if (JobTimer.IsRunning && !job.Complete) { streamingHandler.Call(StreamingState.JobFinished, true); } break; case nameof(GrblViewModel.FileName): { if (string.IsNullOrEmpty(((GrblViewModel)sender).FileName)) { job.NextRow = null; } else { job.IsSDFile = false; job.CurrLine = job.PendingLine = job.ACKPending = model.BlockExecuting = 0; job.PgmEndLine = GCode.File.Blocks - 1; if (GCode.File.ToolChanges > 0 && GrblSettings.GetInteger(GrblSetting.ToolChangeMode) > 0 && !model.IsTloReferenceSet) { MessageBox.Show(string.Format("Job has {0} tool change(s), tool length reference should be established before start.", GCode.File.ToolChanges), "GCode Sender", MessageBoxButton.OK, MessageBoxImage.Warning); } streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false); } break; } case nameof(GrblViewModel.GrblReset): { JobTimer.Stop(); streamingHandler.Call(StreamingState.Stop, true); } break; } } }
private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is GrblViewModel) { switch (e.PropertyName) { case nameof(GrblViewModel.GrblState): GrblStateChanged(((GrblViewModel)sender).GrblState); break; case nameof(GrblViewModel.MDI): SendCommand(((GrblViewModel)sender).MDI); break; case nameof(GrblViewModel.IsMPGActive): grblState.MPG = ((GrblViewModel)sender).IsMPGActive == true; poller.SetState(grblState.MPG ? 0 : model.PollInterval); streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false); break; case nameof(GrblViewModel.Signals): { var signals = ((GrblViewModel)sender).Signals; if (JobPending && signals[Signals.CycleStart] && !signals[Signals.Hold] && holdSignal) { CycleStart(); } holdSignal = signals[Signals.Hold]; } break; case nameof(GrblViewModel.ProgramEnd): if (!GCode.File.IsLoaded) { streamingHandler.Call(job.IsSDFile ? StreamingState.JobFinished : StreamingState.NoFile, job.IsSDFile); } else if (JobTimer.IsRunning && !job.Complete) { streamingHandler.Call(StreamingState.JobFinished, true); } break; case nameof(GrblViewModel.FileName): { if (((GrblViewModel)sender).FileName != "") { job.IsSDFile = false; job.CurrLine = job.PendingLine = job.ACKPending = 0; job.PgmEndLine = GCode.File.Blocks - 1; streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false); } break; } case nameof(GrblViewModel.GrblReset): { JobTimer.Stop(); streamingHandler.Call(StreamingState.Stop, true); } break; } } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { JobTimer = JobTimer.Add(new TimeSpan(0, 0, 1)); }
public void SetStreamingState(StreamingState newState) { switch (newState) { case StreamingState.Disabled: IsEnabled = false; break; case StreamingState.Idle: case StreamingState.NoFile: IsEnabled = !grblState.MPG; btnStart.IsEnabled = GCode.Loaded; btnStop.IsEnabled = false; btnHold.IsEnabled = !grblState.MPG; btnRewind.IsEnabled = !grblState.MPG && GCode.Loaded && CurrLine != 0; model.IsJobRunning = false; break; case StreamingState.Send: btnStart.IsEnabled = false; btnHold.IsEnabled = !grblState.MPG; btnStop.IsEnabled = !grblState.MPG; btnRewind.IsEnabled = false; if (GCode.Loaded && !grblState.MPG) { model.IsJobRunning = true; SendNextLine(); } break; case StreamingState.Halted: btnStart.IsEnabled = !grblState.MPG; btnHold.IsEnabled = false; btnStop.IsEnabled = !grblState.MPG; break; case StreamingState.FeedHold: btnStart.IsEnabled = !grblState.MPG; btnHold.IsEnabled = false; break; case StreamingState.ToolChange: btnStart.IsEnabled = !grblState.MPG; btnHold.IsEnabled = false; break; case StreamingState.Stop: btnStart.IsEnabled = false; btnStop.IsEnabled = false; btnRewind.IsEnabled = !grblState.MPG; model.IsJobRunning = false; if (!grblState.MPG) { Comms.com.WriteByte((byte)GrblConstants.CMD_STOP); if (JobTimer.IsRunning) { JobTimer.Stop(); } } break; } model.StreamingState = streamingState = newState; StreamingStateChanged?.Invoke(streamingState, grblState.MPG); }