예제 #1
0
        /// <summary>
        /// Reads and send the GCode from a file.This should be run inside a thread.
        /// </summary>
        /// <param name="path"></param>
        private void GCodeReadAndSender(string path)
        {
            //To estimate how much printing time is left we substract the printing time of the lines that have been pinted from the
            //total printing time for the file.

            GCodeProgressEstimator progEst = new GCodeProgressEstimator();

            /*double totalTimeForFile = GCodeProgressEstimator.estimateTotalTimeForFile(path,
             *  new Vector3(ApplicationSettings.currentPos_X, ApplicationSettings.currentPos_Y, ApplicationSettings.currentPos_Z));*/
            double totalTimeForFile = progEst.estimateTotalTimeForFile(path);

            double printedTime = 0;//This value represents the amount of time that we have printed

            //This value stores the position of the printed after the previous line has completed and is used to calculate the time needed to complete
            //the current line. We should probably rather use the current printhead position in some way but that will not work directly because the line
            //that is currently being sent is sometimes a few lines ahead of the line that was previously completed
            Vector3 prevPos = new Vector3(Values.currentPos_X, Values.currentPos_Y, Values.currentPos_Z);

            var isf = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(path, FileMode.OpenOrCreate, isf);

            StreamReader streamReader = new StreamReader(isoStream);//path);

            bool problemSending = false;

            /*float prevE = 0;
             * float prevF0 = 0;
             * float prevF1 = 0;*/

            int linecount = 0;

            //Reset the progress estimator
            progEst = new GCodeProgressEstimator();

            while (!streamReader.EndOfStream && !problemSending && !stopGCode)//Wait for the file to be completely read or for an error to happen
            {
                linecount++;

                string line = streamReader.ReadLine();

                //remove comments
                if (line.Contains(";"))
                {
                    line = line.Split(';')[0];
                }

                //ignore empty lines
                if (line.Length < 2)
                {
                    continue;
                }

                //send the GCode line (it gets proccessed first though)
                problemSending = !GCodeSender.trySendingGCode(line);

                GCode.GCode GCodeLine = new GCode.GCode(line);

                /*double addTime = 0;
                 *
                 * if (GCodeLine.hasG)
                 * {
                 *  addTime = progEst.calculateTimeForLine(GCodeLine);
                 * }
                 *
                 * if (addTime > 0.0)
                 *  printedTime += addTime;*/
                double addTime = progEst.calculateTimeForLine(GCodeLine);
                printedTime += addTime;

                Values.progress_SecondsLeft    = (int)(totalTimeForFile - printedTime);
                Values.progress_PercentageDone = (int)(printedTime / totalTimeForFile * 100);
            }

            Debug.WriteLine("finsihed");

            Values.progress_SecondsLeft    = totalTimeForFile;
            Values.progress_PercentageDone = 0;

            if (FileReadingStopped != null)
            {
                FileReadingStopped();//Alert any listeners that we have stopped reading a file
            }
            GCodeGenerator.coolExtruder();
            GCodeGenerator.homeAll();

            stopGCode = false;

            isoStream.Dispose();
            streamReader.Dispose();
        }
예제 #2
0
 /// <summary>
 /// This unction tries to send the specified command
 /// to the printer.
 /// </summary>
 /// <param name="command"></param>
 public void trySendingCommand(string command)
 {
     GCodeSender.trySendingGCode(command);
 }