Forráskód Böngészése

重构PLC模型目录及构造函数完善

将PlcAddressConfig.cs迁移至Models/PLC目录,并同步更新项目文件及相关using引用。为PlcAddress和PlcPointAddress增加构造函数,提升初始化和健壮性。此次调整优化了PLC相关模型的结构和可维护性,未涉及业务逻辑变更。
孝锋 徐 8 hónapja
szülő
commit
1d58d88818

+ 1 - 0
TeamAAS-VM/Interfaces/IConfigService.cs

@@ -6,6 +6,7 @@ using TeamAAS_VP.Models;
 using TeamAAS_VP.Models.Calibration;
 using TeamAAS_VP.Models.Feeder;
 using TeamAAS_VP.Models.Lights;
+using TeamAAS_VP.Models.PLC;
 
 namespace TeamAAS_VP.Interfaces
 {

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

@@ -22,5 +22,19 @@ namespace TeamAAS_VP.Models
 
         private string _Description;
         public string Description { get => _Description; set => SetProperty(ref _Description, value); }
+
+        public PlcAddress()
+        {
+            Address = string.Empty;
+            DataType = "Float";
+            Description = "PLCµØÖ·";
+        }
+
+        public PlcAddress(string address, string dataType, string description)
+        {
+            Address = address;
+            DataType = dataType;
+            Description = description;
+        }
     }
 }

+ 124 - 1
TeamAAS-VM/Models/PlcAddressConfig.cs → TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

@@ -6,7 +6,7 @@ using System.Text;
 using System.Threading.Tasks;
 using TeamAAS_VP.Models.PLC;
 
-namespace TeamAAS_VP.Models
+namespace TeamAAS_VP.Models.PLC
 {
     public class PlcAddressConfig : BindableBase
     {
@@ -489,6 +489,13 @@ namespace TeamAAS_VP.Models
                 return a;
             }
 
+            // 辅助局部函数:确保 PlcPointAddress 实例存在
+            PlcPointAddress EnsurePoint(PlcPointAddress p)
+            {
+                if (p == null) return new PlcPointAddress();
+                return p;
+            }
+
             // 2. 按 JSON 提供的数据设置默认值(以当前属性名为准)
             Out_WorkMode = Ensure(Out_WorkMode);
             Out_WorkMode.Address = "ns=4;s=DB_Communication|FromPC.WorkMode";
@@ -535,6 +542,8 @@ namespace TeamAAS_VP.Models
             Out_FixedCameracheckNum.DataType = "int16";
             Out_FixedCameracheckNum.Description = "固定相机检测锁附/组装次数=0 无";
 
+            Out_PickCamera = EnsurePoint(Out_PickCamera);
+
             // 3. 为其余 Out_* 设置合理默认(基于注释)
             Out_WorkNum = Ensure(Out_WorkNum);
             Out_WorkNum.Address = "ns=4;s=DB_Communication|FromPC.WorkNum";
@@ -586,6 +595,120 @@ namespace TeamAAS_VP.Models
             Out_MesStatus.DataType = "int16";
             Out_MesStatus.Description = "过站信息 =1 允许工作 =2 本站放行 =3 数据上传完成";
 
+            // Out_PickCamera 初始化并赋地址
+            Out_PickCamera = EnsurePoint(Out_PickCamera);
+            Out_PickCamera.Description = "取料拍照点位参数";
+            Out_PickCamera.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.X_Position";
+            Out_PickCamera.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.X_Velocity";
+            Out_PickCamera.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Y_Position";
+            Out_PickCamera.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Y_Velocity";
+            Out_PickCamera.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Z_Position_Start";
+            Out_PickCamera.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Z_Velocity_Start";
+            Out_PickCamera.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Z_Position_Stop";
+            Out_PickCamera.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Z_Velocity_Stop";
+            Out_PickCamera.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.U_Position";
+            Out_PickCamera.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.U_Velocity";
+            Out_PickCamera.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.R_Position";
+            Out_PickCamera.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.R_Velocity";
+            Out_PickCamera.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Torque";
+            Out_PickCamera.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.Feeder";
+            Out_PickCamera.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_PickCamera{0}.ScrewProNum";
+
+            // Out_Pick(取料点位)初始化并赋地址
+            Out_Pick = EnsurePoint(Out_Pick);
+            Out_Pick.Description = "取料点位参数";
+            Out_Pick.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.X_Position";
+            Out_Pick.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.X_Velocity";
+            Out_Pick.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Y_Position";
+            Out_Pick.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Y_Velocity";
+            Out_Pick.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Z_Position_Start";
+            Out_Pick.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Z_Velocity_Start";
+            Out_Pick.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Z_Position_Stop";
+            Out_Pick.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Z_Velocity_Stop";
+            Out_Pick.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.U_Position";
+            Out_Pick.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.U_Velocity";
+            Out_Pick.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.R_Position";
+            Out_Pick.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.R_Velocity";
+            Out_Pick.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Torque";
+            Out_Pick.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.Feeder";
+            Out_Pick.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_Pick{0}.ScrewProNum";
+
+            // Out_SecPosCamera(下相机二次定位)初始化并赋地址
+            Out_SecPosCamera = EnsurePoint(Out_SecPosCamera);
+            Out_SecPosCamera.Description = "下相机二次定位点位参数";
+            Out_SecPosCamera.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.X_Position";
+            Out_SecPosCamera.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.X_Velocity";
+            Out_SecPosCamera.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Y_Position";
+            Out_SecPosCamera.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Y_Velocity";
+            Out_SecPosCamera.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Z_Position_Start";
+            Out_SecPosCamera.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Z_Velocity_Start";
+            Out_SecPosCamera.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Z_Position_Stop";
+            Out_SecPosCamera.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Z_Velocity_Stop";
+            Out_SecPosCamera.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.U_Position";
+            Out_SecPosCamera.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.U_Velocity";
+            Out_SecPosCamera.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.R_Position";
+            Out_SecPosCamera.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.R_Velocity";
+            Out_SecPosCamera.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Torque";
+            Out_SecPosCamera.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.Feeder";
+            Out_SecPosCamera.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_SecPosCamera{0}.ScrewProNum";
+
+            // Out_ScrewCamera(锁附拍照点位)初始化并赋地址
+            Out_ScrewCamera = EnsurePoint(Out_ScrewCamera);
+            Out_ScrewCamera.Description = "锁附拍照点位参数";
+            Out_ScrewCamera.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.X_Position";
+            Out_ScrewCamera.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.X_Velocity";
+            Out_ScrewCamera.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Y_Position";
+            Out_ScrewCamera.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Y_Velocity";
+            Out_ScrewCamera.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Z_Position_Start";
+            Out_ScrewCamera.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Z_Velocity_Start";
+            Out_ScrewCamera.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Z_Position_Stop";
+            Out_ScrewCamera.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Z_Velocity_Stop";
+            Out_ScrewCamera.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.U_Position";
+            Out_ScrewCamera.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.U_Velocity";
+            Out_ScrewCamera.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.R_Position";
+            Out_ScrewCamera.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.R_Velocity";
+            Out_ScrewCamera.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Torque";
+            Out_ScrewCamera.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.Feeder";
+            Out_ScrewCamera.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_ScrewCamera{0}.ScrewProNum";
+
+            // Out_Screw(锁附点位)初始化并赋地址
+            Out_Screw = EnsurePoint(Out_Screw);
+            Out_Screw.Description = "锁附点位参数";
+            Out_Screw.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.X_Position";
+            Out_Screw.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.X_Velocity";
+            Out_Screw.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Y_Position";
+            Out_Screw.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Y_Velocity";
+            Out_Screw.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Z_Position_Start";
+            Out_Screw.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Z_Velocity_Start";
+            Out_Screw.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Z_Position_Stop";
+            Out_Screw.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Z_Velocity_Stop";
+            Out_Screw.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.U_Position";
+            Out_Screw.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.U_Velocity";
+            Out_Screw.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.R_Position";
+            Out_Screw.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.R_Velocity";
+            Out_Screw.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Torque";
+            Out_Screw.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.Feeder";
+            Out_Screw.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_Screw{0}.ScrewProNum";
+
+            // Out_CheckCamera(复检点位)初始化并赋地址
+            Out_CheckCamera = EnsurePoint(Out_CheckCamera);
+            Out_CheckCamera.Description = "复检点位参数";
+            Out_CheckCamera.X_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.X_Position";
+            Out_CheckCamera.X_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.X_Velocity";
+            Out_CheckCamera.Y_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Y_Position";
+            Out_CheckCamera.Y_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Y_Velocity";
+            Out_CheckCamera.Z_Position_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Z_Position_Start";
+            Out_CheckCamera.Z_Velocity_Start.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Z_Velocity_Start";
+            Out_CheckCamera.Z_Position_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Z_Position_Stop";
+            Out_CheckCamera.Z_Velocity_Stop.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Z_Velocity_Stop";
+            Out_CheckCamera.U_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.U_Position";
+            Out_CheckCamera.U_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.U_Velocity";
+            Out_CheckCamera.R_Position.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.R_Position";
+            Out_CheckCamera.R_Velocity.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.R_Velocity";
+            Out_CheckCamera.Torque.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Torque";
+            Out_CheckCamera.Feeder.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.Feeder";
+            Out_CheckCamera.ScrewProNum.Address = "ns=4;s=DB_Communication|FromPC.Point_CheckCamera{0}.ScrewProNum";
+
             // 4. In_* 默认(假定从 PLC 读到 PC,使用 ToPC 前缀)
             In_Code = Ensure(In_Code);
             In_Code.Address = "ns=4;s=DB_Communication|ToPC.Code";

+ 19 - 0
TeamAAS-VM/Models/PLC/PlcPointAddress.cs

@@ -26,5 +26,24 @@ namespace TeamAAS_VP.Models.PLC
         public PlcAddress Feeder { get; set; }
         public PlcAddress ScrewProNum { get; set; }
 
+        public PlcPointAddress()
+        {
+            Description = "点位地址";
+            X_Position = new PlcAddress() { Description = "X轴位置地址",DataType="float" };
+            X_Velocity = new PlcAddress() { Description = "X轴速度地址", DataType = "float" };
+            Y_Position = new PlcAddress() { Description = "Y轴位置地址", DataType = "float" };
+            Y_Velocity = new PlcAddress() { Description = "Y轴速度地址", DataType = "float" };
+            Z_Position_Start = new PlcAddress() { Description = "Z轴起始位置地址", DataType = "float" };
+            Z_Velocity_Start = new PlcAddress() { Description = "Z轴起始速度地址", DataType = "float" };
+            Z_Position_Stop = new PlcAddress() { Description = "Z轴停止位置地址", DataType = "float" };
+            Z_Velocity_Stop = new PlcAddress() { Description = "Z轴停止速度地址", DataType = "float" };
+            U_Position = new PlcAddress() { Description = "U轴位置地址", DataType = "float" };
+            U_Velocity = new PlcAddress() { Description = "U轴速度地址", DataType = "float" };
+            R_Position = new PlcAddress() { Description = "R轴位置地址", DataType = "float" };
+            R_Velocity = new PlcAddress() { Description = "R轴速度地址", DataType = "float" };
+            Torque = new PlcAddress() { Description = "扭矩地址", DataType = "float" };
+            Feeder = new PlcAddress() { Description = "送料器地址", DataType = "int16" };
+            ScrewProNum = new PlcAddress() { Description = "螺杆程序号地址", DataType = "int16" };
+        }
     }
 }

+ 1 - 0
TeamAAS-VM/Services/ConfigService.cs

@@ -12,6 +12,7 @@ using TeamAAS_VP.Models;
 using TeamAAS_VP.Models.Calibration;
 using TeamAAS_VP.Models.Feeder;
 using TeamAAS_VP.Models.Lights;
+using TeamAAS_VP.Models.PLC;
 
 namespace TeamAAS_VP.Services
 {

+ 1 - 1
TeamAAS-VM/TeamAAS-VP.csproj

@@ -594,7 +594,7 @@
     <Compile Include="Models\DataPoint.cs" />
     <Compile Include="Models\Lights\ChannelConfig.cs" />
     <Compile Include="Models\Lights\LightControllerConfig.cs" />
-    <Compile Include="Models\PlcAddressConfig.cs" />
+    <Compile Include="Models\PLC\PlcAddressConfig.cs" />
     <Compile Include="Models\PLC\PlcAddress.cs" />
     <Compile Include="Models\PLC\PlcPoint.cs" />
     <Compile Include="Models\PLC\PlcPointAddress.cs" />