Beispiel #1
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();
            SystemInfo.Clear();

            model.Silent = true;

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

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

            model.Silent = false;

            model.AxisEnabledFlags = AxisFlags;
            model.LatheModeEnabled = LatheModeEnabled;

            return(res == true);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();

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

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

            return(res == true);
        }
Beispiel #4
0
 public KeypressHandler(GrblViewModel model)
 {
     grbl = model;
 }
Beispiel #5
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            settings.Clear();
            Comms.com.PurgeQueue();

            model.Silent = true;

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

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

            model.Silent = false;

            if (IsGrblHAL && !Resources.ConfigName.StartsWith("hal_"))
            {
                Resources.ConfigName = "hal_" + Resources.ConfigName;
            }

            try
            {
                StreamReader file = new StreamReader(string.Format("{0}{1}", Resources.Path, Resources.ConfigName));

                if (file != null)
                {
                    string line = file.ReadLine();

                    line = file.ReadLine(); // Skip header

                    while (line != null)
                    {
                        string[] columns = line.Split('\t');

                        if (columns.Length >= 6)
                        {
                            DataRow[] rows = settings.Select("Id=" + columns[0]);
                            if (rows.Count() == 1)
                            {
                                rows[0]["Name"]        = columns[1];
                                rows[0]["Unit"]        = columns[2];
                                rows[0]["DataType"]    = columns[3];
                                rows[0]["DataFormat"]  = columns[4];
                                rows[0]["Description"] = columns[5];
                                if (columns.Length >= 7)
                                {
                                    rows[0]["Min"] = dbl.Parse(columns[6]);
                                }
                                if (columns.Length >= 8)
                                {
                                    rows[0]["Max"] = dbl.Parse(columns[7]);
                                }
                                if ((string)rows[0]["DataType"] == "float")
                                {
                                    rows[0]["Value"] = GrblSettings.FormatFloat((string)rows[0]["Value"], (string)rows[0]["DataFormat"]);
                                }
                            }
                        }
                        line = file.ReadLine();
                    }
                    file.Close();
                    file.Dispose();
                }
            }
            catch
            {
            }

            settings.AcceptChanges();

            return(Loaded);
        }