private void timerComHandler_Tick(object sender, EventArgs e) { // keep track of incoming bytes int result = 0; int totalBytes = 0; string response; int confirmationsReceived = 1; // string to be sent via Serial string textOut = ""; // state - PORT_RUNNING // type - permanent state // performs - continuosly read COM port data and request redrawing of newly incoming data if ((currentPortState == PortStates.PORT_WAITING_GRBL_HEADER) || (currentPortState == PortStates.PORT_RUNNING_IDLE) || (currentPortState == PortStates.PORT_RUNNING_TRANSMIT)) { byte[] localData = new byte[1024]; totalBytes = serialPort.BytesToRead; int readBytes = totalBytes; //if (serialPort.ReadBufferSize > 0) //{ response = serialPort.ReadExisting(); // filter out empty responses if (response != "") { ComHandler.ConsoleWrite(response); } // if "Grbl" substring has arrived, then we definitely are connected to a GRBL machine if (response.Contains("Grbl")) { currentPortState = PortStates.PORT_RUNNING_IDLE; } else { // process normal incoming data confirmationsReceived = ComHandler.ProcessIncomingData(response); } if (confirmationsReceived > 0) { currentTxState = TransmitStates.TX_IDLE; } //Console.Write(confirmationsReceived); //glControl1.Invalidate(); //} // hadle transmission of GCODE file if (currentPortState == PortStates.PORT_RUNNING_TRANSMIT) { if ((!GcodeHandler.GcodeFileDataFinished) && (currentTxState == TransmitStates.TX_IDLE)) { textOut = GcodeHandler.GetNextGcodeBlock(); ComHandler.ConsoleWrite(textOut + '\t'); serialPort.Write(textOut + "\r"); currentTxState = TransmitStates.TX_PENDING; toolStripProgressBar1.Value = GcodeHandler.GcodeFilePercent; } else if (GcodeHandler.GcodeFileDataFinished) { currentPortState = PortStates.PORT_RUNNING_IDLE; toolStripProgressBar1.Value = 100; } } } }