Beispiel #1
0
        public async Task <float[]> GetCurrentXYZ()
        {
            float[] r = new float[3];
            await Task.Run(() =>
            {
                CNCMessage message = Protokoll.GetCurrentXYZMessage();
                if (ConsoleViewModel.Verbose)
                {
                    Interface.SendMessage(message);
                }
                else
                {
                    Interface.SendMessage(message, false);
                }

                CNCMessage output;
                CNCMessage outokerror;
                List <string> outarray = new List <string>();
                outarray.Add("ok");
                outarray.Add("error");


                if (ConsoleViewModel.Verbose)
                {
                    output     = Interface.WaitReceiveMessageContaining(100, "WPos", 100);
                    outokerror = Interface.WaitReceiveMessageContainingMultible(100, outarray, 100);
                }
                else
                {
                    output     = Interface.WaitReceiveMessageContaining(100, "WPos", 100, logging: false);
                    outokerror = Interface.WaitReceiveMessageContainingMultible(100, outarray, 100, logging: false);
                }


                try
                {
                    r[0] = Convert.ToSingle(Regex.Match(output.Message, @"(WPos:([-0-9]+.[0-9]+),([-0-9]+.[0-9]+),([-0-9]+.[0-9]))").Groups[2].Value, CultureInfo.InvariantCulture);
                    r[1] = Convert.ToSingle(Regex.Match(output.Message, @"(WPos:([-0-9]+.[0-9]+),([-0-9]+.[0-9]+),([-0-9]+.[0-9]))").Groups[3].Value, CultureInfo.InvariantCulture);
                    r[2] = Convert.ToSingle(Regex.Match(output.Message, @"(WPos:([-0-9]+.[0-9]+),([-0-9]+.[0-9]+),([-0-9]+.[0-9]))").Groups[4].Value, CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    r[0] = CurrentX;
                    r[1] = CurrentY;
                    r[2] = CurrentZ;
                }
            });

            return(r);
        }