Пример #1
0
        public void DataReceived(string data)
        {
            if (data.Length == 0)
            {
                return;
            }

            //if (ResponseLogEnable)
            //    ResponseLog.Add(data);

            if (data.Substring(0, 1) == "<")
            {
                ParseStatus(data);

                OnRealtimeStatusProcessed?.Invoke(data);
            }
            else if (data.StartsWith("ALARM"))
            {
                string[] alarm = data.Split(':');

                SetGRBLState("Alarm", alarm.Length == 2 ? int.Parse(alarm[1]) : -1, false);
            }
            else if (data.StartsWith("[PRB:"))
            {
                ParseProbeStatus(data);
            }
            else if (data.StartsWith("[GC:"))
            {
                ParseGCStatus(data);
            }
            else if (data.StartsWith("[TLO:"))
            {
                data = "";
            }
            else if (data.StartsWith("["))
            {
                if (data.StartsWith("[MSG:"))
                {
                    Message = data;
                    if (data == "[MSG:Pgm End]")
                    {
                        ProgramEnd = true;
                    }
                } // else ignore?
            }
            else if (data.StartsWith("Grbl"))
            {
                GrblReset = true;
                OnGrblReset?.Invoke();
                _reset = false;
            }
            else if (StreamingState != StreamingState.Jogging)
            {
                if (data == "ok")
                {
                    OnCommandResponseReceived?.Invoke(data);
                }
                else
                {
                    if (data.StartsWith("error:"))
                    {
                        try
                        {
                            SetError(int.Parse(data.Substring(6)));
                        }
                        catch
                        {
                        }
                        OnCommandResponseReceived?.Invoke(data);
                    }
                    else if (!data.StartsWith("?"))
                    {
                        Message = data; //??
                    }
                }
            }
            OnResponseReceived?.Invoke(data);
        }
Пример #2
0
        public void DataReceived(string data)
        {
            if (data.Length == 0)
            {
                return;
            }

            if (ResponseLogVerbose || !(data.First() == '<' || data.First() == '$' || data.First() == 'o') || data.StartsWith("error"))
            {
                if (!(data.First() == '<' && ResponseLogFilterRT))
                {
                    ResponseLog.Add(data);
                    if (ResponseLog.Count > 200)
                    {
                        ResponseLog.RemoveAt(0);
                    }
                }
            }

            if (data.First() == '<')
            {
                ParseStatus(data);

                OnRealtimeStatusProcessed?.Invoke(data);
            }
            else if (data.StartsWith("ALARM"))
            {
                string[] alarm = data.Split(':');

                SetGRBLState("Alarm", alarm.Length == 2 ? int.Parse(alarm[1]) : -1, false);
            }
            else if (data.StartsWith("["))
            {
                switch (data.Substring(1, data.IndexOf(':') - 1))
                {
                case "PRB":
                    ParseProbeStatus(data);
                    break;

                case "GC":
                    ParseGCStatus(data);
                    break;

                case "TLR":
                    TloReference = dbl.Parse(data.Substring(5).TrimEnd(']'));
                    break;

                case "TLO":
                    // Workaround for legacy grbl, it reports only one offset...
                    ToolOffset.SuspendNotifications = true;
                    ToolOffset.Z = double.NaN;
                    ToolOffset.SuspendNotifications = false;
                    // End workaround

                    ToolOffset.Parse(data.Substring(5).TrimEnd(']'));

                    // Workaround for legacy grbl, copy X offset to Z (there is no info available for which axis...)
                    if (double.IsNaN(ToolOffset.Z))
                    {
                        ToolOffset.Z = ToolOffset.X == 0 ? double.NaN : ToolOffset.X;
                        ToolOffset.X = double.NaN;
                        OnPropertyChanged(nameof(IsToolOffsetActive));
                    }
                    // End workaround
                    break;

                case "HOME":
                    ParseHomedStatus(data);
                    break;

                case "MSG":
                    Message = data == "[MSG:]" ? string.Empty : data;
                    if (data == "[MSG:Pgm End]")
                    {
                        ProgramEnd = true;
                    }
                    break;
                }
            }

            else if (data.StartsWith("Grbl"))
            {
                if (Poller != null)
                {
                    Poller.SetState(0);
                }
                _grblState.State = GrblStates.Unknown;
                GrblReset        = true;
                OnGrblReset?.Invoke();
                _reset = false;
            }
            else if (_grblState.State != GrblStates.Jog)
            {
                if (data == "ok")
                {
                    OnCommandResponseReceived?.Invoke(data);
                }
                else
                {
                    if (data.StartsWith("error:"))
                    {
                        try
                        {
                            SetGrblError(int.Parse(data.Substring(6)));
                        }
                        catch
                        {
                        }
                        OnCommandResponseReceived?.Invoke(data);
                    }
                    else if (!data.StartsWith("?"))
                    {
                        //                 Message = data; //??
                    }
                }
            }
            OnResponseReceived?.Invoke(data);
        }
Пример #3
0
        public void DataReceived(string data)
        {
            if (data.Length == 0)
            {
                return;
            }

            if (ResponseLogVerbose || !(data.First() == '<' || data.First() == '$' || data.First() == 'o') || data.StartsWith("error"))
            {
                ResponseLog.Add(data);
                if (ResponseLog.Count > 200)
                {
                    ResponseLog.RemoveAt(0);
                }
            }

            if (data.First() == '<')
            {
                ParseStatus(data);

                OnRealtimeStatusProcessed?.Invoke(data);
            }
            else if (data.StartsWith("ALARM"))
            {
                string[] alarm = data.Split(':');

                SetGRBLState("Alarm", alarm.Length == 2 ? int.Parse(alarm[1]) : -1, false);
            }
            else if (data.StartsWith("[PRB:"))
            {
                ParseProbeStatus(data);
            }
            else if (data.StartsWith("[GC:"))
            {
                ParseGCStatus(data);
            }
            else if (data.StartsWith("[TLO:"))
            {
                ToolOffset.Parse(data);
            }
            else if (data.StartsWith("["))
            {
                if (data.StartsWith("[MSG:"))
                {
                    Message = data == "[MSG:]" ? string.Empty : data;
                    if (data == "[MSG:Pgm End]")
                    {
                        ProgramEnd = true;
                    }
                } // else ignore?
            }
            else if (data.StartsWith("Grbl"))
            {
                GrblReset        = true;
                _grblState.State = GrblStates.Unknown;
                OnGrblReset?.Invoke();
                _reset = false;
            }
            else if (_grblState.State != GrblStates.Jog)
            {
                if (data == "ok")
                {
                    OnCommandResponseReceived?.Invoke(data);
                }
                else
                {
                    if (data.StartsWith("error:"))
                    {
                        try
                        {
                            SetGrblError(int.Parse(data.Substring(6)));
                        }
                        catch
                        {
                        }
                        OnCommandResponseReceived?.Invoke(data);
                    }
                    else if (!data.StartsWith("?"))
                    {
                        //                 Message = data; //??
                    }
                }
            }
            OnResponseReceived?.Invoke(data);
        }