/// <summary> /// Process the serial port error message reply. /// </summary> /// <param name="data"></param> /// <returns></returns> public void ProcessErrorResponse(string data) { ResponseStatus = RespStatus.Ok;//It is an error but still ok to send next command if (!string.IsNullOrEmpty(data)) { if (VersionGrbl.StartsWith("1", StringComparison.InvariantCulture))//In version 1.1 all error codes have ID { ErrorMessage = GrblErrorCode.ErrorDict11[data.Split(':')[1]]; logger.Info("GrblTool|ProcessErrorResponse|Error key:{0} | description:{1}", data.Split(':')[1], ErrorMessage); } else { if (data.Contains("ID"))//In version 0.9 only error code from 23 to 37 have ID { ErrorMessage = GrblErrorCode.ErrorDict09[data.Split(':')[2]]; logger.Info("GrblTool|ProcessErrorResponse|Error key {0} | description:{1}", data.Split(':')[2], ErrorMessage); } else//Error codes w/o ID { ErrorMessage = GrblErrorCode.ErrorDict09[data.Split(':')[1]]; logger.Info("GrblTool|ProcessErrorResponse|Error key {0} | description:{1}", data.Split(':')[1], ErrorMessage); } } } }
/// <summary> /// Process the serial port alarm message reply. /// </summary> /// <param name="data"></param> /// <returns></returns> public void ProcessAlarmResponse(string data) { ResponseStatus = RespStatus.NOk; MachineStatusColor = Brushes.Red; MachineStatus = MachStatus.Alarm; logger.Info("GrblTool|ProcessResponse|Data:{0}|RespStatus:{1}|MachStatus:{2}", data, ResponseStatus.ToString(), MachineStatus.ToString()); if (!string.IsNullOrEmpty(data)) { if (VersionGrbl.StartsWith("1", StringComparison.InvariantCulture)) { AlarmMessage = GrblAlarmCodec.AlarmDict11[data.Split(':')[1]]; logger.Info("GrblTool|ProcessAlarmResponse11|Alarm key {0} | description:{1}", data.Split(':')[1], AlarmMessage); } else { AlarmMessage = GrblAlarmCodec.AlarmDict09[data.Split(':')[1]]; logger.Info("GrblTool|ProcessAlarmResponse09|Alarm key {0} | description:{1}", data.Split(':')[1], AlarmMessage); } } }
/// <summary> /// Get coordinates and status depending of Grbl version 0.9 or 1.1. /// </summary> /// <param name="data"></param> public void ProcessCurrentStatusResponse(string data) { if (!string.IsNullOrEmpty(data)) { ResponseStatus = RespStatus.Ok; if (data.Contains("|") || VersionGrbl.StartsWith("1", StringComparison.InvariantCulture))//Report state Grbl v1.1 < Idle|MPos:0.000,0.000,0.000> { string[] arr = data.Split(new Char[] { '<', '>', ',', ':', '\r', '\n', '|' }); if (data.Contains("mpos")) { MachinePositionX = arr[3]; MachinePositionY = arr[4]; WorkPositionX = "0"; WorkPositionY = "0"; } else { WorkPositionX = arr[3]; WorkPositionY = arr[4]; MachinePositionX = "0"; MachinePositionY = "0"; } if (!data.Contains("bf")) { MachineFeed = arr[7]; MachineSpeed = arr[8]; PlannerBuffer = "0"; RxBuffer = "0"; if (data.Contains("wco")) { OffsetPositionX = arr[10]; OffsetPositionY = arr[11]; //Normaly WorkPositionX = MachinePositionX - OffsetPositionX; use a converter string to int first and then calculate... } if (data.Contains("Ov")) { //Override value for feed, rapids and spindle speed OverrideMachineFeed = arr[10]; OverrideMachineSpeed = arr[12]; } } else { PlannerBuffer = arr[7]; RxBuffer = arr[8]; MachineFeed = arr[10]; MachineSpeed = arr[11]; if (data.Contains("wco")) { OffsetPositionX = arr[13]; OffsetPositionY = arr[14]; //Normaly WorkPositionX = MachinePositionX - OffsetPositionX; use a converter string to int first and then calculate... } if (data.Contains("Ov")) { //Override value for feed, rapids and spindle speed OverrideMachineFeed = arr[13]; OverrideMachineSpeed = arr[15]; } } switch (arr[1]) { case "idle": MachineStatus = MachStatus.Idle; MachineStatusColor = Brushes.Beige; break; case "run": MachineStatus = MachStatus.Run; MachineStatusColor = Brushes.LightGreen; break; case "hold": MachineStatus = MachStatus.Hold; MachineStatusColor = Brushes.LightBlue; break; case "alarm": MachineStatus = MachStatus.Alarm; MachineStatusColor = Brushes.Red; break; case "jog": MachineStatus = MachStatus.Jog; MachineStatusColor = Brushes.LightSeaGreen; break; case "door": MachineStatus = MachStatus.Door; MachineStatusColor = Brushes.LightYellow; break; case "check": MachineStatus = MachStatus.Check; MachineStatusColor = Brushes.LightCyan; break; case "home": MachineStatus = MachStatus.Home; MachineStatusColor = Brushes.LightPink; break; case "sleep": MachineStatus = MachStatus.Sleep; MachineStatusColor = Brushes.LightGray; break; default: MachineStatus = MachStatus.Undefined; MachineStatusColor = Brushes.DarkGray; break; } } else//Report state Grbl v0.9 <Idle,MPos:0.000,0.000,0.000,WPos:0.000,0.000,0.000,Buf:0,RX:0> { string[] arr = data.Split(new Char[] { '<', '>', ',', ':', '\r', '\n' }); if (arr.Length > 13) { RxBuffer = arr[13]; } if (arr.Length > 11) { PlannerBuffer = arr[11]; } if (arr.Length > 7) { WorkPositionX = arr[7]; WorkPositionY = arr[8]; } if (arr.Length > 3) { MachinePositionX = arr[3]; MachinePositionY = arr[4]; } switch (arr[1]) { case "idle": MachineStatus = MachStatus.Idle; MachineStatusColor = Brushes.Beige; break; case "run": MachineStatus = MachStatus.Run; MachineStatusColor = Brushes.LightGreen; break; case "hold": MachineStatus = MachStatus.Hold; MachineStatusColor = Brushes.LightBlue; break; case "alarm": MachineStatus = MachStatus.Alarm; MachineStatusColor = Brushes.Red; break; case "door": MachineStatus = MachStatus.Door; MachineStatusColor = Brushes.LightYellow; break; case "check": MachineStatus = MachStatus.Check; MachineStatusColor = Brushes.LightCyan; break; case "home": MachineStatus = MachStatus.Home; MachineStatusColor = Brushes.LightPink; break; default: MachineStatus = MachStatus.Undefined; MachineStatusColor = Brushes.DarkGray; break; } } } }