Esempio n. 1
0
        public async Task <CNCMessage> JogY(double Y, double Feed)
        {
            CNCMessage tmp = null;
            await Task.Run(() =>
            {
                GRBLProtokoll pr = new GRBLProtokoll();
                CNCMessage m     = pr.GetCurrentFeedMessage();
                //CNCMessage start = new CNCMessage() { Message = "Grbl 1.1g ['$' for help]" };
                //var an = Interface.WaitReceiveMessage(100, start, 2000);

                CNCMessage message = Protokoll.GetJogByYMessage(Y, Feed);
                Interface.SendMessage(message);
                CNCMessage t = new CNCMessage()
                {
                    Message = "ok"
                };
                tmp = Interface.WaitReceiveMessage(100, t, 1000);
            });

            return(tmp);
        }
Esempio n. 2
0
        /// <summary>
        /// This Method gets called every time a static method is changed. Be !careful!, this method only gets called if the
        /// value actually change. If the new value is the same as before, than it not get changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PresentViewModel_StaticPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(PresentViewModel.CurrentSelectedPortName):

                if (Device != null && Device.Interface.Portname == CurrentSelectedPortName)
                {
                    Device.Interface.CloseConnection();
                    Device.RefreshInterval = 0;
                    _Device = null;
                    return;
                }

                //Delete old device and, most importantly, close old connection
                if (Device != null)
                {
                    Device.Interface.CloseConnection();
                    Device.RefreshInterval = 0;
                    _Device = null;
                }



                // Make new device
                CNCInterface iface     = new SerialGRBLInterface(CurrentSelectedPortName, CurrentSelectedBaudRate);
                CNCProtokoll protokoll = new GRBLProtokoll();

                _Device = new CNC_Device(iface, protokoll);
                (iface as SerialGRBLInterface).PortOpened += (s, k) =>
                {
                    ToolbarViewModel.IsConnected = true;
                };
                (iface as SerialGRBLInterface).OpenPortFailed += (s, k) =>
                {
                    ToolbarViewModel.IsConnected = false;
                };
                (iface as SerialGRBLInterface).PortClosed += (s, k) =>
                {
                    ToolbarViewModel.IsConnected = false;
                    Device.RefreshInterval       = 0;
                };
                Device.PropertyChanged += Device_PropertyChanged;
                (iface as SerialGRBLInterface).FirePortOpened();
                Device.SendReceiveBuffer.CollectionChanged += (s, k) =>
                {
                    if (k.NewItems == null)
                    {
                        return;
                    }

                    foreach (var item in k.NewItems)
                    {
                        ConsoleViewModel.AppendLineToConsole(item as string);
                    }
                };

                // TODO: Add Refresh Rate Textbox to ToolbarPresenter and bind it!
                Device.RefreshInterval = 100;

                break;

            case nameof(Device):


                break;


            default:
                break;
            }
        }