protected void CommandSended(MotorCommand command) { var str = (command.line > 0 ? command.line.ToString() : "-") + " " + command.Command.ToString() + " "; var cc = command as MotorCommand; if (cc != null) { str += " " + cc.x; str += " " + cc.y; str += " " + cc.z; str += " " + cc.speed; } log(str); }
private void btnLeft_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove && CncController.Ready) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.x = 0 - step; command.y = 0; command.z = 0; command.speed = speedY; command.paramA = 64; CncController.SendCommand(command); } }
public static bool Spindle(bool enable) { var mc = new MotorCommand(CommandType.Spindle1); mc.speed = enable ? (ushort)1 : (ushort)0; SpindleState = enable; return SendCommand(mc); }
public static MotorCommand Go(int x, int y, int z) { var command = new MotorCommand(CommandType.Go); command.x = x; command.y = y; command.z = z; return command; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS"); context.Response.AddHeader("Access-Control-Request-Header", "X-Prototype-Version, x-requested-with"); context.Response.AddHeader("Access-Control-Allow-Origin", "*"); //context.Response.Headers.Remove("content-length"); context.Response.Flush(); CncController.OnMessage += Uart_OnMessage; CncProgram.OnCommand += Uart_OnCommand; CncProgram.OnStateChange += new ProgramStateHandler(Program_OnStateChange); CncController.GetStateAsync(); if (CncController.LastCommand != null) OutCommand = CncController.LastCommand; ProgramState = CncProgram.State; var timeout = 10000; while (timeout > 0 && context.Response.IsClientConnected) { Thread.Sleep(100); timeout--; List<string> states = new List<string>(); if (OutCommand != null) { states.Add(OutCommand.ToString()); OutCommand = null; } if (ProgramState != null) { states.Add("{\"state\":\"" + ProgramState.Value.ToString() + "\", \"line\":" + CncProgram.CurrentLine + ",\"type\" : \"program-state\"}"); ProgramState = null; } if (StateMessage != null) { states.Add(StateMessage.ToString()); StateMessage = null; } if (states.Count > 0) { context.Response.Write("[" + String.Join(",", states.ToArray()) + "]"); context.Response.Flush(); } } /* while (Uart.LastState == null) { var dt = DateTime.Now; Uart.SendStateCommand(); var timeout = 2000; while ((Uart.LastState == null || Uart.LastState.date < dt) && timeout > 0) { Thread.Sleep(200); timeout -= 200; } if (Uart.LastState != null && timeout > 0) { context.Response.Write(Uart.LastState.ToString()); } else { context.Response.StatusCode = 504; context.Response.Write(" "); } return; } if (context.Request.HttpMethod == "GET") { var ld = DateTime.Now; if (context.Request["lastdate"] != null) { ld = DateTime.Parse(context.Request["lastdate"]); if (ld >= Uart.LastState.date && context.Request["wait"] == null) { return; } } if (context.Request["wait"] != null) { if (context.Request["ping"] != null) { Uart.SendStateCommand(); } var timeout = 2000; while ((Uart.LastState == null || Uart.LastState.date < ld) && timeout > 0) { Thread.Sleep(200); timeout -= 200; } if (Uart.LastState != null && timeout > 0) { context.Response.Write(Uart.LastState.ToString()); } else { context.Response.StatusCode = 504; } return; } context.Response.Write(Uart.LastState.ToString()); } if (context.Request.HttpMethod == "POST") { }*/ }
private void Uart_OnCommand(MotorCommand command) { OutCommand = command; }
private void button7_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.X = 0 - step; command.Y = 0 + step; command.Z = 0; command.Speed = (ushort)((speedX + speedY) / 2); CncController.SendCommand(command); } }
private void resetXbtn_Click(object sender, EventArgs e) { if (CncController.LastState != null && CncController.Ready && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Rebase); command.X = 0; command.Y = CncController.LastState.y; command.Z = CncController.LastState.z; command.Speed = 7000; CncController.SendCommand(command); } }
private void btnBottom_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.X = 0; command.Y = 0; command.Z = 0 + step; command.Speed = speedZ; command.paramB = 8; CncController.SendCommand(command); } }
private void btnRightEnd_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.X = 99999999; command.Y = 0; command.Z = 0; command.Speed = speedY; command.paramA = 32; command.paramB = chkWaitHardwareStop.Checked ? (byte)16 : (byte)0; CncController.SendCommand(command); } }
private void button7_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.X = 0 - step; command.Y = 0 + step; command.Z = 0; command.Speed = (ushort)((speedX + speedY) / 2); command.paramA = 64 + 8; command.paramB = chkWaitHardwareStop.Checked ? (byte)16 : (byte)0; CncController.SendCommand(command); } }
private void btnTop_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.X = 0; command.Y = 0; command.Z = 0 - step; command.Speed = speedZ; command.paramB = (byte)(8 | (chkWaitHardwareStop.Checked ? 16 : 0)); CncController.SendCommand(command); } }
private void btnDown_Click(object sender, EventArgs e) { if (CncController.LastState != null && !CncController.InMove && CncController.Ready) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Move); command.x = 0; command.y = 0 - step; command.z = 0; command.speed = speedX; command.paramA = 16; command.paramB = chkWaitHardwareStop.Checked ? (byte)16 : (byte)0; CncController.SendCommand(command); } }
public static bool SendCommand(MotorCommand command) { if (command == null || command.Command <= CommandType.Null) { return false; } LastCommand = command; Uart.Send(command.Serialize(CncAddress)); command.Sended = true; if (OnCommand != null) { OnCommand(command); } return true; }
private void button11_Click(object sender, EventArgs e) { var command = new MotorCommand(MRS.Hardware.Server.CommandType.Go); command.X = 0; command.Y = 0; command.Z = 0; command.Speed = 7000; CncController.SendCommand(command); }
private void NextCommand(MotorState ms) { CurrentLine++; if (CurrentLine < Commands.Length) { CncController.SendCommand(CurrentCommand); LastSended = CurrentCommand; } else { Stop(); } }
void UART_OnCommand(MotorCommand command) { try { Invoke(new Action<MotorCommand>(CommandSended), command); } catch (Exception e) { } }