示例#1
0
 public override void Dispose(string msg)
 {
     Console.WriteLine(msg);
     try
     {
         if (Remote != null)
         {
             lock (this)
             {
                 if (Remote != null)
                 {
                     Remote      = null;
                     IsAvailable = false;
                     UdpClient.Close();
                     UdpClient.Dispose();
                     SendLine.Clear();
                     MessageLine.Clear();
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Dispose " + e.Message);
     }
 }
        private async void ButtonApply_Click(object sender, RoutedEventArgs e)
        {
            List <Tuple <int, double> > ToSend = new List <Tuple <int, double> >();

            foreach (KeyValuePair <int, double> kvp in CurrentSettings)
            {
                double newval;

                if (!double.TryParse(SettingsBoxes[kvp.Key].Text, System.Globalization.NumberStyles.Float, Util.Constants.DecimalParseFormat, out newval))
                {
                    MessageBox.Show($"Value \"{SettingsBoxes[kvp.Key].Text}\" is invalid for Setting \"{Util.GrblCodeTranslator.Settings[kvp.Key].Item1}\"");
                    return;
                }

                if (newval == kvp.Value)
                {
                    continue;
                }

                ToSend.Add(new Tuple <int, double>(kvp.Key, newval));
            }

            if (SendLine == null)
            {
                return;
            }

            foreach (Tuple <int, double> setting in ToSend)
            {
                SendLine.Invoke($"${setting.Item1}={setting.Item2.ToString(Util.Constants.DecimalOutputFormat)}");
                CurrentSettings[setting.Item1] = setting.Item2;
                await Task.Delay(Properties.Settings.Default.SettingsSendDelay);
            }
        }
示例#3
0
        protected void SendCompleted()
        {
            if (SendArgs.BytesTransferred > 0)
            {
                byte[] buffer = null;
                lock (SendLine)
                {
                    //获取队列数据
                    if (SendLine.Count <= 0)
                    {
                        //没有数据重置外部调用
                        SendAvailable = true;
                    }
                    else
                    {
                        buffer = SendLine.Dequeue();
                    }
                }

                //有效
                if (IsAvailable)
                {
                    if (buffer != null)
                    {
                        //继续发送
                        Send(buffer);
                    }
                }
            }
            else
            {
                Dispose("SendArgs 小于0");
            }
        }
示例#4
0
        /// <summary>
        /// Reset Selected G54 X, Y, Z Offsets - All Reset buttons use this function - uses TAG= to desinguish between what button is pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnResetOffset_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if (b == null)
            {
                return;
            }

            switch (b.Tag as string)
            {
            case "ResetG54":
                G54X.Text = "0.000";
                G54Y.Text = "0.000";
                G54Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P1 X0.000 Y0.000 Z0.000");
                break;

            case "ResetG55":
                G55X.Text = "0.000";
                G55Y.Text = "0.000";
                G55Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P2 X0.000 Y0.000 Z0.000");
                break;

            case "ResetG56":
                G56X.Text = "0.000";
                G56Y.Text = "0.000";
                G56Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P3 X0.000 Y0.000 Z0.000");
                break;

            case "ResetG57":
                G57X.Text = "0.000";
                G57Y.Text = "0.000";
                G57Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P4 X0.000 Y0.000 Z0.000");
                break;

            case "ResetG58":
                G58X.Text = "0.000";
                G58Y.Text = "0.000";
                G58Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P5 X0.000 Y0.000 Z0.000");
                break;

            case "ResetG59":
                G59X.Text = "0.000";
                G59Y.Text = "0.000";
                G59Z.Text = "0.000";
                SendLine.Invoke($"G10 L2 P6 X0.000 Y0.000 Z0.000");
                break;
            }
        }
示例#5
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns></returns>
 public override bool PushDataIntoLine(byte[] buffer)
 {
     if (IsAvailable)
     {
         lock (SendLine)
         {
             SendLine.Enqueue(buffer);
             Monitor.PulseAll(SendLine);
         }
         return(true);
     }
     return(false);
 }
示例#6
0
        public Netstat()
        {
            InitializeComponent();
            int        Pid  = 0;
            MainWindow Main = new MainWindow();

            Pid = MainWindow.PPID;
            ProcInfo.ProcessID = Pid;
            t = new Thread(new ThreadStart(list));
            t.SetApartmentState(ApartmentState.STA);
            t.IsBackground = true;
            t.Start();
            for (int i = 0; i < SendLine.Count; i++)
            {
                SendLine.RemoveAt(i);
            }
            ReadLine.Clear();
        }
示例#7
0
        /// <summary>
        /// 循环发送
        /// </summary>
        protected override void Send(byte[] data)
        {
            try
            {
                lock (SendLine)
                {
                    if (SendLine.Count > 0)
                    {
                        data = SendLine.Dequeue();
                    }
                    else
                    {
                        SendFlag = true;
                        Monitor.Wait(SendLine);
                    }
                }

                if (data != null)
                {
                    UdpClient.BeginSend(data, data.Length, Remote, (ar) =>
                    {
                        if (UdpClient.EndSend(ar) == data.Length)
                        {
                            ar.AsyncWaitHandle.Dispose();
                            Send(null);
                        }
                    }, null);
                }
                else
                {
                    Send(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Dispose("Send " + e.Message);
            }
        }
示例#8
0
        public override bool PushDataIntoLine(byte[] buffer)
        {
            bool flag = false;

            lock (SendLine)
            {
                if (SendAvailable)
                {
                    SendAvailable = false;
                    flag          = true;
                }
                else
                {
                    SendLine.Enqueue(buffer);
                }
            }

            if (flag)
            {
                Send(buffer);
            }
            return(IsAvailable);
        }
示例#9
0
        /// <summary>
        /// Saves work offset values for the selected work offset ie G54, G55, G56, G57, G58, G59
        /// </summary>
        /// <param name="selectedOffset"></param>
        private void saveWorkOffset(string selectedOffset)
        {
            string Xaxis = "0.000";
            string Yaxis = "0.000";
            string Zaxis = "0.000";

            // 1) Get Selected Offset ie G54-G59.
            // 2) Get values from the selected Offset Textboxes - X, Y, Z
            // 3) Send Command G10 L2 P1  X0.000, Y0.000, Z0.000 - G54=P1....G59=P6
            if (selectedOffset == "G54")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G54X.Text = Xaxis;
                G54Y.Text = Yaxis;
                G54Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P1 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else if (selectedOffset == "G55")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G55X.Text = Xaxis;
                G55Y.Text = Yaxis;
                G55Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P2 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else if (selectedOffset == "G56")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G56X.Text = Xaxis;
                G56Y.Text = Yaxis;
                G56Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P3 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else if (selectedOffset == "G57")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G57X.Text = Xaxis;
                G57Y.Text = Yaxis;
                G57Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P4 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else if (selectedOffset == "G58")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G58X.Text = Xaxis;
                G58Y.Text = Yaxis;
                G58Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P5 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else if (selectedOffset == "G59")
            {
                Xaxis = MachineX_Current.Text;
                Yaxis = MachineY_Current.Text;
                Zaxis = MachineZ_Current.Text;

                G59X.Text = Xaxis;
                G59Y.Text = Yaxis;
                G59Z.Text = Zaxis;

                SendLine.Invoke($"G10 L2 P6 X{Xaxis} Y{Yaxis} Z{Zaxis}");
            }
            else
            {
                return;
            }
        }
示例#10
0
        private void saveIndividualOffsetAxis(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            string newValue;

            TextBox b = sender as TextBox;

            if (b == null)
            {
                return;
            }

            switch (b.Tag as string)
            {
            // G10 L2 Px Axis+Value
            // G54 Axies
            case "G54X":
                newValue = G54X.Text;
                SendLine.Invoke($"G10 L2 P1 X{newValue}");
                break;

            case "G54Y":
                newValue = G54Y.Text;
                SendLine.Invoke($"G10 L2 P1 Y{newValue}");
                break;

            case "G54Z":
                newValue = G54Z.Text;
                SendLine.Invoke($"G10 L2 P1 Z{newValue}");
                break;

            // G55 Axies
            case "G55X":
                newValue = G55X.Text;
                SendLine.Invoke($"G10 L2 P2 X{newValue}");
                break;

            case "G55Y":
                newValue = G55Y.Text;
                SendLine.Invoke($"G10 L2 P2 Y{newValue}");
                break;

            case "G55Z":
                newValue = G55Z.Text;
                SendLine.Invoke($"G10 L2 P2 Z{newValue}");
                break;

            // G56 Axies
            case "G56X":
                newValue = G56X.Text;
                SendLine.Invoke($"G10 L2 P3 X{newValue}");
                break;

            case "G56Y":
                newValue = G56Y.Text;
                SendLine.Invoke($"G10 L2 P3 Y{newValue}");
                break;

            case "G56Z":
                newValue = G56Z.Text;
                SendLine.Invoke($"G10 L2 P3 Z{newValue}");
                break;

            // G57 Axies
            case "G57X":
                newValue = G57X.Text;
                SendLine.Invoke($"G10 L2 P4 X{newValue}");
                break;

            case "G57Y":
                newValue = G57Y.Text;
                SendLine.Invoke($"G10 L2 P4 Y{newValue}");
                break;

            case "G57Z":
                newValue = G57Z.Text;
                SendLine.Invoke($"G10 L2 P4 Z{newValue}");
                break;

            // G58 Axies
            case "G58X":
                newValue = G58X.Text;
                SendLine.Invoke($"G10 L2 P5 X{newValue}");
                break;

            case "G58Y":
                newValue = G58Y.Text;
                SendLine.Invoke($"G10 L2 P5 Y{newValue}");
                break;

            case "G58Z":
                newValue = G58Z.Text;
                SendLine.Invoke($"G10 L2 P5 Z{newValue}");
                break;

            // G59 Axies
            case "G59X":
                newValue = G59X.Text;
                SendLine.Invoke($"G10 L2 P6 X{newValue}");
                break;

            case "G59Y":
                newValue = G59Y.Text;
                SendLine.Invoke($"G10 L2 P6 Y{newValue}");
                break;

            case "G59Z":
                newValue = G59Z.Text;
                SendLine.Invoke($"G10 L2 P6 Z{newValue}");
                break;
            }
        }
示例#11
0
        private void CanvasAdd2()
        {
            Line Reav = new Line();
            Line ReavSYG;

            Line Send = new Line();
            Line SendSYG;

            if (ReadLine.Count == 0)
            {
                Reav.X1 = 0;
                Reav.Y1 = 10;
                if (R == 0)
                {
                    Reav.X2 = 5;
                    Reav.Y2 = 15;
                }
                else
                {
                    Reav.X2 = Reav.X1 + (R / 10);
                    Reav.Y2 = -(Reav.X2 + 10);
                }
            }
            else
            {
                ReavSYG = (Line)ReadLine[ReadLine.Count - 1];
                Reav.X1 = ReavSYG.X2;
                Reav.Y1 = ReavSYG.Y2;
                if (R == 0)
                {
                    Reav.X2 = ReavSYG.X1 + 5;
                    Reav.Y2 = Reav.X2 + 10;
                }
                else
                {
                    Reav.X2 = Reav.X1 + (R / 10);
                    Reav.Y2 = -(Reav.X2 + 10);
                }

                //调整线条位置
                if (Reav.X2 > 200)
                {
                    for (int i = 0; i < ReadLine.Count; i++)
                    {
                        Line u = ReadLine[i];
                        Canvas1.Children.Remove(u);
                    }
                    ReadLine.Clear();
                    return;
                }
            }


            if (SendLine.Count == 0)
            {
                Send.X1 = 0;
                Send.Y1 = 10;
                if (S == 0)
                {
                    Send.X2 = 5;  //长度
                    Send.Y2 = 15; //下降
                }
                else
                {
                    Send.X2 = Send.X1 + (S / 4); //长度
                    Send.Y2 = -(Send.X2 + 10);   //上升
                }
            }
            else
            {
                SendSYG = (Line)SendLine[SendLine.Count - 1];
                Send.X1 = SendSYG.X2;
                Send.Y1 = SendSYG.Y2;
                if (S == 0)
                {
                    Send.X2 = SendSYG.X1 + 5; //长度
                    Send.Y2 = Send.X2 + 10;   //下降
                }
                else
                {
                    Send.X2 = Send.X1 + (S / 4); //长度
                    Send.Y2 = -(Send.X2 + 10);   //上升
                }
                //调整线条位置
                if (Send.X2 > 200)
                {
                    for (int i = 0; i < SendLine.Count; i++)
                    {
                        Line u = SendLine[i];
                        Canvas1.Children.Remove(u);
                    }
                    SendLine.Clear();
                    return;
                }
            }


            BrushConverter ie    = new BrushConverter();
            Brush          brush = (Brush)ie.ConvertFromString("#DC143C");

            Send.Stroke          = brush;
            Send.StrokeThickness = 3;
            Canvas.SetTop(Send, 200);
            SendLine.Add(Send);

            brush                = (Brush)ie.ConvertFromString("#4682B4");
            Reav.Stroke          = brush;
            Reav.StrokeThickness = 3;
            Canvas.SetTop(Reav, 180);
            ReadLine.Add(Reav);

            Debug.WriteLine(ProcInfo.CpuTime);
            Canvas1.Children.Add(Reav);
            Canvas1.Children.Add(Send);
            //this.stakpanal1.Children.Add(element);
        }