public void sendGCode(string text) { Console.Out.WriteLine(text); CustomSerial movementSerial = ComChannelFactory.getGCodeSerial(); movementSerial.configure("COM3", "115200", "8", "One", "None"); movementSerial.Open(); //movementSerial.WriteLine(text); movementSerial.Write("M105\n"); //movementSerial.WriteLine("T1\n"); System.Threading.Thread.Sleep(1000); movementSerial.Write("G91\n"); movementSerial.Write("G1 X-300 F6000\n"); System.Threading.Thread.Sleep(1000); movementSerial.ReadExisting(); //movementSerial.ReadLine(); movementSerial.Close(); }
public void write(string dataToSend) { //while (InterOperationFlag.isCanBusy != false) //{ // System.Threading.Thread.Sleep(100); //} //InterOperationFlag.isSerialBusy = true; serial.isBusy = true; Logger.Instance.writeToLog(">>>>>>>>>>>>>>>>>>>>>", true, true); Logger.Instance.writeToLog("SERIAL - Sending at : " + System.DateTime.Now, true, true); Logger.Instance.writeToLog(dataToSend, true, true); Logger.Instance.writeToLog(">>>>>>>>>>>>>>>>>>>>>", true, true); serial.Open(); serial.DiscardInBuffer(); serial.DiscardOutBuffer(); serial.Write(dataToSend + '\n'); String receivedData; bool stayInThere = true; receivedData = serial.ReadLine(); while (stayInThere == true) { Logger.Instance.writeToLog("<<<<<<<<<<<<<<<<<<<<<", true, true); Logger.Instance.writeToLog("SERIAL - Receiving at : " + System.DateTime.Now, true, true); Logger.Instance.writeToLog(receivedData, false, true); Logger.Instance.writeToLog("<<<<<<<<<<<<<<<<<<<<<", true, true); if (receivedData.Contains(dataToSend)) { serial.DiscardInBuffer(); serial.DiscardOutBuffer(); System.Threading.Thread.Sleep(200); //System.Windows.Forms.MessageBox.Show(test); stayInThere = false; wait.Set(); serial.isBusy = false; } else { receivedData = serial.ReadLine(); System.Threading.Thread.Sleep(200); } } //InterOperationFlag.isSerialBusy = false; serial.Close(); }