Exemple #1
0
        private async Task InterpretProgram(GCodePreparer preparer, IProgress <float> progress)
        {
            CoordintatesExpression coordintatesExpression = new CoordintatesExpression();
            GCodeExpression        gCodeExpression        = new GCodeExpression();
            MCodeExpression        mCodeExpression        = new MCodeExpression();
            TCodeExpression        tCodeExpression        = new TCodeExpression();
            FeedrateExpression     feedrateExpression     = new FeedrateExpression();

            await Task.Run(() =>
            {
                float progressValue = 0;
                int lineNumber      = 0;
                foreach (var preparedString in preparer.Strings)
                {
                    Context context = new Context
                    {
                        PreviousFrame = Program.LastOrDefault(),
                        InputString   = preparedString
                    };
                    gCodeExpression.Interpret(context);
                    mCodeExpression.Interpret(context);
                    tCodeExpression.Interpret(context);
                    coordintatesExpression.Interpret(context);
                    feedrateExpression.Interpret(context);
                    Program.Add(context.OutputData);
                    var currentValue = (float)((double)lineNumber / preparer.Strings.Count * 90 + 10);
                    if ((currentValue - progressValue) > 0.1)
                    {
                        progressValue = currentValue;
                        progress.Report(progressValue);
                    }
                    lineNumber++;
                }
            }).ConfigureAwait(false);
        }
Exemple #2
0
        public void OpenFileAsyncNotExistingFile()
        {
            var notexistNc = @".\notexist.nc";
            var preparer   = new GCodePreparer();

            Assert.ThrowsAsync <FileNotFoundException>(async() => await preparer.OpenFileAsync(notexistNc, new Progress <float>()));
        }
Exemple #3
0
        public void OpenFileAsyncTestValidFile()
        {
            var validFilePath = @".\TestFiles\valid.nc";
            var preparer      = new GCodePreparer();

            Assert.DoesNotThrowAsync(async() => await preparer.OpenFileAsync(validFilePath, new Progress <float>()));
        }
Exemple #4
0
        public void FindTestStringWithComments(string value)
        {
            const string valid = "G3 X0.046 Y0.756 I0.3098 J0.0954";

            var output = GCodePreparer.Find(value).Trim();

            Assert.IsTrue(output.Equals(valid, StringComparison.OrdinalIgnoreCase));
        }
Exemple #5
0
        public async Task PrepareStringsAsyncTest()
        {
            var validFilePath = @".\TestFiles\valid.nc";
            var preparer      = new GCodePreparer();
            await preparer.OpenFileAsync(validFilePath, new Progress <float>());

            try
            {
                await preparer.PrepareStringsAsync();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            Assert.Pass();
        }
Exemple #6
0
        public virtual async Task LoadProgramAsync(string path, IProgress <float> progressChanger)
        {
            progressChanger.Report(0);
            Program.Clear();
            progressChanger.Report(1);
            GCodePreparer preparer = new GCodePreparer();
            await preparer.OpenFileAsync(path, progressChanger);

            progressChanger.Report(5);
            await preparer.PrepareStringsAsync();

            progressChanger.Report(10);

            await InterpretProgram(preparer, progressChanger);

            if (Program.Count == 0)
            {
                return;
            }
            FrameNumber  = 0;
            CurrentFrame = Program[FrameNumber];
            InitFrame();
            progressChanger.Report(100);
        }
Exemple #7
0
        public void FindTestNullArgument()
        {
            var output = GCodePreparer.Find(null).Trim();

            Assert.IsTrue(string.IsNullOrEmpty(output));
        }
Exemple #8
0
        public void FindTestInvalidString(string value)
        {
            var output = GCodePreparer.Find(value).Trim();

            Assert.IsFalse(output.Equals(value, StringComparison.OrdinalIgnoreCase));
        }