예제 #1
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult result = openFileDialog_GCode.ShowDialog();//show open dialog
         if (result == DialogResult.OK)
         {
             string FilePath = openFileDialog_GCode.FileName;
             //sr = new StreamReader(FilePath);
             //MessageBox.Show(sr.ReadLine());
             gc = new GCode(FilePath);
             //List<string> Codes = gc.GetCodesInUse();
             //comboBox1.DataSource = Codes;
             richTextBox_Commands.Text = gc.ToString();
         }
         else
         {
             throw new Exception("Error Loading File");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
예제 #2
0
 private void getCodeInfoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         MessageBox.Show(GCode.GetInfo(PromptBox.ShowDialog("Enter Command", "Enter Command Name")));
         //MessageBox.Show(GCode.GetInfo("A"));
     }
     catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); }
 }
예제 #3
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");
            }
        }
예제 #4
0
        public void MillCode(GCode _gcode)
        {
            if (!Calibrated)
            {
                MessageBox.Show("Please Use the Controls to move the Spindle to the Start Location.\n\nPress 'Calibrated' Button when done and retry Milling");
            }
            else
            {
                Log("Milling Started");
                GlobalMaximum = _gcode.Commands.Count;
                //CurrentCode = _gcode[0];
                this.gCode = _gcode;
                Drill_X    = 0;
                Drill_Y    = 0;
                Drill_Z    = 0;

                GlobalCounter      = 0;
                StringMillComplete = true; //force the timer to find a string first
                MillTimer.Start();         //Mill timer does the main work to stop from getting trapped in an infinite loop
            }
        }
예제 #5
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     gc = new GCode();
     richTextBox_Commands.Text = "";
 }
예제 #6
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;
                }
            }
        }
예제 #7
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();
            }
        }
예제 #8
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;
                }
            }
        }