Exemple #1
0
 public T this[int i]
 {
     get { return(arr[i]); }
     set
     {
         if (!value.Equals(arr[i]))
         {
             arr[i] = value;
             if (!_suspend)
             {
                 OnPropertyChanged(GrblInfo.AxisIndexToLetter(i));
             }
         }
     }
 }
Exemple #2
0
 public void ParseHomedStatus(string data)
 {
     string[] values = data.TrimEnd(']').Split(':');
     if (values.Length == 3)
     {
         HomePosition.Parse(values[1]);
         AxisHomed.Value = (AxisFlags)int.Parse(values[2]);
         for (int i = 0; i < GrblInfo.NumAxes; i++)
         {
             if (!AxisHomed.Value.HasFlag(GrblInfo.AxisIndexToFlag(i)))
             {
                 HomePosition.Values[i] = double.NaN;
             }
         }
     }
 }
 public T this[int i]
 {
     get { return(arr[i]); }
     set
     {
         //double v = (double)(object)arr[i];
         //if (dbl.Assign((double)(object)value, ref v))
         {
             arr[i] = value;
             if (!_suspend)
             {
                 OnPropertyChanged(GrblInfo.AxisIndexToLetter(i));
             }
         }
     }
 }
Exemple #4
0
        private bool Set(string parameter, string value)
        {
            bool pos_changed = false;

            switch (parameter)
            {
            case "MPos":
                if ((pos_changed = _MPos != value))
                {
                    if (!_isMPos)
                    {
                        IsMachinePosition = true;
                    }
                    _MPos = value;
                    MachinePosition.Parse(_MPos);
                }
                break;

            case "WPos":
                if ((pos_changed = _WPos != value))
                {
                    if (_isMPos)
                    {
                        IsMachinePosition = false;
                    }
                    _WPos = value;
                    WorkPosition.Parse(_WPos);
                }
                break;

            case "WCO":
                if ((pos_changed = _wco != value))
                {
                    _wco    = value;
                    has_wco = true;
                    WorkPositionOffset.Parse(value);
                }
                break;

            case "A":
                if (_a != value)
                {
                    _a = value;

                    if (_a == "")
                    {
                        Mist = Flood = IsToolChanging = false;
                        SpindleState.Value = GCode.SpindleState.Off;
                    }
                    else
                    {
                        Mist               = value.Contains("M");
                        Flood              = value.Contains("F");
                        IsToolChanging     = value.Contains("T");
                        SpindleState.Value = value.Contains("S") ? GCode.SpindleState.CW : (value.Contains("C") ? GCode.SpindleState.CCW : GCode.SpindleState.Off);
                    }
                }
                break;

            case "WCS":
                if (_wcs != value)
                {
                    WorkCoordinateSystem = GrblParserState.WorkOffset = value;
                }
                break;

            case "Bf":
                string[] buffers = value.Split(',');
                if (buffers[0] != _pb_avail)
                {
                    _pb_avail = buffers[0];
                    OnPropertyChanged(nameof(PlanBufferAvailable));
                }
                if (buffers[1] != _rxb_avail)
                {
                    _rxb_avail = buffers[1];
                    OnPropertyChanged(nameof(RxBufferAvailable));
                }
                break;

            case "Ln":
                LineNumber = int.Parse(value);
                break;

            case "FS":
                if (_fs != value)
                {
                    _fs = value;
                    if (_fs == "")
                    {
                        FeedRate = ProgrammedRPM = 0d;
                        if (!double.IsNaN(ActualRPM))
                        {
                            ActualRPM = 0d;
                        }
                    }
                    else
                    {
                        double[] values = dbl.ParseList(_fs);
                        if (_feedrate != values[0])
                        {
                            FeedRate = values[0];
                        }
                        if (_rpm != values[1])
                        {
                            ProgrammedRPM = values[1];
                        }
                        if (values.Length > 2 && _rpmActual != values[2])
                        {
                            ActualRPM = values[2];
                        }
                    }
                }
                break;

            case "F":
                if (_fs != value)
                {
                    _fs = value;
                    if (_fs == "")
                    {
                        FeedRate = ProgrammedRPM = 0d;
                        if (!double.IsNaN(ActualRPM))
                        {
                            ActualRPM = 0d;
                        }
                    }
                    else
                    {
                        FeedRate = dbl.Parse(_fs);
                    }
                }
                break;

            case "PWM":
                PWM = int.Parse(value);
                break;

            case "Pn":
                if (_pn != value)
                {
                    _pn = value;

                    int s = 0;
                    foreach (char c in _pn)
                    {
                        int i = GrblConstants.SIGNALS.IndexOf(c);
                        if (i >= 0)
                        {
                            s |= (1 << i);
                        }
                    }
                    Signals.Value = (Signals)s;
                }
                break;

            case "Ov":
                if (_ov != value)
                {
                    _ov = value;
                    if (_ov == string.Empty)
                    {
                        FeedOverride = RapidsOverride = RPMOverride = 100d;
                    }
                    else
                    {
                        double[] values = dbl.ParseList(_ov);
                        if (_feedOverride != values[0])
                        {
                            FeedOverride = values[0];
                        }
                        if (_rapidsOverride != values[1])
                        {
                            RapidsOverride = values[1];
                        }
                        if (_rpmOverride != values[2])
                        {
                            RPMOverride = values[2];
                        }
                    }
                }
                break;

            case "Sc":
                if (_sc != value)
                {
                    int s = 0;
                    foreach (char c in value)
                    {
                        int i = GrblInfo.AxisLetterToIndex(c);
                        if (i >= 0)
                        {
                            s |= (1 << i);
                        }
                    }
                    AxisScaled.Value = (AxisFlags)s;
                    Scaling          = value;
                }
                break;

            case "Ex":
                if (_ex != value)
                {
                    TubeCoolant = value == "C";
                }
                break;

            case "SD":
                value = string.Format("SD Card streaming {0}% complete", value.Split(',')[0]);
                if (SDCardStatus != value)
                {
                    Message = SDCardStatus = value;
                }
                break;

            case "T":
                if (_tool != value)
                {
                    Tool = value == "0" ? GrblConstants.NO_TOOL : value;
                }
                break;

            case "TLR":
                IsTloReferenceSet = value != "0";
                break;

            case "MPG":
                GrblInfo.MPGMode = _grblState.MPG = value == "1";
                IsMPGActive      = _grblState.MPG;
                break;

            case "H":
                if (_h != value)
                {
                    _h = value;
                    var hs = _h.Split(',');
                    HomedState = hs[0] == "1" ? HomedState.Homed : (GrblState.State == GrblStates.Alarm && GrblState.Substate == 11 ? HomedState.NotHomed : HomedState.Unknown);
                }
                break;

            case "D":
                _d        = value;
                LatheMode = GrblParserState.LatheMode = value == "0" ? LatheMode.Radius : LatheMode.Diameter;
                break;

            case "THC":
            {
                var values = value.Split(',');

                if (_thcv != values[0])
                {
                    _thcv      = values[0];
                    THCVoltage = dbl.Parse(_thcv);
                }

                value = values.Length > 1 ? values[1] : "";

                if (_thcs != value)
                {
                    _thcs = value;

                    int s = 0;
                    foreach (char c in _thcs)
                    {
                        int i = GrblConstants.THCSIGNALS.IndexOf(c);
                        if (i >= 0)
                        {
                            s |= (1 << i);
                        }
                    }
                    THCSignals.Value = (THCSignals)s;
                }
            }
            break;

            case "Enc":
            {
                var enc = value.Split(',');
                OverrideEncoderMode = (GrblEncoderMode)int.Parse(enc[0]);
            }
            break;
            }

            return(pos_changed);
        }
Exemple #5
0
        public bool ProcessKeypress(KeyEventArgs e, bool allowJog, UserControl context = null)
        {
            bool isJogging = IsJogging, jogkeyPressed = false;

            double[] dist = new double[4] {
                0d, 0d, 0d, 0d
            };

            if (e.IsUp && isJogging)
            {
                bool cancel = !allowJog;

                isJogging = false;

                for (int i = 0; i < N_AXIS; i++)
                {
                    if (axisjog[i] == e.Key)
                    {
                        axisjog[i] = Key.None;
                        cancel     = true;
                    }
                    else
                    {
                        isJogging = isJogging || (axisjog[i] != Key.None);
                    }
                }

                isJogging &= allowJog;

                if (cancel && !isJogging && jogMode != JogMode.Step)
                {
                    JogCancel();
                }
            }

            if (!isJogging && allowJog && Comms.com.OutCount != 0)
            {
                return(true);
            }

            this.allowJog = allowJog;

            if (IsJoggingEnabled && e.IsDown && CanJog)
            {
                // Do not respond to autorepeats!
                if (e.IsRepeat)
                {
                    return(true);
                }

                N_AXIS = GrblInfo.AxisFlags.HasFlag(AxisFlags.A) ? 4 : 3;

                switch (e.Key)
                {
                case Key.PageUp:
                    isJogging = axisjog[GrblConstants.Z_AXIS] != Key.PageUp;
                    axisjog[GrblConstants.Z_AXIS] = Key.PageUp;
                    break;

                case Key.PageDown:
                    isJogging = axisjog[GrblConstants.Z_AXIS] != Key.PageDown;
                    axisjog[GrblConstants.Z_AXIS] = Key.PageDown;
                    break;

                case Key.Left:
                    isJogging = axisjog[GrblConstants.X_AXIS] != Key.Left;
                    axisjog[GrblConstants.X_AXIS] = Key.Left;
                    break;

                case Key.Up:
                    isJogging = axisjog[GrblConstants.Y_AXIS] != Key.Up;
                    axisjog[GrblConstants.Y_AXIS] = Key.Up;
                    break;

                case Key.Right:
                    isJogging = axisjog[GrblConstants.X_AXIS] != Key.Right;
                    axisjog[GrblConstants.X_AXIS] = Key.Right;
                    break;

                case Key.Down:
                    isJogging = axisjog[GrblConstants.Y_AXIS] != Key.Down;
                    axisjog[GrblConstants.Y_AXIS] = Key.Down;
                    break;

                case Key.Home:
                    if (N_AXIS == 4)
                    {
                        isJogging = axisjog[GrblConstants.A_AXIS] != Key.Home;
                        axisjog[GrblConstants.A_AXIS] = Key.Home;
                    }
                    break;

                case Key.End:
                    if (N_AXIS == 4)
                    {
                        isJogging = axisjog[GrblConstants.A_AXIS] != Key.End;
                        axisjog[GrblConstants.A_AXIS] = Key.End;
                    }
                    break;
                }
            }
            else
            {
                jogkeyPressed = !(Keyboard.FocusedElement is System.Windows.Controls.TextBox) && (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.PageUp || e.Key == Key.PageDown);
            }

            if (isJogging)
            {
                string command = string.Empty;

                if (GrblInfo.LatheModeEnabled)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        switch (axisjog[i])
                        {
                        case Key.Left:
                            dist[GrblConstants.Z_AXIS] = -1d;
                            command += "Z-{3}";
                            break;

                        case Key.Up:
                            dist[GrblConstants.X_AXIS] = -1d;
                            command += "X-{1}";
                            break;

                        case Key.Right:
                            dist[GrblConstants.Z_AXIS] = 1d;
                            command += "Z{3}";
                            break;

                        case Key.Down:
                            dist[GrblConstants.X_AXIS] = 1d;
                            command += "X{1}";
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < N_AXIS; i++)
                    {
                        switch (axisjog[i])
                        {
                        case Key.PageUp:
                            dist[GrblConstants.Z_AXIS] = 1d;
                            command += "Z{3}";
                            break;

                        case Key.PageDown:
                            dist[GrblConstants.Z_AXIS] = -1d;
                            command += "Z-{3}";
                            break;

                        case Key.Left:
                            dist[GrblConstants.X_AXIS] = -1d;
                            command += "X-{1}";
                            break;

                        case Key.Up:
                            dist[GrblConstants.Y_AXIS] = 1d;
                            command += "Y{2}";
                            break;

                        case Key.Right:
                            dist[GrblConstants.X_AXIS] = 1d;
                            command += "X{1}";
                            break;

                        case Key.Down:
                            dist[GrblConstants.Y_AXIS] = -1d;
                            command += "Y-{2}";
                            break;

                        case Key.Home:
                            dist[GrblConstants.A_AXIS] = 1d;
                            command += "A{4}";
                            break;

                        case Key.End:
                            dist[GrblConstants.A_AXIS] = -1d;
                            command += "A-{4}";
                            break;
                        }
                    }
                }

                if ((isJogging = command != string.Empty))
                {
                    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        for (int i = 0; i < N_AXIS; i++)
                        {
                            axisjog[i] = Key.None;
                        }
                        preCancel = !(jogMode == JogMode.Step || jogMode == JogMode.None);
                        jogMode   = JogMode.Step;
                        JogDistances[(int)jogMode] = grbl.JogStep;
                    }
                    else if (IsContinuousJoggingEnabled)
                    {
                        preCancel = true;
                        if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                        {
                            jogMode = JogMode.Fast;
                        }
                        else
                        {
                            jogMode = JogMode.Slow;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < N_AXIS; i++)
                        {
                            axisjog[i] = Key.None;
                        }
                        jogMode = JogMode.None;
                    }

                    if (jogMode != JogMode.None)
                    {
                        if (GrblInfo.IsGrblHAL || !SoftLimits)
                        {
                            var distance = JogDistances[(int)jogMode].ToInvariantString();
                            SendJogCommand("$J=G91G21" + string.Format(command + "F{0}",
                                                                       JogFeedrates[(int)jogMode].ToInvariantString(),
                                                                       distance, distance, distance, distance));
                        }
                        else
                        {
                            for (int i = 0; i < N_AXIS; i++)
                            {
                                if (dist[i] != 0d)
                                {
                                    dist[i] = grbl.MachinePosition.Values[i] + JogDistances[(int)jogMode] * dist[i];

                                    if (i == GrblConstants.A_AXIS && GrblInfo.MaxTravel.Values[GrblConstants.A_AXIS] == 0d)
                                    {
                                        continue;
                                    }

                                    if (GrblInfo.ForceSetOrigin)
                                    {
                                        if (!GrblInfo.HomingDirection.HasFlag(GrblInfo.AxisIndexToFlag(i)))
                                        {
                                            if (dist[i] > 0)
                                            {
                                                dist[i] = 0;
                                            }
                                            else if (dist[i] < (-GrblInfo.MaxTravel.Values[i] + LimitSwitchesClearance))
                                            {
                                                dist[i] = (-GrblInfo.MaxTravel.Values[i] + LimitSwitchesClearance);
                                            }
                                        }
                                        else
                                        {
                                            if (dist[i] < 0d)
                                            {
                                                dist[i] = 0d;
                                            }
                                            else if (dist[i] > (GrblInfo.MaxTravel.Values[i] - LimitSwitchesClearance))
                                            {
                                                dist[i] = GrblInfo.MaxTravel.Values[i] - LimitSwitchesClearance;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (dist[i] > -LimitSwitchesClearance)
                                        {
                                            dist[i] = -LimitSwitchesClearance;
                                        }
                                        else if (dist[i] < -(GrblInfo.MaxTravel.Values[i] - LimitSwitchesClearance))
                                        {
                                            dist[i] = -(GrblInfo.MaxTravel.Values[i] - LimitSwitchesClearance);
                                        }
                                    }
                                }
                            }

                            SendJogCommand("$J=G53G21" + string.Format(command.Replace('-', ' ') + "F{0}",
                                                                       JogFeedrates[(int)jogMode].ToInvariantString(),
                                                                       dist[GrblConstants.X_AXIS].ToInvariantString(),
                                                                       dist[GrblConstants.Y_AXIS].ToInvariantString(),
                                                                       dist[GrblConstants.Z_AXIS].ToInvariantString(),
                                                                       dist[GrblConstants.A_AXIS].ToInvariantString()));
                        }
                    }

                    return(jogMode != JogMode.None);
                }
            }

            IsRepeating = e.IsRepeat;

            if (Keyboard.Modifiers == ModifierKeys.Alt)
            {
                var handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.SystemKey && k.onUp == e.IsUp && k.context == context).FirstOrDefault();
                if (handler != null)
                {
                    return(handler.Call(e.SystemKey));
                }
                else
                {
                    handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.SystemKey && k.onUp == e.IsUp && k.context == null).FirstOrDefault();
                    if (handler != null)
                    {
                        return(handler.Call(e.SystemKey));
                    }
                }
            }
            else if (Keyboard.Modifiers == ModifierKeys.None || Keyboard.Modifiers == ModifierKeys.Control || Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
            {
                var handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.Key && k.onUp == e.IsUp && k.context == context).FirstOrDefault();
                if (handler != null)
                {
                    return(handler.Call(e.Key));
                }
                else
                {
                    handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.Key && k.onUp == e.IsUp && k.context == null).FirstOrDefault();
                    if (handler != null)
                    {
                        return(handler.Call(e.Key));
                    }
                }
            }

            return(jogkeyPressed);
        }
Exemple #6
0
        public bool Set(string parameter, string value)
        {
            bool changed = false;

            switch (parameter)
            {
            case "MPos":
                if ((changed = _MPos != value))
                {
                    if (!_isMPos)
                    {
                        IsMachinePosition = true;
                    }
                    _MPos = value;
                    MachinePosition.Parse(_MPos);
                    for (int i = 0; i < GrblInfo.NumAxes; i++)
                    {
                        double newpos = MachinePosition.Values[i] - WorkPositionOffset.Values[i];
                        if (!Position.Values[i].Equals(newpos))
                        {
                            Position.Values[i] = newpos;
                        }
                    }
                }
                break;

            case "WPos":
                if ((changed = _WPos != value))
                {
                    if (_isMPos)
                    {
                        IsMachinePosition = false;
                    }
                    _WPos = value;
                    WorkPosition.Parse(_WPos);
                    for (int i = 0; i < GrblInfo.NumAxes; i++)
                    {
                        if (!Position.Values[i].Equals(WorkPosition.Values[i]))
                        {
                            Position.Values[i] = WorkPosition.Values[i];
                        }
                    }
                }
                break;

            case "A":
                if ((changed = _a != value))
                {
                    _a = value;

                    if (_a == "")
                    {
                        Mist = Flood = IsToolChanging = false;
                        SpindleState.Value = GCode.SpindleState.Off;
                    }
                    else
                    {
                        Mist               = value.Contains("M");
                        Flood              = value.Contains("F");
                        IsToolChanging     = value.Contains("T");
                        SpindleState.Value = value.Contains("S") ? GCode.SpindleState.CW : (value.Contains("C") ? GCode.SpindleState.CCW : GCode.SpindleState.Off);
                    }
                }
                break;

            case "WCO":
                if ((changed = _wco != value))
                {
                    _wco = value;
                    WorkPositionOffset.Parse(value);
                    if (_isMPos)
                    {
                        for (int i = 0; i < GrblInfo.NumAxes; i++)
                        {
                            double newpos = MachinePosition.Values[i] - WorkPositionOffset.Values[i];
                            if (!Position.Values[i].Equals(newpos))
                            {
                                Position.Values[i] = newpos;
                            }
                        }
                    }
                }
                break;

            case "WCS":
                if ((changed = _wcs != value))
                {
                    WorkCoordinateSystem = GrblParserState.WorkOffset = value;
                }
                break;

            case "FS":
                if ((changed = _fs != value))
                {
                    _fs = value;
                    if (_fs == "")
                    {
                        FeedRate = ProgrammedRPM = 0d;
                        if (!double.IsNaN(ActualRPM))
                        {
                            ActualRPM = 0d;
                        }
                    }
                    else
                    {
                        double[] values = dbl.ParseList(_fs);
                        if (_feedrate != values[0])
                        {
                            FeedRate = values[0];
                        }
                        if (_rpm != values[1])
                        {
                            ProgrammedRPM = values[1];
                        }
                        if (values.Length > 2 && _rpmActual != values[2])
                        {
                            ActualRPM = values[2];
                        }
                    }
                }
                break;

            case "Pn":
                if ((changed = _pn != value))
                {
                    _pn = value;

                    int s = 0;
                    foreach (char c in _pn)
                    {
                        int i = GrblConstants.SIGNALS.IndexOf(c);
                        if (i >= 0)
                        {
                            s |= (1 << i);
                        }
                    }
                    Signals.Value = (Signals)s;
                }
                break;

            case "Ov":
                if ((changed = _ov != value))
                {
                    _ov = value;
                    if (_ov == string.Empty)
                    {
                        FeedOverride = RapidsOverride = RPMOverride = 100d;
                    }
                    else
                    {
                        double[] values = dbl.ParseList(_ov);
                        if (_feedOverride != values[0])
                        {
                            FeedOverride = values[0];
                        }
                        if (_rapidsOverride != values[1])
                        {
                            RapidsOverride = values[1];
                        }
                        if (_rpmOverride != values[2])
                        {
                            RPMOverride = values[2];
                        }
                    }
                }
                break;

            case "Sc":
                if ((changed = _sc != value))
                {
                    int s = 0;
                    foreach (char c in value)
                    {
                        int i = GrblInfo.AxisLetterToIndex(c);
                        if (i >= 0)
                        {
                            s |= (1 << i);
                        }
                    }
                    AxisScaled.Value = (AxisFlags)s;
                    Scaling          = value;
                }
                break;

            case "Ex":
                if ((changed = _ex != value))
                {
                    TubeCoolant = value == "C";
                }
                break;

            case "SD":
                value = string.Format("SD Card streaming {0}% complete", value);
                if ((changed = SDCardStatus != value))
                {
                    Message = SDCardStatus = value;
                }
                break;

            case "T":
                if ((changed = _tool != value))
                {
                    Tool = GrblParserState.Tool = value == "0" ? GrblConstants.NO_TOOL : value;
                }
                break;

            case "MPG":
                GrblInfo.MPGMode = _grblState.MPG = value == "1";
                IsMPGActive      = _grblState.MPG;
                changed          = true;
                break;

            case "H":
                if (_h != value)
                {
                    _h         = value;
                    HomedState = value == "1" ? HomedState.Homed : HomedState.Unknown;
                    changed    = true;
                }
                break;

            case "D":
                _d        = value;
                LatheMode = GrblParserState.LatheMode = value == "0" ? LatheMode.Radius : LatheMode.Diameter;
                changed   = true;
                break;
            }

            return(changed);
        }