Exemple #1
0
        private void timerBkgrTasks_Tick(object sender, EventArgs e)
        {
            // enumerate for new ports and update the list
            if (!SerialPort.GetPortNames().SequenceEqual(portNames))
            {
                portNames = SerialPort.GetPortNames();
                comboBox1.Items.Clear();
                comboBox1.Items.AddRange(portNames);

                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.SelectedIndex = 0;
                }
            }


            // state    -   PORT_OPENING
            // type     -   transitory to PORT_WAITING_GRBL_HEADER
            // performs -   opening COM connection and start of acquisition timer
            // error    -   return to PORT_CLOSED state
            if (currentPortState == PortStates.PORT_OPENING)
            {
                try
                {
                    serialPort.PortName = comboBox1.Text;
                    serialPort.Open();
                    serialPort.DiscardInBuffer();
                    timerComHandler.Enabled = true;
                    currentPortState        = PortStates.PORT_WAITING_GRBL_HEADER;


                    btnConnect.Text   = "Disconnect";
                    comboBox1.Enabled = false;
                    textInput.Enabled = true;
                }
                catch
                {
                    currentPortState = PortStates.PORT_CLOSING;
                }
            }


            // state    -   PORT_WAITING_GRBL_HEADER
            // type     -   transitory to PORT_RUNNING
            // performs -   opening COM connection and start of acquisition timer
            // error    -   return to PORT_CLOSED state
            if (currentPortState == PortStates.PORT_WAITING_GRBL_HEADER)
            {
                //currentPortState = PortStates.PORT_RUNNING_IDLE;
            }



            // state    -   PORT_RUNNING_IDLE
            // type     -   permanent state
            // performs -   updates different states in the system
            // error    -   none
            if (currentPortState == PortStates.PORT_RUNNING_IDLE)
            {
                if (GcodeHandler.GcodeLoaded)
                {
                    btnStart.Enabled = true;
                    btnStop.Enabled  = true;
                }
            }

            // state    -   PORT_RUNNING_TRANSMIT
            // type     -   permanent state
            // performs -   updates different states in the system
            // error    -   none
            // hadled   -   handled in timerComHandler, not here


            // state    -   PORT_CLOSING
            // type     -   transitory state to PORT_CLOSED
            // performs -   closes the port and stops the acquisition timer
            if (currentPortState == PortStates.PORT_CLOSING)
            {
                serialPort.DiscardInBuffer();
                try
                {
                    serialPort.Close();
                }
                catch
                {
                    // do nothing, port goes into state PORT_CLOSED anyway
                    //Console.WriteLine("Error at closing port");
                }

                currentPortState = PortStates.PORT_CLOSED;
                btnConnect.Text  = "Connect";

                textInput.Enabled = false;
                comboBox1.Enabled = true;

                // disable GCODE file processor buttons
                btnStart.Enabled = false;
                btnStop.Enabled  = false;
            }

            // update graphics interface
            GraphicsHandler.SetDrawingColor1();
            GcodeHandler.RedrawFullPicture();

            toolStripStatusLabel1.Text = currentPortState.ToString();

            glControl1.Invalidate();
        }
Exemple #2
0
 private void glControl1_ContextCreated(object sender, OpenGL.GlControlEventArgs e)
 {
     GraphicsHandler.GraphicContextCreated();
 }