Beispiel #1
0
        public void ShowPosition()
        {
            GrblViewModel model = (GrblViewModel)DataContext;

            Machine.ToolPosition = null;

            positionPoints.Clear();

            if (Machine.Limits.X == 0d)
            {
                Machine.SetLimits(GrblSettings.GetDouble(GrblSetting.AxisSetting_XMaxTravel),
                                  GrblSettings.GetDouble(GrblSetting.AxisSetting_YMaxTravel),
                                  GrblSettings.GetDouble(GrblSetting.AxisSetting_ZMaxTravel));
            }

            positionPoints.Add(new Point3D(Math.Min(model.Position.X, model.ProgramLimits.MinX) - 5d, model.Position.Y, model.Position.Z));
            positionPoints.Add(new Point3D(Machine.Limits.X, model.Position.Y, model.Position.Z));

            positionPoints.Add(new Point3D(model.Position.X, Math.Min(model.Position.Y, model.ProgramLimits.MinY) - 5d, model.Position.Z));
            positionPoints.Add(new Point3D(model.Position.X, Machine.Limits.Y, model.Position.Z));

            positionPoints.Add(new Point3D(model.Position.X, model.Position.Y, Math.Min(model.Position.Z, model.ProgramLimits.MinZ) - 5d));
            positionPoints.Add(new Point3D(model.Position.X, model.Position.Y, Machine.Limits.Z));

            Machine.ToolPosition = positionPoints;
            var orgpos = Machine.StartPosition;

            Machine.SetStartPosition(model.Position.X, model.Position.Y, model.Position.Z);

            if (Machine.RapidLines != null && Machine.RapidLines.Count > 0 && Machine.RapidLines[0].Equals(orgpos))
            {
                Machine.RapidLines.RemoveAt(0);
                Machine.RapidLines.Insert(0, Machine.StartPosition);
            }
        }
Beispiel #2
0
 private void GrblConfigView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.OldValue is GrblViewModel)
     {
         model = (GrblViewModel)e.OldValue;
     }
 }
Beispiel #3
0
        public bool Load(GrblViewModel model, string cmd)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();

            model.Silent = true;

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

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

            return(settings.Count > 0);
        }
        public MPGPending(GrblViewModel model)
        {
            InitializeComponent();

            this.model = model;

            model.OnRealtimeStatusProcessed += OnRealtimeStatusProcessed;
        }
Beispiel #5
0
 private void TrinamicView_Loaded(object sender, RoutedEventArgs e)
 {
     if (model == null)
     {
         model       = DataContext as GrblViewModel;
         DataContext = null;
     }
 }
Beispiel #6
0
 private void DisplayPosition(GrblViewModel grbl)
 {
     model.Position = string.Format("X:{0}  Y:{1}  Z:{2} {3} {4}",
                                    grbl.Position.X.ToInvariantString(grbl.Format),
                                    grbl.Position.Y.ToInvariantString(grbl.Format),
                                    grbl.Position.Z.ToInvariantString(grbl.Format),
                                    probeTriggered ? "P" : "",
                                    probeDisconnected ? "D" : "");
 }
        private void Renderer_Loaded(object sender, RoutedEventArgs e)
        {
            model = DataContext as GrblViewModel;

            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                AppConfig.Settings.GCodeViewer.PropertyChanged += GCodeViewer_PropertyChanged;
            }
        }
Beispiel #8
0
 private void View_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is GrblViewModel)
     {
         model = (GrblViewModel)e.NewValue;
         model.PropertyChanged += OnDataContextPropertyChanged;
         DataContextChanged    -= View_DataContextChanged;
         //          model.OnGrblReset += Model_OnGrblReset;
     }
 }
 public void Setup(UIViewModel model, AppConfig profile)
 {
     this.model     = model;
     grblmodel      = DataContext as GrblViewModel;
     DataContext    = profile.Base;
     xx.ItemsSource = model.ConfigControls;
     model.ConfigControls.Add(new BasicConfigControl());
     model.ConfigControls.Add(new StripGCodeConfigControl());
     model.ConfigControls.Add(new JogConfigControl());
 }
Beispiel #10
0
        public ProbingViewModel(GrblViewModel grblmodel)
        {
            Grbl       = grblmodel;
            Distance.X = Distance.Y = Distance.Z = 10d;
            Offset.X   = Offset.Y = Offset.Z = 5d;

            Execute = new ActionCommand <bool>(ExecuteProgram);

            HeightMap.PropertyChanged += HeightMap_PropertyChanged;
        }
Beispiel #11
0
        public static void Load(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            data.Clear();

            if (mounted == null)
            {
                Comms.com.PurgeQueue();

                new Thread(() =>
                {
                    mounted = WaitFor.AckResponse <string>(
                        cancellationToken,
                        null,
                        a => model.OnResponseReceived += a,
                        a => model.OnResponseReceived -= a,
                        500, () => Comms.com.WriteCommand(GrblConstants.CMD_SDCARD_MOUNT));
                }).Start();

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

            if (mounted == true)
            {
                Comms.com.PurgeQueue();

                id           = 0;
                model.Silent = true;

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

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

                model.Silent = false;

                data.AcceptChanges();
            }
        }
Beispiel #12
0
 private void JobControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.OldValue != null && e.OldValue is INotifyPropertyChanged)
     {
         ((INotifyPropertyChanged)e.OldValue).PropertyChanged -= OnDataContextPropertyChanged;
     }
     if (e.NewValue != null && e.NewValue is INotifyPropertyChanged)
     {
         model = (GrblViewModel)e.NewValue;
         model.PropertyChanged += OnDataContextPropertyChanged;
     }
 }
Beispiel #13
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (DataContext is GrblViewModel)
            {
                model = DataContext as GrblViewModel;
            }

            if (Visibility != Visibility.Visible)
            {
                DataContext = null;
            }
        }
Beispiel #14
0
        public ProbingViewModel(GrblViewModel grblmodel, ProbingProfiles profile)
        {
            Grbl = grblmodel;

//            Execute = new ActionCommand<bool>(ExecuteProgram);

            Program = new Program(this);

            Profiles = profile.Profiles;
            Profile  = profile.Profiles[0];

            HeightMap.PropertyChanged += HeightMap_PropertyChanged;
        }
        public KeypressHandler(GrblViewModel model)
        {
            grbl = model;

            bool useFirmwareJog = false;

            if (GrblSettings.IsLoaded)
            {
                double val;
                if ((useFirmwareJog = !(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN)))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                model.IsMetric = GrblSettings.GetString(GrblSetting.ReportInches) != "1";
            }

            if (!useFirmwareJog)
            {
                model.JogStep = jogDistance[(int)JogMode.Step] = AppConfig.Settings.Jog.StepDistance;
                jogDistance[(int)JogMode.Slow] = AppConfig.Settings.Jog.SlowDistance;
                jogDistance[(int)JogMode.Fast] = AppConfig.Settings.Jog.SlowDistance;
                jogSpeed[(int)JogMode.Step]    = AppConfig.Settings.Jog.StepFeedrate;
                jogSpeed[(int)JogMode.Slow]    = AppConfig.Settings.Jog.SlowFeedrate;
                jogSpeed[(int)JogMode.Fast]    = AppConfig.Settings.Jog.FastFeedrate;
            }

            fullJog = AppConfig.Settings.Jog.KeyboardEnable || GrblSettings.IsGrblHAL;
        }
 private void JobControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.OldValue != null && e.OldValue is INotifyPropertyChanged)
     {
         ((INotifyPropertyChanged)e.OldValue).PropertyChanged -= OnDataContextPropertyChanged;
     }
     if (e.NewValue != null && e.NewValue is INotifyPropertyChanged)
     {
         model = (GrblViewModel)e.NewValue;
         model.PropertyChanged           += OnDataContextPropertyChanged;
         model.OnRealtimeStatusProcessed += RealtimeStatusProcessed;
         model.OnCommandResponseReceived += ResponseReceived;
         GCode.File.Model = model;
     }
 }
Beispiel #17
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!keyboardMappingsOk && DataContext is GrblViewModel)
            {
                grbl = (DataContext as GrblViewModel);
                KeypressHandler keyboard = grbl.Keyboard;

                keyboardMappingsOk = true;

                keyboard.AddHandler(Key.R, ModifierKeys.Alt, StartProbe, this);
                keyboard.AddHandler(Key.S, ModifierKeys.Alt, StopProbe, this);
                keyboard.AddHandler(Key.C, ModifierKeys.Alt, ProbeConnectedToggle, this);

                DataContext = model = new ProbingViewModel(DataContext as GrblViewModel, profiles);
            }
        }
Beispiel #18
0
        public KeypressHandler(GrblViewModel model)
        {
            grbl = model;

            bool useFirmwareJog = false;

            if (GrblSettings.IsLoaded)
            {
                double val;
                if ((useFirmwareJog = !(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN)))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                fullJog        = GrblSettings.IsGrblHAL;
                model.IsMetric = GrblSettings.GetString(GrblSetting.ReportInches) != "1";
            }

            if (!useFirmwareJog)
            {
                AppConfig.Settings.Jog.PropertyChanged += Jog_PropertyChanged;
                updateConfig();
            }
        }
        public void ShowPosition()
        {
            GrblViewModel model = (GrblViewModel)DataContext;

            foreach (var path in position)
            {
                viewport.Children.Remove(path);
            }

            position.Clear();

            double maxX = GrblSettings.GetDouble(GrblSetting.AxisSetting_XMaxTravel);
            double maxY = GrblSettings.GetDouble(GrblSetting.AxisSetting_YMaxTravel);
            double maxZ = GrblSettings.GetDouble(GrblSetting.AxisSetting_ZMaxTravel);

            var positionX = new LinesVisual3D();

            positionX.Color     = Colors.Green;
            positionX.Thickness = 1;
            positionX.Points.Add(new Point3D(model.ProgramLimits.MinX - 5d, model.Position.Y, model.Position.Z));
            positionX.Points.Add(new Point3D(maxX, model.Position.Y, model.Position.Z));
            position.Add(positionX);

            var positionY = new LinesVisual3D();

            positionY.Color     = Colors.Green;
            positionY.Thickness = 1;
            positionY.Points.Add(new Point3D(model.Position.X, model.ProgramLimits.MinY - 5d, model.Position.Z));
            positionY.Points.Add(new Point3D(model.Position.X, maxY, model.Position.Z));
            position.Add(positionY);

            var positionZ = new LinesVisual3D();

            positionZ.Color     = Colors.Green;
            positionZ.Thickness = 1;
            positionZ.Points.Add(new Point3D(model.Position.X, model.Position.Y, model.ProgramLimits.MinZ - 5d));
            positionZ.Points.Add(new Point3D(model.Position.X, model.Position.Y, maxZ));
            position.Add(positionZ);

            foreach (var path in position)
            {
                viewport.Children.Add(path);
            }
        }
Beispiel #20
0
 public void Setup(UIViewModel model, AppConfig profile)
 {
     if (this.model == null)
     {
         this.model     = model;
         grblmodel      = DataContext as GrblViewModel;
         DataContext    = profile.Base;
         xx.ItemsSource = model.ConfigControls;
         model.ConfigControls.Add(new BasicConfigControl());
         if (AppConfig.Settings.Jog.Mode != JogConfig.JogMode.Keypad)
         {
             model.ConfigControls.Add(new JogUiConfigControl());
         }
         if (AppConfig.Settings.Jog.Mode != JogConfig.JogMode.UI)
         {
             model.ConfigControls.Add(new JogConfigControl());
         }
         model.ConfigControls.Add(new StripGCodeConfigControl());
     }
 }
Beispiel #21
0
 private void Renderer_Loaded(object sender, RoutedEventArgs e)
 {
     model = DataContext as GrblViewModel;
 }
Beispiel #22
0
        public int SetupAndOpen(string appname, GrblViewModel model, System.Windows.Threading.Dispatcher dispatcher)
        {
            int    status     = 0;
            bool   selectPort = false;
            int    jogMode    = -1;
            string port       = string.Empty;

            CNC.Core.Resources.Path = AppDomain.CurrentDomain.BaseDirectory;

            string[] args = Environment.GetCommandLineArgs();

            int p = 0;

            while (p < args.GetLength(0))
            {
                switch (args[p++].ToLowerInvariant())
                {
                case "-inifile":
                    CNC.Core.Resources.IniName = GetArg(args, p++);
                    break;

                case "-debugfile":
                    CNC.Core.Resources.DebugFile = GetArg(args, p++);
                    break;

                case "-configmapping":
                    CNC.Core.Resources.ConfigName = GetArg(args, p++);
                    break;

                case "-locale":
                case "-language":     // deprecated
                    CNC.Core.Resources.Locale = GetArg(args, p++);
                    break;

                case "-port":
                    port = GetArg(args, p++);
                    break;

                case "-selectport":
                    selectPort = true;
                    break;

                case "-islegacy":
                    CNC.Core.Resources.IsLegacyController = true;
                    break;

                case "-jogmode":
                    if (int.TryParse(GetArg(args, p++), out jogMode))
                    {
                        jogMode = Math.Min(Math.Max(jogMode, 0), (int)JogConfig.JogMode.KeypadAndUI);
                    }
                    break;

                default:
                    if (!args[p - 1].EndsWith(".exe") && File.Exists(args[p - 1]))
                    {
                        FileName = args[p - 1];
                    }
                    break;
                }
            }

            if (!Load(CNC.Core.Resources.IniFile))
            {
                if (MessageBox.Show(LibStrings.FindResource("CreateConfig"), appname, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    if (!Save(CNC.Core.Resources.IniFile))
                    {
                        MessageBox.Show(LibStrings.FindResource("CreateConfigFail"), appname);
                        status = 1;
                    }
                }
                else
                {
                    return(1);
                }
            }

            if (jogMode != -1)
            {
                Base.Jog.Mode = (JogConfig.JogMode)jogMode;
            }

            if (!string.IsNullOrEmpty(port))
            {
                selectPort = false;
            }

            if (!selectPort)
            {
                if (!string.IsNullOrEmpty(port))
                {
                    setPort(port);
                }
#if USEWEBSOCKET
                if (Base.PortParams.ToLower().StartsWith("ws://"))
                {
                    new WebsocketStream(Base.PortParams, dispatcher);
                }
                else
#endif
                if (char.IsDigit(Base.PortParams[0])) // We have an IP address
                {
                    new TelnetStream(Base.PortParams, dispatcher);
                }
                else
#if USEELTIMA
                { new EltimaStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#else
                { new SerialStream(Base.PortParams, Base.ResetDelay, dispatcher); }
#endif
            }

            if ((Comms.com == null || !Comms.com.IsOpen) && string.IsNullOrEmpty(port))
            {
                PortDialog portsel = new PortDialog();

                port = portsel.ShowDialog(Base.PortParams);
                if (string.IsNullOrEmpty(port))
                {
                    status = 2;
                }

                else
                {
                    setPort(port);
#if USEWEBSOCKET
                    if (port.ToLower().StartsWith("ws://"))
                    {
                        new WebsocketStream(Base.PortParams, dispatcher);
                    }
                    else
#endif
                    if (char.IsDigit(port[0])) // We have an IP address
                    {
                        new TelnetStream(Base.PortParams, dispatcher);
                    }
                    else
#if USEELTIMA
                    { new EltimaStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#else
                    { new SerialStream(Base.PortParams, Base.ResetDelay, dispatcher); }
#endif
                    Save(CNC.Core.Resources.IniFile);
                }
            }

            if (Comms.com != null && Comms.com.IsOpen)
            {
                Comms.com.DataReceived += model.DataReceived;

                CancellationToken cancellationToken = new CancellationToken();

                // Wait 400ms to see if a MPG is polling Grbl...

                new Thread(() =>
                {
                    MPGactive = WaitFor.SingleEvent <string>(
                        cancellationToken,
                        null,
                        a => model.OnRealtimeStatusProcessed += a,
                        a => model.OnRealtimeStatusProcessed -= a,
                        500);
                }).Start();

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

                // ...if so show dialog for wait for it to stop polling and relinquish control.
                if (MPGactive == true)
                {
                    MPGPending await = new MPGPending(model);
                    await.ShowDialog();
                    if (await.Cancelled)
                    {
                        Comms.com.Close(); //!!
                        status = 2;
                    }
                }

                model.IsReady = true;
            }
            else if (status != 2)
            {
                MessageBox.Show(string.Format(LibStrings.FindResource("ConnectFailed"), Base.PortParams), appname, MessageBoxButton.OK, MessageBoxImage.Error);
                status = 2;
            }

            return(status);
        }
Beispiel #23
0
 public Program(ProbingViewModel model)
 {
     Grbl    = model.Grbl;
     probing = model;
 }
Beispiel #24
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.CallHandler(GCode.File.IsLoaded ? StreamingState.Idle : (sdStream ? StreamingState.Start : StreamingState.NoFile), false);
                sdStream = false;

                if (initOK != true)
                {
                    model.Message = "Waiting for controller...";

                    Comms.com.PurgeQueue();
                    Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT));

                    int timeout = 30; // 1.5s
                    do
                    {
                        System.Threading.Thread.Sleep(50);
                    } while (Comms.com.Reply == "" && --timeout != 0);

                    if (Comms.com.Reply.StartsWith("<Alarm"))
                    {
                        GrblViewModel data = (GrblViewModel)DataContext;
                        data.ParseStatus(Comms.com.Reply);

                        // Alarm 1, 2 and 10 are critical events
                        if (!(data.GrblState.Substate == 1 || data.GrblState.Substate == 2 || data.GrblState.Substate == 10))
                        {
                            InitSystem();
                        }
                    }
                    else if (Comms.com.Reply != "")
                    {
                        InitSystem();
                    }
                }

                if (initOK == null)
                {
                    initOK = false;
                }

                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset += Camera_MoveOffset;
                    MainWindow.UIViewModel.Camera.Opened     += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCode.File.IsLoaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }
            }
            else if (ViewType != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset -= Camera_MoveOffset;
                }
                #endif
            }

            if (GCodeSender.Activate(activate))
            {
                Task.Delay(500).ContinueWith(t => DRO.EnableFocus());
                Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    Focus();
                }), DispatcherPriority.Render);
            }
        }
Beispiel #25
0
 public Controller(GrblViewModel model)
 {
     this.model = model;
 }
Beispiel #26
0
        private void JogCommand(string cmd)
        {
            GrblViewModel model = DataContext as GrblViewModel;

            if (cmd == "stop")
            {
                cmd = ((char)GrblConstants.CMD_JOG_CANCEL).ToString();
            }

            else
            {
                var distance = cmd[1] == '-' ? -JogData.Distance : JogData.Distance;

                if (softLimits)
                {
                    int axis = GrblInfo.AxisLetterToIndex(cmd[0]);

                    if (jogAxis != -1 && axis != jogAxis)
                    {
                        return;
                    }

                    if (axis != jogAxis)
                    {
                        position = distance + model.MachinePosition.Values[axis];
                    }
                    else
                    {
                        position += distance;
                    }

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

                    if (position == 0d)
                    {
                        return;
                    }

                    jogAxis = axis;

                    cmd = string.Format("$J=G53{0}{1}{2}F{3}", mode, cmd.Substring(0, 1), position.ToInvariantString(), Math.Ceiling(JogData.FeedRate).ToInvariantString());
                }
                else
                {
                    cmd = string.Format("$J=G91{0}{1}{2}F{3}", mode, cmd.Substring(0, 1), distance.ToInvariantString(), Math.Ceiling(JogData.FeedRate).ToInvariantString());
                }
            }

            model.ExecuteCommand(cmd);
        }
Beispiel #27
0
        private void Upload_Click(object sender, RoutedEventArgs e)
        {
            bool           ok       = false;
            string         filename = string.Empty;
            OpenFileDialog file     = new OpenFileDialog();

            file.Filter = string.Format("GCode files ({0})|{0}|Text files (*.txt)|*.txt|All files (*.*)|*.*", FileUtils.ExtensionsToFilter(GCode.FileTypes));

            if (file.ShowDialog() == true)
            {
                filename = file.FileName;
            }

            if (filename != string.Empty)
            {
                GrblViewModel model = DataContext as GrblViewModel;

                model.Message = (string)FindResource("Uploading");

                if (GrblInfo.UploadProtocol == "FTP")
                {
                    if (GrblInfo.IpAddress == string.Empty)
                    {
                        model.Message = (string)FindResource("NoConnection");
                    }
                    else
                    {
                        using (new UIUtils.WaitCursor())
                        {
                            model.Message = (string)FindResource("Uploading");
                            try
                            {
                                using (WebClient client = new WebClient())
                                {
                                    client.Credentials = new NetworkCredential("grblHAL", "grblHAL");
                                    client.UploadFile(string.Format("ftp://{0}/{1}", GrblInfo.IpAddress, filename.Substring(filename.LastIndexOf('\\') + 1)), WebRequestMethods.Ftp.UploadFile, filename);
                                    ok = true;
                                }
                            }
                            catch (WebException ex)
                            {
                                model.Message = ex.Message.ToString() + " " + ((FtpWebResponse)ex.Response).StatusDescription;
                            }
                            catch (System.Exception ex)
                            {
                                model.Message = ex.Message.ToString();
                            }
                        }
                    }
                }
                else
                {
                    model.Message = (string)FindResource("Uploading");
                    YModem ymodem = new YModem();
                    ymodem.DataTransferred += Ymodem_DataTransferred;
                    ok = ymodem.Upload(filename);
                }

                if (!(GrblInfo.UploadProtocol == "FTP" && !ok))
                {
                    model.Message = (string)FindResource(ok ? "TransferDone" : "TransferAborted");
                }

                GrblSDCard.Load(model);
            }
        }
 private void DisplayPosition(GrblViewModel grbl)
 {
     model.Position = string.Format("X:{0}  Y:{1}  Z:{2}{3}", grbl.Position.X.ToInvariantString(grbl.Format), grbl.Position.Y.ToInvariantString(grbl.Format), grbl.Position.Z.ToInvariantString(grbl.Format), probeTriggered ? " P" : "");
     //   model.Message = string.Format("X:{0}  Y:{1}  Z:{2}", grbl.Position.X.ToInvariantString(), grbl.Position.Y.ToInvariantString(), grbl.Position.Z.ToInvariantString());
 }
Beispiel #29
0
        public int SetupAndOpen(string appname, GrblViewModel model, System.Windows.Threading.Dispatcher dispatcher)
        {
            int    status     = 0;
            bool   selectPort = false;
            string port       = string.Empty;

            CNC.Core.Resources.Path = AppDomain.CurrentDomain.BaseDirectory;

            string[] args = Environment.GetCommandLineArgs();

            int p = 0;

            while (p < args.GetLength(0))
            {
                switch (args[p++])
                {
                case "-inifile":
                    CNC.Core.Resources.IniName = GetArg(args, p++);
                    break;

                case "-configmapping":
                    CNC.Core.Resources.ConfigName = GetArg(args, p++);
                    break;

                case "-language":
                    CNC.Core.Resources.Language = GetArg(args, p++);
                    break;

                case "-port":
                    port = GetArg(args, p++);
                    break;

                case "-selectport":
                    selectPort = true;
                    break;

                default:
                    if (!args[p - 1].EndsWith(".exe") && File.Exists(args[p - 1]))
                    {
                        FileName = args[p - 1];
                    }
                    break;
                }
            }

            if (!Load(CNC.Core.Resources.IniFile))
            {
                if (MessageBox.Show("Config file not found or invalid, create new?", appname, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    if (!Save(CNC.Core.Resources.IniFile))
                    {
                        MessageBox.Show("Could not save config file.", appname);
                        status = 1;
                    }
                }
                else
                {
                    return(1);
                }
            }

            if (!string.IsNullOrEmpty(port))
            {
                selectPort = false;
            }

            if (!selectPort)
            {
                if (!string.IsNullOrEmpty(port))
                {
                    setPort(port);
                }
#if USEWEBSOCKET
                if (Config.PortParams.ToLower().StartsWith("ws://"))
                {
                    new WebsocketStream(Config.PortParams, dispatcher);
                }
                else
#endif
                if (char.IsDigit(Config.PortParams[0])) // We have an IP address
                {
                    new TelnetStream(Config.PortParams, dispatcher);
                }
                else
#if USEELTIMA
                { new EltimaStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#else
                { new SerialStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#endif
            }

            if ((Comms.com == null || !Comms.com.IsOpen) && string.IsNullOrEmpty(port))
            {
                PortDialog portsel = new PortDialog();

                port = portsel.ShowDialog(Config.PortParams);
                if (string.IsNullOrEmpty(port))
                {
                    status = 2;
                }

                else
                {
                    setPort(port);
#if USEWEBSOCKET
                    if (port.ToLower().StartsWith("ws://"))
                    {
                        new WebsocketStream(Config.PortParams, dispatcher);
                    }
                    else
#endif
                    if (char.IsDigit(port[0])) // We have an IP address
                    {
                        new TelnetStream(Config.PortParams, dispatcher);
                    }
                    else
#if USEELTIMA
                    { new EltimaStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#else
                    { new SerialStream(Config.PortParams, Config.ResetDelay, dispatcher); }
#endif
                    Save(CNC.Core.Resources.IniFile);
                }
            }

            if (Comms.com != null && Comms.com.IsOpen)
            {
                Comms.com.DataReceived += model.DataReceived;

                CancellationToken cancellationToken = new CancellationToken();

                // Wait 400ms to see if a MPG is polling Grbl...

                new Thread(() =>
                {
                    MPGactive = WaitFor.SingleEvent <string>(
                        cancellationToken,
                        null,
                        a => model.OnRealtimeStatusProcessed += a,
                        a => model.OnRealtimeStatusProcessed -= a,
                        500);
                }).Start();

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

                // ...if so show dialog for wait for it to stop polling and relinquish control.
                if (MPGactive == true)
                {
                    MPGPending await = new MPGPending(model);
                    await.ShowDialog();
                    if (await.Cancelled)
                    {
                        Comms.com.Close(); //!!
                        status = 2;
                    }
                }

                model.IsReady      = true;
                model.PollInterval = Config.PollInterval;
            }
            else if (status != 2)
            {
                MessageBox.Show(string.Format("Unable to open connection ({0})", Config.PortParams), appname, MessageBoxButton.OK, MessageBoxImage.Error);
                status = 2;
            }

            return(status);
        }
Beispiel #30
0
        private void Ymodem_DataTransferred(long size, long transferred)
        {
            GrblViewModel model = DataContext as GrblViewModel;

            model.Message = string.Format((string)FindResource("Transferring"), transferred, size);
        }