Selaa lähdekoodia

정기 업데이트

SK.Kang 6 vuotta sitten
vanhempi
commit
07194c4fed

+ 8 - 0
Dev/OHV/OHV.Common/Events/MessageEventArgs.cs

@@ -9,10 +9,14 @@ namespace OHV.Common.Events
 {
     public class GUIMessageEventArgs : EventArgs
     {
+        /// <summary>
+        /// To GUI
+        /// </summary>
         public enum eGUIMessageKind
         {
             RspIOObject,
             RspIOMapList,
+            RspJog,
         }
 
         public eGUIMessageKind Kind { get; set; }
@@ -29,12 +33,16 @@ namespace OHV.Common.Events
         }
     }
 
+    /// <summary>
+    /// To Background
+    /// </summary>
     public class VCSMessageEventArgs : EventArgs
     {
         public enum eVCSMessageKind
         {
             ReqIOObject,
             ReqIOMapList,
+            ReqJog,
         }
 
         public eVCSMessageKind Kind { get; set; }

+ 2 - 3
Dev/OHV/OHV.Common/Model/Alarm.cs

@@ -11,9 +11,8 @@ namespace OHV.Common.Model
 {
     public class Alarm
     {
-        [Index("AlarmID")]
-        [Autoincrement]
-        public int Id { get; set; }
+        [Index]
+        public int AlarmId { get; set; }
 
         public string Name { get; set; }
         public string Text { get; set; }

+ 27 - 0
Dev/OHV/OHV.Common/Model/HisAlarm.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OHV.Common.Model
+{
+    public class HisAlarm
+    {
+        public string id { get; set; }
+        public string Text { get; set; }
+        public DateTime OccurTime { get; set; }
+        public string Solution { get; set; }
+
+        public int? AlarmId { get; set; }
+
+        public virtual Alarm Alarm { get; set; }
+
+        public HisAlarm()
+        {
+            this.id = $"{Guid.NewGuid()}_{DateTime.Now.ToString("HHmmssfff")}";
+            this.OccurTime = DateTime.Now;
+        }
+    }
+}

+ 1 - 0
Dev/OHV/OHV.Common/OHV.Common.csproj

@@ -71,6 +71,7 @@
     <Compile Include="Model\AxisVelocityData.cs" />
     <Compile Include="Model\Command.cs" />
     <Compile Include="Model\Config.cs" />
+    <Compile Include="Model\HisAlarm.cs" />
     <Compile Include="Model\Route.cs" />
     <Compile Include="Model\SelectionItem.cs" />
     <Compile Include="Model\SelectionList.cs" />

+ 17 - 0
Dev/OHV/OHV.SqliteDAL/DAL/AbstractDAL.cs

@@ -52,6 +52,14 @@ namespace OHV.SqliteDAL.DAL
             }
         }
 
+        public List<T> ListN(Expression<Func<T, bool>> where)
+        {
+            using (var db = new OHVDbContext("OHVDb"))
+            {
+                return db.Set<T>().Where(where).ToList();
+            }
+        }
+
         public void Add(T entity)
         {
             using (var db = new OHVDbContext("OHVDb"))
@@ -70,6 +78,15 @@ namespace OHV.SqliteDAL.DAL
             }
         }
 
+        public virtual void Update(T entity)
+        {
+            using (var db = new OHVDbContext("OHVDb"))
+            {
+                db.Entry(entity).State = EntityState.Modified;
+                db.SaveChanges();
+            }
+        }
+
         //protected int DeleteN(Expression<Func<T, bool>> where)
         //{
 

+ 1 - 3
Dev/OHV/OHV.SqliteDAL/DAL/AxisPositionDataDAL.cs

@@ -7,7 +7,7 @@ using OHV.Common.Model;
 
 namespace OHV.SqliteDAL.DAL
 {
-    public class AxisPositionDataDAL
+    public class AxisPositionDataDAL : GenericDAL<AxisPositionData>
     {
         public List<AxisPositionData> All
         {
@@ -48,8 +48,6 @@ namespace OHV.SqliteDAL.DAL
 
         public AxisPositionData GetK(string axisName, string position)
         {
-            AxisPositionData data = null;
-
             var list = this.GetKFromName(axisName);
 
             return list.Where(x => x.Name.Equals(position)).SingleOrDefault();

+ 35 - 0
Dev/OHV/OHV.SqliteDAL/DAL/HisAlarmDAL.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OHV.Common.Model;
+
+namespace OHV.SqliteDAL.DAL
+{
+    public class HisAlarmDAL : GenericDAL<HisAlarm>
+    {
+        public void Delete(int backupDay)
+        {
+            using (var db = new OHVDbContext("OHVDb"))
+            {
+                var backup = DateTime.Now.AddDays(-backupDay);
+                var delList = db.Set<HisAlarm>().Where(x => x.OccurTime < backup).ToList();
+                if (delList.Count > 0)
+                {
+                    db.Set<HisAlarm>().RemoveRange(delList);
+                    db.SaveChanges();
+                }
+            }
+        }
+
+        public List<HisAlarm> GetN(DateTime from, DateTime to)
+        {
+            using (var db = new OHVDbContext("OHVDb"))
+            {
+                return db.Set<HisAlarm>().Where(x => x.OccurTime >= from && x.OccurTime <= to).ToList();
+            }
+
+        }
+    }
+}

+ 1 - 0
Dev/OHV/OHV.SqliteDAL/ModelConfiguration.cs

@@ -20,6 +20,7 @@ namespace OHV.SqliteDAL
             modelBuilder.Entity<AxisVelocityData>();
             modelBuilder.Entity<AxisConfig>();
             modelBuilder.Entity<Alarm>();
+            modelBuilder.Entity<HisAlarm>();
         }
     }
 }

+ 1 - 0
Dev/OHV/OHV.SqliteDAL/OHV.SqliteDAL.csproj

@@ -81,6 +81,7 @@
     <Compile Include="DAL\AxisVelocityDataDAL.cs" />
     <Compile Include="DAL\CommandDAL.cs" />
     <Compile Include="DAL\ConfigDAL.cs" />
+    <Compile Include="DAL\HisAlarmDAL.cs" />
     <Compile Include="DAL\RouteDAL.cs" />
     <Compile Include="DAL\SubCmdDAL.cs" />
     <Compile Include="ModelConfiguration.cs" />

+ 4 - 0
Dev/OHV/OHV.SqliteDAL/OHVDbInitializer.cs

@@ -119,6 +119,10 @@ namespace OHV.SqliteDAL
                     Address = "100.100.100.21",
                 }
             });
+
+            context.Set<Alarm>().Add(new Alarm { AlarmId = 1, Kind = eAlarmKind.Axis, Name = "adfsdfds", Level = eAlarmLevel.Falut, });
+
+            context.Set<HisAlarm>().Add(new HisAlarm { AlarmId = 1, OccurTime = DateTime.Now.AddDays(-10) });
         }
     }
 }

+ 2 - 0
Dev/OHV/OHV.SqliteDAL/SqliteManager.cs

@@ -21,6 +21,7 @@ namespace OHV.SqliteDAL
         public AxisPositionDataDAL AxisPositionDataDAL { get; set; }
         public AxisVelocityDataDAL AxisVelocityDataDAL { get; set; }
         public AlarmDAL AlarmDAL { get; set; }
+        public HisAlarmDAL HisAlarmDAL { get; set; }
 
         public SqliteManager()
         {
@@ -32,6 +33,7 @@ namespace OHV.SqliteDAL
             this.AxisPositionDataDAL = new AxisPositionDataDAL();
             this.AxisVelocityDataDAL = new AxisVelocityDataDAL();
             this.AlarmDAL = new AlarmDAL();
+            this.HisAlarmDAL = new HisAlarmDAL();
         }
 
         public void RegisterTypes(IContainerRegistry containerRegistry)

+ 161 - 15
Dev/OHV/VehicleControlSystem/ControlLayer/Clamp.cs

@@ -3,9 +3,11 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using GSG.NET.LINQ;
 using OHV.Common.Shareds;
 using OHV.SqliteDAL;
 using VehicleControlSystem.ControlLayer.Axis;
+using VehicleControlSystem.ControlLayer.Lib.EziPlusE;
 
 namespace VehicleControlSystem.ControlLayer
 {
@@ -19,6 +21,11 @@ namespace VehicleControlSystem.ControlLayer
             this.sql = sqliteManager;
         }
 
+        public void Init()
+        {
+            this.CreateAxis();
+        }
+
         void CreateAxis()
         {
             sql.AxisConfigDAL.All.ForEach(config =>
@@ -53,32 +60,171 @@ namespace VehicleControlSystem.ControlLayer
             });
         }
 
-        bool CLAMP_OriginReturn()
+        public int LeftOriginReturn()
         {
-            this.axes.ForEach(a =>
-            {
-                a.OriginReturn(true);
-            });
+            var servo = this.axes.Where(s => s.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT)).Single();
+            return servo.OriginReturn(true);
+        }
 
-            return true;
+        public int RightOriginReturn()
+        {
+            var servo = this.axes.Where(s => s.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_RIGHT)).Single();
+            return servo.OriginReturn(true);
         }
 
-        bool CLAMP_Lock()
+        public int AllOriginReturn()
         {
-            this.axes.ForEach(a =>
-            {
-                var pData = sql.AxisPositionDataDAL.GetK(a.Config.AxisName, ConstString.TEACH_POSITION_LOCK);
-                a.StartMove(pData.Value, 0);
-            });
+            int result = 0;
+            result = LeftOriginReturn();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return 7;
 
-            this.axes.ForEach(a =>
+            result = RightOriginReturn();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return 8;
+
+            return result;
+        }
+
+        public int IsAllAxisOriginReturn()
+        {
+            int result = 0;
+            this.axes.ForEach(x =>
             {
-                a.Wait4Done();
+                if (!x.IsOriginReturn())
+                {
+                    if (x.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT))
+                        result = 5;
+                    else 
+                        result = 6;
+                    return;
+                }
             });
 
-            return true;
+            return result;
         }
 
+        #region Data
+        public void SavePositionData(string pos, double left, double right)
+        {
+            var dataList = sql.AxisPositionDataDAL.GetKFromPostion(pos);
+            var sqlLeft = dataList.Where(x => x.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT)).Single();
+            var sqlRight = dataList.Where(x => x.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_RIGHT)).Single();
+
+            sqlLeft.Value = left;
+            sql.AxisPositionDataDAL.Update(sqlLeft);
+
+            sqlRight.Value = right;
+            sql.AxisPositionDataDAL.Update(sqlRight);
+        }
+        #endregion
+
+        public int JogMove(string axisName, E_JogMoveDir dir, int velocity)
+        {
+            var axis = this.axes.Where(x => x.Config.AxisName.Equals(axisName)).Single();
+            return axis.JogMove(dir, velocity);
+        }
 
+        public int MoveToLockPosition(string axisName)
+        {
+            var servo = this.axes.Where(x => x.Config.AxisName.Equals(axisName)).Single();
+            var axisPositionDatas = sql.AxisPositionDataDAL.GetKFromName(axisName).ToList();
+            var data = axisPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_LOCK)).Single();
+
+            int result = servo.Move(data.Value);
+
+            return result;
+        }
+
+        public int MoveToUnlockPosition(string axisName)
+        {
+            var servo = this.axes.Where(x => x.Config.AxisName.Equals(axisName)).Single();
+            var axisPositionDatas = sql.AxisPositionDataDAL.GetKFromName(axisName).ToList();
+            var data = axisPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_UNLOCK)).Single();
+
+            int result = servo.Move(data.Value);
+
+            return result;
+        }
+
+        /// <summary>
+        /// 두개를 동시에 Lock
+        /// </summary>
+        /// <returns></returns>
+        public int Lock_Sync()
+        {
+            int result = 0;
+
+            result = this.AllOriginReturn();
+            if (result != 0)
+                return result;
+
+            var leftPositionDatas = sql.AxisPositionDataDAL.GetKFromName(ConstString.AXIS_CARRIER_LOCK_LEFT).ToList();
+            var leftData = leftPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_LOCK)).Single();
+            var left = this.axes.Where(x => x.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT)).Single();
+
+            var rightPositionDatas = sql.AxisPositionDataDAL.GetKFromName(ConstString.AXIS_CARRIER_LOCK_RIGHT).ToList();
+            var rightData = leftPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_LOCK)).Single();
+            var right = this.axes.Where(x => x.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_RIGHT)).Single();
+
+            result = left.StartMove(leftData.Value, 0);
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+            
+            result = right.StartMove(rightData.Value, 0);
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+            result = left.Wait4Done();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+            result = right.Wait4Done();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+
+            return EziMOTIONPlusELib.FMM_OK;
+        }
+
+        /// <summary>
+        /// 두개의 Axis 를 동시에 Unlock
+        /// </summary>
+        /// <returns></returns>
+        public int Unlock_Sync()
+        {
+            int result = 0;
+
+            result = this.AllOriginReturn();
+            if (result != 0)
+                return result;
+
+            var leftPositionDatas = sql.AxisPositionDataDAL.GetKFromName(ConstString.AXIS_CARRIER_LOCK_LEFT).ToList();
+            var leftData = leftPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_UNLOCK)).Single();
+            var left = this.axes.Where(x => x.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT)).Single();
+
+            var rightPositionDatas = sql.AxisPositionDataDAL.GetKFromName(ConstString.AXIS_CARRIER_LOCK_RIGHT).ToList();
+            var rightData = leftPositionDatas.Where(x => x.Name.Equals(ConstString.TEACH_POSITION_UNLOCK)).Single();
+            var right = this.axes.Where(x => x.Config.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_RIGHT)).Single();
+
+            result = left.StartMove(leftData.Value, 0);
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+            result = right.StartMove(rightData.Value, 0);
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+            result = left.Wait4Done();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+            result = right.Wait4Done();
+            if (result != EziMOTIONPlusELib.FMM_OK)
+                return result;
+
+
+            return EziMOTIONPlusELib.FMM_OK;
+        }
     }
 }

+ 92 - 0
Dev/OHV/VehicleControlSystem/ControlLayer/Conveyor.cs

@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using GSG.NET.Utils;
+using VehicleControlSystem.ControlLayer.IO;
+
+namespace VehicleControlSystem.ControlLayer
+{
+    public class Conveyor
+    {
+        IIO iO = null;
+        public Conveyor(IIO io)
+        {
+            this.iO = io;
+        }
+
+        void OnOffConveyor(bool isOn, bool isCW)
+        {
+            if (isCW)
+                this.iO.OutputOn("OUT_Conveyor_CWCCW");
+            else
+                this.iO.OutputOff("OUT_Conveyor_CWCCW");
+
+            if (isOn)
+                this.iO.OutputOn("OUT_Conveyor_Run");
+            else
+                this.iO.OutputOff("OUT_Conveyor_Run");
+        }
+
+        bool IsDetectedCarrier() => this.iO.IsOn("IN_Carrier_Detect");
+
+        int Load_Carrier()
+        {
+            if (IsDetectedCarrier())
+                return 9;
+
+            OnOffConveyor(true, true);
+
+            long sTime = SwUtils.CurrentTimeMillis;
+            while (true)
+            {
+                if (SwUtils.Gt(sTime, 20 * ConstUtils.ONE_SECOND)) //Wait 20Sec
+                {
+                    OnOffConveyor(false, true);
+                    return 10;
+                }
+
+                if (IsDetectedCarrier())
+                    break;
+            }
+
+            return 0;
+        }
+
+        int UnloadCarrier()
+        {
+            if (!IsDetectedCarrier())
+                return 11;
+
+            OnOffConveyor(true, true);
+
+            long sTime = SwUtils.CurrentTimeMillis;
+            while (true)
+            {
+                if (SwUtils.Gt(sTime, 20 * ConstUtils.ONE_SECOND)) //Wait 20Sec
+                {
+                    OnOffConveyor(false, true);
+                    return 12;
+                }
+
+                if (!IsDetectedCarrier())
+                    break;
+            }
+
+            return 0;
+        }
+
+        public int PIOAndLoad()
+        {
+
+            return 0;
+        }
+
+        public int PIOAndUnload()
+        {
+            return 0;
+        }
+
+    }
+}

+ 16 - 1
Dev/OHV/VehicleControlSystem/ControlLayer/Vehicle.cs

@@ -55,6 +55,8 @@ namespace VehicleControlSystem.ControlLayer
         IIO iO = null;
         GSIMotion motion = null;
         SqliteManager sql = null;
+        Clamp clamp = null;
+        Conveyor conveyor = null;
 
         #region List.
         List<ICylinder> cylinders = new List<ICylinder>();
@@ -91,7 +93,9 @@ namespace VehicleControlSystem.ControlLayer
 
         public void Init()
         {
-            var a = sql.AlarmDAL.GetK(1);
+            this.CreateClamp();
+            this.CreateConveyor();
+
             ThreadStart();
         }
 
@@ -356,6 +360,17 @@ namespace VehicleControlSystem.ControlLayer
                 this.cylinders.Add(new Cylinder(cylinder, this.iO));
             });
         }
+
+        void CreateClamp()
+        {
+            this.clamp = new Clamp(this.sql);
+            this.clamp.Init();
+        }
+
+        void CreateConveyor()
+        {
+            this.conveyor = new Conveyor(this.iO);
+        }
         #endregion
 
         #region Help Method

+ 1 - 1
Dev/OHV/VehicleControlSystem/Managers/AutoManager.cs

@@ -97,7 +97,7 @@ namespace VehicleControlSystem.Managers
             }
         }
 
-        public void ProcessAlarm()
+        public void ProcessAlarm(int alarmID)
         {
             
         }

+ 9 - 0
Dev/OHV/VehicleControlSystem/VCSystem.cs

@@ -6,6 +6,7 @@ using System.Text;
 using System.Threading.Tasks;
 using GSG.NET;
 using GSG.NET.ObjectBase;
+using GSG.NET.Quartz;
 using OHV.Common.Events;
 using OHV.Common.Model;
 using OHV.SqliteDAL;
@@ -43,6 +44,9 @@ namespace VehicleControlSystem
 
         public void Init()
         {
+            QuartzUtils.Init(5);
+            QuartzUtils.Invoke("HIS_ALARM", QuartzUtils.GetExpnMinute(1), this.CleanHisAlarm);
+            
             //Create IO
             this.IO = new EzIO();
             var mapPath = Path.Combine(System.Environment.CurrentDirectory) + @"\Config\IO.xlsx";
@@ -67,6 +71,11 @@ namespace VehicleControlSystem
             this.hostManager.Init();
         }
 
+        public void CleanHisAlarm()
+        {
+            sql.HisAlarmDAL.Delete(20);
+        }
+
         #region EzIO Event
         private void EzIO_OnChangedIO(BitBlock bit)
         {

+ 5 - 0
Dev/OHV/VehicleControlSystem/VehicleControlSystem.csproj

@@ -57,6 +57,10 @@
     <Reference Include="Prism.Wpf, Version=7.2.0.1422, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
       <HintPath>..\packages\Prism.Wpf.7.2.0.1422\lib\net45\Prism.Wpf.dll</HintPath>
     </Reference>
+    <Reference Include="Quartz, Version=1.0.3.2, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Assambly\Quartz.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
@@ -86,6 +90,7 @@
     <Compile Include="ControlLayer\Axis\EzAxis.cs" />
     <Compile Include="ControlLayer\Axis\IAxis.cs" />
     <Compile Include="ControlLayer\Clamp.cs" />
+    <Compile Include="ControlLayer\Conveyor.cs" />
     <Compile Include="ControlLayer\IO\BitBlock.cs" />
     <Compile Include="ControlLayer\IO\Delegates.cs" />
     <Compile Include="ControlLayer\IO\EzBoard.cs" />