Beispiel #1
0
        private void generateMachineCodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Code = PromptBox.ShowDialog("Enter GCode", "Enter GCode to convert to machine code");

            switch (GCode.GetCode(Code))
            {
            case "G00":
                G00 g0 = new G00(Code);
                break;

            case "G01":
                G01 g1 = new G01(Code);
                MessageBox.Show(g1.MachineCodeFromLocation(0, 0, 0));
                break;

            default:
                throw new NotSupportedException("OpCode " + GCode.GetCode(Code) + " not supported");
            }
        }
Beispiel #2
0
        void MillTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                switch (GCode.GetCode(gCode[GlobalCounter]))
                {
                case "G00":    //Rapid Move
                    Log("Rapid Move");
                    G00 g = new G00(gCode[GlobalCounter++]);
                    MillString = g.MachineCodeFromLocation(Drill_X, Drill_Y, Drill_Z);
                    CutString(MillString);
                    break;

                case "G01":    //Liner Interpolation INCOMPLETE

                    G01 g1 = new G01(gCode[GlobalCounter++]);
                    MillString = g1.MachineCodeFromLocation(Drill_X, Drill_Y, Drill_Z);
                    CutString(MillString);
                    break;

                case "G04":     //Dwell - implement a wait. NOT CORRECTLY WORKING DISABLED FOR NOW
                    //G04 g4 = new G04(gCode[GlobalCounter++]);
                    //Log("Wait for " + g4.Wait.ToString() + " milliseconds");
                    //System.Threading.Thread.Sleep(g4.Wait);
                    GlobalCounter++;
                    break;

                case "G21":     //Programming in Millimeters
                    Log("Programming In Millimeters");
                    GlobalCounter++;
                    break;

                case "G90":     //Absoulte Programming
                    Log("Absolute Programming");
                    GlobalCounter++;
                    break;

                case "M03":     //Spindle On, Clockwise
                    //UserRequest.ShowDialog("Please turn the spindle on.");
                    //Need to implement a wait for okay button pressed style effect
                    GlobalCounter++;
                    break;

                case "M05":     //Spindle Off
                    //UserRequest.ShowDialog("Please turn the spindle off.");
                    GlobalCounter++;
                    break;

                default:
                    Log("OpCode " + GCode.GetCode(gCode[GlobalCounter]) + " not supported");
                    throw new NotSupportedException("OpCode " + GCode.GetCode(gCode[GlobalCounter]) + " not supported");
                }
            }
            catch (Exception ex)
            {
                MillTimer.Dispose();
                Log(ex.Message);
            }


            if ((GlobalCounter == GlobalMaximum) && StringMillComplete)//if we're on the last command and we've cut it out, finish
            {
                MessageBox.Show("Milling Complete");
                MillTimer.Stop();
                MillTimer.Enabled = false;
                MillTimer.Dispose();
            }
        }
Beispiel #3
0
        public G01(string command)
        {
            if (!(GCode.GetCode(command) == "G01"))
            {
                throw new Exception("Incorrect Command");
            }
            else
            {
                Code    = GCode.GetCode(command);
                Command = command;
            }
            MoveX = false;//all moves are false unless found otherwise
            MoveY = false;
            MoveZ = false;


            //split into components and store as necessary

            string temp = "";
            bool   Go   = true;
            int    i    = 0;

            while (Go)
            {
                switch (Command[i])
                {
                case 'X':
                    MoveX = true; //found a X Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    X    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                case 'Y':
                    MoveY = true; //found a Y Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    Y    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                case 'Z':
                    MoveZ = true; //found a Z Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    Z    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                case 'F':
                    Feed = true;  //found a Z Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    F    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                default:
                    i++;
                    break;
                }
                if (i == Command.Length)
                {
                    Go = false;
                }
            }
        }
Beispiel #4
0
        //Constructor deciphers code into coordinates to move to
        public G00(string command)
        {
            MoveX = false;//all moves are false unless found otherwise
            MoveY = false;
            MoveZ = false;


            //split into components and store as necessary
            Command = command;
            Code    = GCode.GetCode(Command);
            if (Code != "G00")
            {
                throw new Exception("Not Correct GCode");
            }
            string temp = "";
            bool   Go   = true;
            int    i    = 0;

            while (Go)
            {
                switch (Command[i])
                {
                case 'X':
                    MoveX = true; //found an X Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    X    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                case 'Y':
                    MoveY = true; //found an X Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    Y    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                case 'Z':
                    MoveZ = true; //found an X Coord
                    i++;
                    while (Go)    //
                    {
                        temp += Command[i];
                        i++;
                        if (i == Command.Length)
                        {
                            Go = false;
                        }
                        else if (Command[i] == ' ')
                        {
                            Go = false;
                        }
                    }
                    Go   = true;
                    Z    = Convert.ToDouble(temp);
                    temp = "";
                    break;

                default:
                    i++;
                    break;
                }
                if (i == Command.Length)
                {
                    Go = false;
                }
            }
        }