Parcourir la source

完善开料分拣异常信息提示

陈子杰 il y a 3 mois
Parent
commit
1fa25b3692

+ 32 - 108
SCADA_DAQ/Customer/Machines/SortMachine.cs

@@ -187,15 +187,31 @@ namespace SCADA_DAQ.Customer.Machines
                 //Labels = new ObservableCollection<LabelModel>(_Lbls);
                 var errorCount = 0;
                 var end = false;
-
+                if (BaseDevice.Simulated)
+                {
+                    end = true;
+                    _Lbls = GetLabes(File.FilePath);
+                    Labels = new ObservableCollection<LabelModel>(_Lbls);
+                }
                 while (!end)
                 {
                     if (CuttingMac.isConnected())
                     {
                         var ncName = new int[40];
                         CuttingMac.READ_plc_register(7200, 7240, out ncName);
-                        _Lbls = GetLabes(CycFilePath(ncName));
-                        Labels = new ObservableCollection<LabelModel>(_Lbls);
+                        var path = CycFilePath(ncName);
+                        if (path != null)
+                        {
+                            _Lbls = GetLabes(path);
+                            Labels = new ObservableCollection<LabelModel>(_Lbls);
+                        }
+                        else
+                        {
+                            
+                            MessageBox.Show($"文件不存在");
+                            GetListenReg(Tag_Reset).SetBit();
+
+                        }
                         end = true;
                     }
                     else
@@ -352,10 +368,11 @@ namespace SCADA_DAQ.Customer.Machines
                 reg.ResetBit();
             }
             else if (reg.Comment.Variable == Tag_CameraMoveOK && reg.Value == 1 && reg.OldValue == 0)
-            {
+            { 
                 //var _lbl = new LabelModel() { ID = CurrentLabel.ID };
                 var _lbl = new LabelModel();
                 var isCancel = false;
+                GetListenReg(Tag_AAutoSpeed).WriteReg(CustomerEnv.SortingMacConfigValue.AxisAAutoHighSpeed);
                 if (GetListenReg(Tag_CameraEnable).Value == 0)
                 {
                     _barcodeReader = MachineServer.GetInstance().GetMachine<SampleBarcodeReader>("BarcodeReader4");
@@ -415,113 +432,12 @@ namespace SCADA_DAQ.Customer.Machines
                 {
                     _lbl.ID = CurrentLabel.ID;
                 }
-
-                //var centerX = (double)CurrentLabel.CenterX + (double)CurrentLabel.ActualWidth / 2;
-                //var centerY = (double)CurrentLabel.CenterY + (double)CurrentLabel.ActualLength / 2;
-
-                //var cupCenter = new Point((double)CurrentLabel.X, (double)CurrentLabel.Y);
-                //var cupCenter = new Point(CenterX, CenterY);
-                //var cup1Center = new Point(-140, -155);
-                //var cup3Center = new Point(135, -155);
-                //var BoardInfo.RelaeaseY = 0m;
                 if (!isCancel)
                 {
                     if (_lbl.ID == CurrentLabel.ID)
                     {
                         Log.Info($"开始处理,{CurrentLabel.ID}");
-                        //var cupIndex = 0;
-                        //var rotation = 0m;
-                        //if ((CurrentLabel.ActualLength > 550 && CurrentLabel.ActualWidth > 200) ||
-                        //    (CurrentLabel.ActualWidth > 550 && CurrentLabel.ActualLength > 200)
-                        //    )
-                        //{
-                        //    cupIndex = 2;
-                        //    if (CurrentLabel.ActualWidth > CurrentLabel.ActualLength)
-                        //    {
-                        //        rotation = -90;
-                        //        releaseY = CurrentLabel.ActualLength / 2 - 150;
-                        //        //releaseY = CurrentLabel.ActualLength / 2 - 140;
-
-                        //    }
-                        //    else
-                        //    {
-                        //        releaseY = CurrentLabel.ActualWidth / 2 - 150;
-                        //        //releaseY = CurrentLabel.ActualWidth / 2 - 140;
-
-                        //    }
-
-                        //}
-                        //else
-                        //{
-                        //    if ((CenterX > 600 && CurrentLabel.ActualLength > CurrentLabel.ActualWidth) ||   //靠近X轴且横着
-                        //        (CenterX <= 600 && CurrentLabel.ActualLength < CurrentLabel.ActualWidth))
-                        //    {
-                        //        cupIndex = 3;
-                        //    }
-                        //    else
-                        //    {
-                        //        cupIndex = 1;
-                        //    }
-
-                        //    if (cupIndex == 1)
-                        //    {
-                        //        if (CenterX <= 600)
-                        //        {
-                        //            if (CurrentLabel.ActualLength >= CurrentLabel.ActualWidth)
-                        //            {
-                        //                var cup1NewCenter = new Point(cup1Center.X, cup1Center.Y);  //旋转后的坐标
-                        //                cupCenter = new Point(cupCenter.X - cup1NewCenter.X, cupCenter.Y - cup1NewCenter.Y);
-                        //                releaseY = CurrentLabel.ActualWidth / 2 - 180;
-                        //                //releaseY = CurrentLabel.ActualWidth / 2 - 170;
-
-                        //            }
-                        //        }
-                        //        else
-                        //        {
-                        //            rotation = -90;
-                        //            var cup3NewCenter = new Point(-1 * cup1Center.Y, (double)cup1Center.X);  //旋转后的坐标
-                        //                                                                                     //cup3NewCenter.Offset(100, 32.5);   //补偿夹具尺寸
-                        //            cupCenter = new Point(cupCenter.X - cup3NewCenter.X, cupCenter.Y - cup3NewCenter.Y);
-                        //            //releaseY = CurrentLabel.ActualWidth / 2;
-                        //            releaseY = CurrentLabel.ActualWidth / 2 - 30;
-                        //            //releaseY = CurrentLabel.ActualWidth / 2 - 20;
-
-
-                        //        }
-                        //    }
-                        //    else if (cupIndex == 3)
-                        //    {
-
-                        //        if (CenterX <= 600)
-                        //        {
-                        //            if (CurrentLabel.ActualLength < CurrentLabel.ActualWidth)
-                        //            {
-                        //                rotation = 90;
-                        //                var cup3NewCenter = new Point(cup3Center.Y, -1 * (double)cup3Center.X);  //旋转后的坐标
-                        //                cupCenter = new Point(cupCenter.X - cup3NewCenter.X, cupCenter.Y - cup3NewCenter.Y);
-                        //            }
-                        //            //releaseY = CurrentLabel.ActualWidth / 2;
-                        //            releaseY = CurrentLabel.ActualWidth / 2 - 30;
-                        //            //releaseY = CurrentLabel.ActualWidth / 2 - 20;
-
-
-                        //        }
-                        //        else
-                        //        {
-                        //            var cup3NewCenter = new Point(cup3Center.X, (double)cup3Center.Y);  //旋转后的坐标
-                        //            cupCenter = new Point(cupCenter.X - cup3NewCenter.X, cupCenter.Y - cup3NewCenter.Y);
-                        //            //releaseY = CurrentLabel.ActualWidth / 2 + 500;
-                        //            releaseY = CurrentLabel.ActualWidth / 2 - 30;
-                        //            //releaseY = CurrentLabel.ActualWidth / 2 - 20;
-
-                        //        }
-                        //    }
-                        //    else
-                        //    {
-                        //        //releaseY = CurrentLabel.ActualWidth / 2;
-                        //    }
-
-                        //}
+                        
                         var rotation = BoardInfo.Rotation;
                         var releaseRotation = rotation == -90 ? -90 : 90;
                         var releaseXOffset = 0f;
@@ -535,9 +451,17 @@ namespace SCADA_DAQ.Customer.Machines
 
                         var moveX = (float)((double)_lbl.X + BoardInfo.CupCenter.X);
                         moveX = moveX > originXOffset ? moveX - originXOffset : 0;
-                        var moveY = (float)((double)_lbl.Y + BoardInfo.CupCenter.Y);
+                        var moveY = (float)((double)_lbl.Y + BoardInfo.CupCenter.Y);                       
                         if (moveX < GetListenReg(Tag_XMaxLimitPos).ScaleValue && moveY < 2800)
                         {
+                            if (Math.Max(CurrentLabel.ActualLength, CurrentLabel.ActualWidth) >= 1500)
+                            {
+                                GetListenReg(Tag_AAutoSpeed).WriteReg(CustomerEnv.SortingMacConfigValue.AxisAAutoLowSpeed);
+                            }
+                            if (Math.Max(CurrentLabel.ActualLength, CurrentLabel.ActualWidth) >= 2400)
+                            {
+                                releaseXOffset -= 200;
+                            }
                             GetListenReg(Tag_CaptureX).WriteObject(null,
                             moveX,  //D1512
                             moveY,  //D1514
@@ -549,7 +473,7 @@ namespace SCADA_DAQ.Customer.Machines
                             (float)BoardInfo.ReleaseY,  // D1524 放板位置Y
                             (float)releaseRotation          //放板角度
                             );
-
+                            
                             CupMove?.Invoke(this, new CupMoveEventArgs() { X = (double)_lbl.X + BoardInfo.CupCenter.X, Y = (double)_lbl.Y + BoardInfo.CupCenter.Y, R = (double)rotation, CupIndex = BoardInfo.CupIndex });
 
                             Log.Info($"正在分拣:{CurrentLabel.ID},X:{moveX},Y:{moveY},角度:{rotation},吸盘:{BoardInfo.CupIndex}");

+ 41 - 0
SCADA_DAQ/Customer/Models/SortingModel/SortingMacSettingModel.cs

@@ -90,6 +90,45 @@ namespace SCADA_DAQ.Customer.Models.SortingModel
         }
         private string _CycFolder;
 
+        /// <summary>
+        /// 旋转轴自动高速
+        /// </summary>
+        /// 
+        [AutoViewProperty("旋转轴自动高速", Icon = "Speedometer")]
+        public int AxisAAutoHighSpeed
+        {
+            get { return _AxisAAutoHighSpeed; }
+            set
+            {
+                if (value != _AxisAAutoHighSpeed)
+                {
+                    _AxisAAutoHighSpeed = value;
+                    OnPropertyChanged(nameof(AxisAAutoHighSpeed));
+                }
+            }
+        }
+        private int _AxisAAutoHighSpeed;
+
+
+        /// <summary>
+        /// 旋转轴自动低速
+        /// </summary>
+        /// 
+        [AutoViewProperty("旋转轴自动低速", Icon = "SpeedometerSlow")]
+        public int AxisAAutoLowSpeed
+        {
+            get { return _AxisAAutoLowSpeed; }
+            set
+            {
+                if (value != _AxisAAutoLowSpeed)
+                {
+                    _AxisAAutoLowSpeed = value;
+                    OnPropertyChanged(nameof(AxisAAutoLowSpeed));
+                }
+            }
+        }
+        private int _AxisAAutoLowSpeed;
+
 
         /// <summary>
         /// 吸盘1坐标偏移
@@ -179,5 +218,7 @@ namespace SCADA_DAQ.Customer.Models.SortingModel
         private decimal _Y;
 
 
+       
+
     }
 }

+ 35 - 25
SCADA_DAQ/Customer/Views/Menu/UctFrmSorting/UctFrmSortingMain.xaml.cs

@@ -7,6 +7,7 @@ using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Views.Uct;
 using SCADA_DAQ.Plugin.Machine;
 using System;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -68,7 +69,7 @@ namespace SCADA_DAQ.Customer.Views.Menu.UctFrmSorting
                 SortMachine.Tag_YAutoSpeed,
                 SortMachine.Tag_ZAutoSpeed,
                 SortMachine.Tag_Y1AutoSpeed,
-                SortMachine.Tag_AAutoSpeed,
+                //SortMachine.Tag_AAutoSpeed,
             };
             for (int i = 0; i < autoSetting.Length; i++)
             {
@@ -209,41 +210,50 @@ namespace SCADA_DAQ.Customer.Views.Menu.UctFrmSorting
         {
             if (plc.BaseDevice.Simulated)
             {
-                Btn_Sim.IsEnabled = false;
-                if (string.IsNullOrEmpty(plc.File.FilePath))
-                {
-                    MessageBox.Show(Application.Current.MainWindow, "没有选择有效的NC文件");
-                    return;
-                }
-                Task.Run(async () =>
+                ShowChildWindow(new AutoView(plc.File), "选择模拟的加工文件", () =>
                 {
+                    Dispatcher.Invoke(() =>
+                    {
+                        Btn_Sim.IsEnabled = false;
 
-                    plc.GetListenReg(SortMachine.Tag_SortFinish).ResetBit();
-                    plc.GetListenReg(SortMachine.Tag_StartSort).SetBit();
-                    await Task.Delay(1000);
-                    plc.GetListenReg(SortMachine.Tag_StartSort).ResetBit();
+                    });
+                    //plc.Labels = new ObservableCollection<LabelModel>(plc.GetLabes(plc.File.FilePath));
+                    Task.Run(async () =>
+                    {
+                        plc.GetListenReg(SortMachine.Tag_SortFinish).ResetBit();
+                        plc.GetListenReg(SortMachine.Tag_StartSort).SetBit();
+                        await Task.Delay(1000);
+                        plc.GetListenReg(SortMachine.Tag_StartSort).ResetBit();
 
 
-                    while (plc.GetListenReg(SortMachine.Tag_SortFinish).Value == 0)
-                    {
-                        await Task.Delay(500);
-                        plc.GetListenReg(SortMachine.Tag_RequestNext).ResetBit();
-                        plc.GetListenReg(SortMachine.Tag_RequestNext).SetBit();
+                        while (plc.GetListenReg(SortMachine.Tag_SortFinish).Value == 0)
+                        {
+                            await Task.Delay(500);
+                            plc.GetListenReg(SortMachine.Tag_RequestNext).ResetBit();
+                            plc.GetListenReg(SortMachine.Tag_RequestNext).SetBit();
 
 
-                        await Task.Delay(500);
-                        plc.GetListenReg(SortMachine.Tag_CameraMoveOK).ResetBit();
-                        plc.GetListenReg(SortMachine.Tag_CameraMoveOK).SetBit();
+                            await Task.Delay(500);
+                            plc.GetListenReg(SortMachine.Tag_CameraMoveOK).ResetBit();
+                            plc.GetListenReg(SortMachine.Tag_CameraMoveOK).SetBit();
 
 
-                        await Task.Delay(3000);
-                    }
+                            await Task.Delay(3000);
+                        }
 
-                    Dispatcher.Invoke(() =>
-                    {
-                        Btn_Sim.IsEnabled = true;
+                        Dispatcher.Invoke(() =>
+                        {
+                            Btn_Sim.IsEnabled = true;
+                        });
                     });
+
+                    return true;
                 });
+                //if (string.IsNullOrEmpty(plc.File.FilePath))
+                //{
+                //    MessageBox.Show(Application.Current.MainWindow, "没有选择有效的NC文件");
+                //    return;
+                //}
             }
             else
             {