Пример #1
0
        private void ProcessQueue()
        {
            _processing = true;
            Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(10)).TakeUntil(_stopSubject).Subscribe(
                l =>
            {
                if ((SystemCommands.TryPeekCommand(out var cmd) || ManualCommands.TryPeekCommand(out cmd) || FileCommands.TryPeekCommand(out cmd) || FileCommands.State != CommandSourceState.Running && _waitingCommandQueue.Count == 0 && MacroCommands.TryPeekCommand(out cmd)) && cmd != null && cmd.Data.RemoveSpace().Length + CommandQueueLength <= _bufferSizeLimit)
                {
                    var continueProcess = cmd.Source switch
                    {
                        CommandSourceType.System => SystemCommands.TryGetCommand(out cmd),
                        CommandSourceType.Macros => MacroCommands.TryGetCommand(out cmd),
                        CommandSourceType.Manual => ManualCommands.TryGetCommand(out cmd),
                        CommandSourceType.File => FileCommands.TryGetCommand(out cmd),
                        _ => false
                    };

                    if (!continueProcess)
                    {
                        return;
                    }

                    _commandPreProcessor.Process(ref cmd);

                    Send(cmd);
                }
            });
        }
Пример #2
0
        public void PurgeQueues()
        {
            while (_waitingCommandQueue.Count > 0)
            {
                _waitingCommandQueue.TryDequeue(out var dummy);
                CommandQueueLengthChanged?.Invoke(this, CommandQueueLength);
            }

            SystemCommands.Purge();
            ManualCommands.Purge();
            FileCommands.Purge();
            MacroCommands.Purge();
        }
        private void MacroCommands_MouseDoubleClick(object sender, EventArgs e)
        {
            MacroActionEditor edit = new MacroActionEditor();
            ListViewItem      item = MacroCommands.SelectedItems[0];

            edit.Init(item);
            edit.Location = System.Windows.Forms.Control.MousePosition;
            if (edit.ShowDialog() == DialogResult.OK)
            {
                item = edit.GetListViewItem();
                MacroCommands.Items[MacroCommands.SelectedIndices[0]] = item;
                ValidateMacroTiming();
            }
            MacroCommands.Invalidate();
        }
Пример #4
0
 private void ComServiceConnectionStateChanged(object sender, ConnectionState e)
 {
     if (e == ConnectionState.Online)
     {
         if (!_processing)
         {
             ProcessQueue();
         }
         SystemCommands.StartProcessing();
         ManualCommands.StartProcessing();
         MacroCommands.StartProcessing();
     }
     else
     {
         _stopSubject.OnNext(Unit.Default);
         _processing = false;
         SystemCommands.PauseProcessing();
         ManualCommands.PauseProcessing();
         MacroCommands.PauseProcessing();
     }
 }
Пример #5
0
        private void ComServiceLineReceived(object sender, string e)
        {
            lock (_lockObject)
            {
                _uiContext.Send(
                    x =>
                {
                    CommunicationLog.Insert(0, "grbl =>" + e);
                    if (CommunicationLog.Count > 500)
                    {
                        CommunicationLog.Remove(CommunicationLog.Last());
                    }
                }, null);

                var type = _responseTypeFinder.GetType(e);

                OnResponseReceived(new Response {
                    Data = e, Type = type
                });

                if ((type == ResponseType.Ok || type == ResponseType.Error || type == ResponseType.Alarm) && _waitingCommandQueue.Any() && _waitingCommandQueue.TryDequeue(out var cmd))
                {
                    CommandQueueLengthChanged?.Invoke(this, CommandQueueLength);
                    if (type == ResponseType.Ok)
                    {
                        cmd.ResultType = CommandResultType.Ok;
                    }
                    else if (type == ResponseType.Error)
                    {
                        cmd.ResultType         = CommandResultType.Error;
                        cmd.CommandResultCause = e.Split(':')[1];

                        if (cmd.Source == CommandSourceType.File)
                        {
                            FileCommands.PauseProcessing();
                        }
                        else if (cmd.Source == CommandSourceType.Macros)
                        {
                            MacroCommands.Purge();
                        }
                    }
                    else if (type == ResponseType.Alarm)
                    {
                        cmd.ResultType         = CommandResultType.Alarm;
                        cmd.CommandResultCause = e.Split(':')[1];

                        if (cmd.Source == CommandSourceType.File)
                        {
                            FileCommands.PauseProcessing();
                        }
                        else if (cmd.Source == CommandSourceType.Macros)
                        {
                            MacroCommands.Purge();
                        }
                    }

                    if (!string.IsNullOrEmpty(cmd.CommandOnResult))
                    {
                        SendAsync(cmd.CommandOnResult);
                    }

                    _uiContext.Send(
                        x =>
                    {
                        switch (cmd.Source)
                        {
                        case CommandSourceType.System:

                            SystemCommands.CommandList.Insert(0, cmd);
                            if (ManualCommands.CommandList.Count > 500)
                            {
                                ManualCommands.CommandList.Remove(ManualCommands.CommandList.Last());
                            }
                            break;

                        case CommandSourceType.Manual:

                            ManualCommands.CommandList.Insert(0, cmd);
                            if (ManualCommands.CommandList.Count > 500)
                            {
                                ManualCommands.CommandList.Remove(ManualCommands.CommandList.Last());
                            }
                            break;

                        case CommandSourceType.File:
                            FileCommands.CommandList.Add(cmd);
                            break;

                        case CommandSourceType.Macros:
                            MacroCommands.CommandList.Add(cmd);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        OnCommandFinished(cmd);
                        OnCommandListUpdated();
                    },
                        null);
                }
                else if (_waitingCommandQueue.Any() && _waitingCommandQueue.TryPeek(out var peekCmd))
                {
                    if (peekCmd.ExpectedResponses.Any(x => x == type))
                    {
                        peekCmd.Result += (string.IsNullOrEmpty(peekCmd.Result) ? "" : Environment.NewLine) + e;
                    }
                }
            }
        }