Beispiel #1
0
        private void OnMessageReceived(Grbl.GrblMessage msg)
        {
            var args = new GrblMessageReceivedEventArgs(msg);

            MessageReceived?.Invoke(this, args);
        }
Beispiel #2
0
 internal GrblMessageReceivedEventArgs(Grbl.GrblMessage message)
 {
     Message = message;
 }
Beispiel #3
0
        /// <summary>
        /// Parses the specified Grbl message.
        /// </summary>
        /// <param name="message">The Grbl message string.</param>
        /// <returns></returns>
        public static GrblMessage Parse(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            GrblMessage msg = null;

            if (message == "ok")
            {
                msg = new OkMessage();
            }
            else if (message.StartsWith("error:"))
            {
                msg = new ErrorMessage();
            }
            else if (message.StartsWith("<") && message.EndsWith(">"))
            {
                msg = new StatusReportMessage();
            }
            else if (message.StartsWith("Grbl "))
            {
                msg = new WelcomeMessage();
            }
            else if (message.StartsWith("ALARM:"))
            {
                msg = new AlarmMessage();
            }
            else if (message.StartsWith("$"))
            {
                msg = new SettingsPrintoutMessage();
            }
            else if (message.StartsWith("[MSG:"))
            {
                msg = new NonQueriedFeedbackMessage();
            }
            else if (message.StartsWith("[GC:"))
            {
                msg = new GcodeParserStateMessage();
            }
            else if (message.StartsWith("[HLP:"))
            {
                msg = new HelpMessage();
            }
            else if (message.StartsWith("[G5") ||
                     message.StartsWith("[G28:") ||
                     message.StartsWith("[G30:") ||
                     message.StartsWith("[G92:"))
            {
                msg = new CoordinateSettingMessage();
            }
            else if (message.StartsWith("[PRB:"))
            {
                msg = new ProbeSettingMessage();
            }
            else if (message.StartsWith("[TLO:"))
            {
                msg = new ToolLengthOffsetMessage();
            }
            else if (message.StartsWith("[VER:"))
            {
                msg = new VersionMessage();
            }
            else if (message.StartsWith("[OPT:"))
            {
                msg = new CompileOptionPrintoutMessage();
            }
            else if (message.StartsWith("[echo:"))
            {
                msg = new EchoMessage();
            }
            else if (message.StartsWith(">"))
            {
                msg = new StartupLineResponseMessage();
            }
            else
            {
                msg = new UnknownMessage();
            }
            msg.MessageBody = message;
            msg.OnLoadMessage(message);
            return(msg);
        }