徐孝锋 há 8 meses atrás
pai
commit
b026502e44

+ 13 - 12
TeamAAS-VM/Core/Management.cs

@@ -290,7 +290,7 @@ namespace TeamAAS_VP.Core
                     SendTaskMessage($"{item.Name}{Lang.断开连接}!", MessageLevel.Alarm);
                 }
             }
-            //await WriteSystemParameterToPlcAsync(_configService.GetSystemConfiguration());
+            await WriteSystemParameterToPlcAsync(_configService.GetSystemConfiguration());
             if (sb.Length == 0)
             {
                 return (true, "");
@@ -842,18 +842,19 @@ namespace TeamAAS_VP.Core
         {
             var addressConfig = _configService.GetPlcAddresses();
             var plc=_plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null) return;
             Dictionary<string,object> nodeValues = new Dictionary<string, object>();
-            nodeValues.Add(addressConfig.WorkMode.Address, systemConfiguration.WorkMode);
-            nodeValues.Add(addressConfig.PickPointNum.Address, systemConfiguration.PickPointNum);
-            nodeValues.Add(addressConfig.CameraShotCount.Address, systemConfiguration.CameraShotCount);
-            nodeValues.Add(addressConfig.UpperCameraPickShotCount.Address, systemConfiguration.UpperCameraPickShotCount);
-            nodeValues.Add(addressConfig.UpperCameraPlaceShotCount.Address, systemConfiguration.UpperCameraPlaceShotCount);
-            nodeValues.Add(addressConfig.UpperCameraLockAssembleCount.Address, systemConfiguration.UpperCameraLockAssembleCount);
-            nodeValues.Add(addressConfig.PickFixedPositionProductCameraCount.Address, systemConfiguration.PickFixedPositionProductCameraCount);
-            nodeValues.Add(addressConfig.LockFixedPositionProductCameraCount.Address, systemConfiguration.LockFixedPositionProductCameraCount);
-            nodeValues.Add(addressConfig.FixedCameraDetectLockAssembleCount.Address, systemConfiguration.FixedCameraDetectLockAssembleCount);
-
-            await plc.WriteNodesAsync(nodeValues);
+            nodeValues.Add(addressConfig.WorkMode.Address, (Int16)systemConfiguration.WorkMode);
+            nodeValues.Add(addressConfig.PickPointNum.Address, (Int16)systemConfiguration.PickPointNum);
+            nodeValues.Add(addressConfig.CameraShotCount.Address, (Int16)systemConfiguration.CameraShotCount);
+            nodeValues.Add(addressConfig.UpperCameraPickShotCount.Address, (Int16)systemConfiguration.UpperCameraPickShotCount);
+            nodeValues.Add(addressConfig.UpperCameraPlaceShotCount.Address, (Int16)systemConfiguration.UpperCameraPlaceShotCount);
+            nodeValues.Add(addressConfig.UpperCameraLockAssembleCount.Address, (Int16)systemConfiguration.UpperCameraLockAssembleCount);
+            nodeValues.Add(addressConfig.PickFixedPositionProductCameraCount.Address, (Int16)systemConfiguration.PickFixedPositionProductCameraCount);
+            nodeValues.Add(addressConfig.LockFixedPositionProductCameraCount.Address, (Int16)systemConfiguration.LockFixedPositionProductCameraCount);
+            nodeValues.Add(addressConfig.FixedCameraDetectLockAssembleCount.Address, (Int16)systemConfiguration.FixedCameraDetectLockAssembleCount);
+
+            var res= await plc.WriteNodesAsync(nodeValues);
         }
 
         #endregion

+ 0 - 7
TeamAAS-VM/Models/PLC/PlcAddress.cs

@@ -8,13 +8,6 @@ namespace TeamAAS_VP.Models
     /// </summary>
     public class PlcAddress : BindableBase
     {
-
-        private int _PlcNo;
-        /// <summary>
-        /// PLC number used in system (int)
-        /// </summary>
-        public int PlcNo { get => _PlcNo; set => SetProperty(ref _PlcNo, value); }
-
         private string _Address;
         /// <summary>
         /// Address or node string used to access PLC (e.g. OP-UA node id or Modbus address)

+ 4 - 67
TeamAAS-VM/Services/PlcService.cs

@@ -223,74 +223,11 @@ namespace TeamAAS_VP.Services
                 {
                     var p = kvp.Value;
                     if (p == null) continue;
-
-                    object rawValue = null;
-                    var type = p.GetType();
-
-                    var prop = type.GetProperty("PlcNo") ?? type.GetProperty("Number") ?? type.GetProperty("No");
-                    if (prop != null)
+                    if (p.Index==number)
                     {
-                        try
-                        {
-                            rawValue = prop.GetValue(p);
-                        }
-                        catch
-                        {
-                            rawValue = null;
-                        }
-                    }
-
-                    if (rawValue == null)
-                    {
-                        var infoProp = type.GetProperty("PlcInfo") ?? type.GetProperty("Info");
-                        if (infoProp != null)
-                        {
-                            try
-                            {
-                                var infoObj = infoProp.GetValue(p);
-                                if (infoObj != null)
-                                {
-                                    var infoType = infoObj.GetType();
-                                    var numberProp = infoType.GetProperty("PlcNo") ?? infoType.GetProperty("PlcNumber") ?? infoType.GetProperty("Number") ?? infoType.GetProperty("No");
-                                    if (numberProp != null)
-                                    {
-                                        try
-                                        {
-                                            rawValue = numberProp.GetValue(infoObj);
-                                        }
-                                        catch
-                                        {
-                                            rawValue = null;
-                                        }
-                                    }
-                                }
-                            }
-                            catch
-                            {
-                                rawValue = null;
-                            }
-                        }
-                    }
-
-                    if (rawValue != null)
-                    {
-                        int parsed;
-                        try
-                        {
-                            if (rawValue is int) parsed = (int)rawValue;
-                            else parsed = Convert.ToInt32(rawValue);
-                        }
-                        catch
-                        {
-                            continue;
-                        }
-
-                        if (parsed == number)
-                        {
-                            id = kvp.Key;
-                            plc = p;
-                            return true;
-                        }
+                        id = kvp.Key;
+                        plc = kvp.Value;
+                        return true;
                     }
                 }
             }

+ 22 - 13
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -1168,6 +1168,8 @@ namespace TeamAAS_VP.ViewModels
             var sys = _configService.GetSystemConfiguration();
             if (sys != null)
             {
+                WorkMode = sys.WorkMode;
+                PickPointNum = sys.PickPointNum;
                 CameraShotCount = sys.CameraShotCount;
                 UpperCameraPickShotCount = sys.UpperCameraPickShotCount;
                 UpperCameraPlaceShotCount = sys.UpperCameraPlaceShotCount;
@@ -1278,19 +1280,26 @@ namespace TeamAAS_VP.ViewModels
             var result = await DialogHost.Show(view, "RootDialog", null, null, null);
             if (result != null && result is bool && (bool)result)
             {
-                var sysConfig = _configService.GetSystemConfiguration();
-                sysConfig.WorkMode = WorkMode;
-                sysConfig.PickPointNum = PickPointNum;
-                sysConfig.CameraShotCount = CameraShotCount;
-                sysConfig.UpperCameraPickShotCount = UpperCameraPickShotCount;
-                sysConfig.UpperCameraPlaceShotCount = UpperCameraPlaceShotCount;
-                sysConfig.UpperCameraLockAssembleCount = UpperCameraLockAssembleCount;
-                sysConfig.PickFixedPositionProductCameraCount = FixedPickCameraCount;
-                sysConfig.LockFixedPositionProductCameraCount = FixedLockAssembleCameraCount;
-                sysConfig.FixedCameraDetectLockAssembleCount = FixedCameraDetectLockAssembleCount;
-                _configService.SaveSystemConfiguration(sysConfig);
-                await management. WriteSystemParameterToPlcAsync(sysConfig);
-                _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
+                try
+                {
+                    var sysConfig = _configService.GetSystemConfiguration();
+                    sysConfig.WorkMode = WorkMode;
+                    sysConfig.PickPointNum = PickPointNum;
+                    sysConfig.CameraShotCount = CameraShotCount;
+                    sysConfig.UpperCameraPickShotCount = UpperCameraPickShotCount;
+                    sysConfig.UpperCameraPlaceShotCount = UpperCameraPlaceShotCount;
+                    sysConfig.UpperCameraLockAssembleCount = UpperCameraLockAssembleCount;
+                    sysConfig.PickFixedPositionProductCameraCount = FixedPickCameraCount;
+                    sysConfig.LockFixedPositionProductCameraCount = FixedLockAssembleCameraCount;
+                    sysConfig.FixedCameraDetectLockAssembleCount = FixedCameraDetectLockAssembleCount;
+                    _configService.SaveSystemConfiguration(sysConfig);
+                    await management.WriteSystemParameterToPlcAsync(sysConfig);
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
+                }
+                catch (Exception ex)
+                {
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg =ex.Message, Duration = 1 });
+                }
             }
         }
         #endregion