Пример #1
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            if (Tools.Count == 0)
            {
                Tools.Add(new Tool(GrblConstants.NO_TOOL));
            }

            if (!GrblParserState.Loaded)
            {
                GrblParserState.Get(model);
            }

            dispatcher    = Dispatcher.CurrentDispatcher;
            dataReceived += process;
            LatheMode     = GrblParserState.LatheMode;

            model.Silent = true;

            Comms.com.PurgeQueue();

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => dataReceived(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(GrblConstants.CMD_GETNGCPARAMETERS));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            model.Silent  = false;
            dataReceived -= process;

            if (Tools.Count == 1)
            {
                Tools.Add(new Tool("1"));
                Tools.Add(new Tool("2"));
                Tools.Add(new Tool("3"));
                Tools.Add(new Tool("4"));
            }

            GrblParserState.Tool = GrblParserState.Tool; // Add tool to Tools if not in list

            // Reeread parser state since work offset and tool lists are now populated
            Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE);

            return(res == true);
        }
Пример #2
0
        public bool ParseGCStatus(string data)
        {
            GrblParserState.Process(data);
            if (GrblParserState.IsLoaded)
            {
                ParserState = data.Substring(4).TrimEnd(']');
            }

            return(GrblParserState.IsLoaded);
        }
Пример #3
0
        public bool ParseGCStatus(string data)
        {
            GrblParserState.Process(data);
            if (GrblParserState.Loaded)
            {
                ParserState = data;
            }

            return(GrblParserState.Loaded);
        }
Пример #4
0
        public static bool Get()
#endif
        {
            if (Tools.Count == 0)
            {
                Tools.Add(new Tool("None"));
            }

            if (!GrblParserState.Loaded)
            {
                GrblParserState.Get();
            }

            LatheMode = GrblParserState.LatheMode;

            Comms.com.DataReceived += process;
#if USE_ASYNC
            var task = Task.Run(() => Comms.com.AwaitAck(GrblConstants.CMD_GETNGCPARAMETERS));
            await await Task.WhenAny(task, Task.Delay(2500));
#else
            Comms.com.PurgeQueue();
            Comms.com.WriteCommand(GrblConstants.CMD_GETNGCPARAMETERS);
            Comms.com.AwaitAck();
#endif
            Comms.com.DataReceived -= process;

            if (Tools.Count == 1)
            {
                Tools.Add(new Tool("1"));
                Tools.Add(new Tool("2"));
                Tools.Add(new Tool("3"));
                Tools.Add(new Tool("4"));
            }

            GrblParserState.Tool = GrblParserState.Tool; // Add tool to Tools if not in list

            return(Loaded);
        }
Пример #5
0
        public void Reset()
        {
            // Sync with controller
            if (GrblInfo.IsGrblHAL)
            {
                GrblParserState.Get();
                GrblWorkParameters.Get();
            }
            else
            {
                GrblParserState.Get(true);
            }

            coordinateSystems.Clear();
            foreach (CoordinateSystem c in GrblWorkParameters.CoordinateSystems)
            {
                coordinateSystems.Add(c);
            }

            toolTable.Clear();
            if (GrblInfo.NumTools > 0)
            {
                foreach (Tool t in GrblWorkParameters.Tools)
                {
                    toolTable.Add(t);
                }
            }

            coordinateSystem = coordinateSystems.Where(x => x.Code == GrblParserState.WorkOffset).FirstOrDefault();
            g28 = coordinateSystems.Where(x => x.Code == "G28").FirstOrDefault();
            g30 = coordinateSystems.Where(x => x.Code == "G30").FirstOrDefault();
            g92 = coordinateSystems.Where(x => x.Code == "G92").FirstOrDefault();

            isRelative       = GrblParserState.DistanceMode == DistanceMode.Incremental;
            IsImperial       = !GrblParserState.IsMetric;
            CoolantState     = GrblParserState.CoolantState;
            SpindleState     = GrblParserState.SpindleState;
            LatheMode        = GrblParserState.LatheMode;
            DistanceMode     = GrblParserState.DistanceMode;
            ToolLengthOffset = GrblParserState.ToolLengthOffset;
            FeedRateMode     = GrblParserState.FeedRateMode;
            MotionMode       = GrblParserState.MotionMode;
            IJKMode          = GrblParserState.IJKMode;
            IsScaled         = GrblParserState.IsActive("G51") != null;
            string val = GrblParserState.IsActive("F");

            Feedrate       = val == null ? 0d : double.Parse(val, CultureInfo.InvariantCulture);
            val            = GrblParserState.IsActive("S");
            _rpm           = val == null ? 0d : double.Parse(val, CultureInfo.InvariantCulture);
            _tool          = GrblParserState.Tool == GrblConstants.NO_TOOL ? 0 : int.Parse(GrblParserState.Tool);
            SelectedTool   = null;
            RetractOldZ    = GrblParserState.IsActive("G99") == null;
            SpindleRpmMode = GrblParserState.IsActive("G96") == null;
            G92Active      = GrblParserState.IsActive("G92") != null;

            Line = 0;

            foreach (int i in AxisFlags.All.ToIndices())
            {
                offsets[i]      = coordinateSystem == null ? 0d :  coordinateSystem.Values[i];
                origin[i]       = g92 == null ? 0d : g92.Values[i];
                machinePos[i]   = 0d;
                scaleFactors[i] = 1d;
                toolOffsets[i]  = SelectedTool == null ? 0d : SelectedTool.Values[i];
            }

            switch (GrblParserState.Plane)
            {
            case GCode.Plane.XY:
                Plane = new GCPlane(Commands.G17, 0);
                break;

            case GCode.Plane.XZ:
                Plane = new GCPlane(Commands.G18, 0);
                break;

            case GCode.Plane.YZ:
                Plane = new GCPlane(Commands.G19, 0);
                break;
            }
        }