孝锋 徐 há 8 meses atrás
pai
commit
1a53da63ca
1 ficheiros alterados com 176 adições e 7 exclusões
  1. 176 7
      TeamAAS-VM/Core/Management.cs

+ 176 - 7
TeamAAS-VM/Core/Management.cs

@@ -369,7 +369,7 @@ namespace TeamAAS_VP.Core
             {
                 try
                 {
-                    var lishtCtr= await _lightManagerService.RegisterControllerAsync(item.Id, item);
+                    var lishtCtr = await _lightManagerService.RegisterControllerAsync(item.Id, item);
                     //var lightcontroller = _cameraService.GetLightController(item.Id);
                     //await lightcontroller.ConnectAsync();     //连接光源控制器
                     //SendTaskMessage($"{item.LightControllerName}{Lang.已连接}!", MessageLevel.Debug);
@@ -380,9 +380,9 @@ namespace TeamAAS_VP.Core
                     //SendTaskMessage($"{item.LightControllerName}{Lang.断开连接}!", MessageLevel.Alarm);
                 }
             }
-            if (lightcontrollers.Count>0)
+            if (lightcontrollers.Count > 0)
             {
-                var result=await _lightManagerService.ConnectAllAsync();
+                var result = await _lightManagerService.ConnectAllAsync();
                 if (result)
                 {
                     return (true, "");
@@ -841,9 +841,9 @@ namespace TeamAAS_VP.Core
         public async Task WriteSystemParameterToPlcAsync(SystemConfiguration systemConfiguration)
         {
             var addressConfig = _configService.GetPlcAddresses();
-            var plc=_plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
-            if (plc == null) return;
-            Dictionary<string,object> nodeValues = new Dictionary<string, object>();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
+            Dictionary<string, object> nodeValues = new Dictionary<string, object>();
             nodeValues.Add(addressConfig.Out_WorkMode.Address, (Int16)systemConfiguration.WorkMode);
             nodeValues.Add(addressConfig.Out_PickPointNum.Address, (Int16)systemConfiguration.PickPointNum);
             nodeValues.Add(addressConfig.Out_DowmCameraNum.Address, (Int16)systemConfiguration.DowmCameraNum);
@@ -854,7 +854,176 @@ namespace TeamAAS_VP.Core
             nodeValues.Add(addressConfig.Out_FixedCameraPutNum.Address, (Int16)systemConfiguration.FixedCameraPutNum);
             nodeValues.Add(addressConfig.Out_FixedCameracheckNum.Address, (Int16)systemConfiguration.FixedCameracheckNum);
 
-            var res= await plc.WriteNodesAsync(nodeValues);
+            var res = await plc.WriteNodesAsync(nodeValues);
+        }
+
+        //注册需要监控的PLC地址
+        public void RegisterPlcMonitorAddress()
+        {
+            var addressConfig = _configService.GetPlcAddresses();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
+
+            //PLC地址数组
+            List<string> monitorNodeIds = new List<string>()
+            {
+                addressConfig.In_DowmCameraExe.Address,
+                addressConfig.In_UpCameraPickExe.Address,
+                addressConfig.In_UpCameraPutExe.Address,
+                addressConfig.In_UPCameracheckExe.Address,
+                addressConfig.In_FixedCameraPickExe.Address,
+                addressConfig.In_FixedCameraPutExe.Address,
+                addressConfig.In_FixedCameracheckExe.Address,
+                addressConfig.In_WorkStart.Address,
+                addressConfig.In_WorkDone.Address,
+            };
+
+            //订阅PLC地址变化
+            plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger);
+        }
+
+        /// <summary>
+        /// PLC命令触发时
+        /// </summary>
+        /// <param name="tuple"></param>
+        private void PlcCommandTrigger((string key, string nodeId, object value) tuple)
+        {
+            var addressConfig = _configService.GetPlcAddresses();
+            // 触发下相机拍照
+            if (tuple.nodeId.Contains(addressConfig.In_DowmCameraExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 触发上相机取料拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_UpCameraPickExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 上相机锁附/组装拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_UpCameraPutExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 上相机检测拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_UPCameracheckExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 固定相机取料拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_FixedCameraPickExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 固定相机锁附/组装拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_FixedCameraPutExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 固定相机检测拍照
+            else if (tuple.nodeId.Contains(addressConfig.In_FixedCameracheckExe.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 开始锁付
+            else if (tuple.nodeId.Contains(addressConfig.In_WorkStart.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
+            // 停止锁付
+            else if (tuple.nodeId.Contains(addressConfig.In_WorkDone.Address))
+            {
+                if (tuple.value is bool state)
+                {
+                    if (state)
+                    {
+
+                    }
+                    else
+                    {
+
+                    }
+                }
+            }
         }
 
         #endregion