using Prism.Mvvm; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using TeamAAS_VP.Core.PLCs; using TeamAAS_VP.Interfaces; namespace TeamAAS_VP.Models.PLC { public class PlcPoint : BindableBase { private int _Number; /// /// 点位编号 /// public int Number { get { return _Number; } set { SetProperty(ref _Number, value); } } private string _Label; /// /// 点位标签 /// public string Label { get { return _Label; } set { SetProperty(ref _Label, value); } } private float _X_Position; /// /// X轴位置 /// public float X_Position { get { return _X_Position; } set { SetProperty(ref _X_Position, value); } } private float _X_Velocity; /// /// X轴速度 /// public float X_Velocity { get { return _X_Velocity; } set { SetProperty(ref _X_Velocity, value); } } private float _Y_Position; /// /// Y轴位置 /// public float Y_Position { get { return _Y_Position; } set { SetProperty(ref _Y_Position, value); } } private float _Y_Velocity; /// /// Y轴速度 /// public float Y_Velocity { get { return _Y_Velocity; } set { SetProperty(ref _Y_Velocity, value); } } private float _Z_Position_Start; /// /// Z轴起点位置 /// public float Z_Position_Start { get { return _Z_Position_Start; } set { SetProperty(ref _Z_Position_Start, value); } } private float _Z_Velocity_Start; /// /// Z轴起点速度 /// public float Z_Velocity_Start { get { return _Z_Velocity_Start; } set { SetProperty(ref _Z_Velocity_Start, value); } } private float _Z_Position_Stop; /// /// Z轴终点位置 /// public float Z_Position_Stop { get { return _Z_Position_Stop; } set { SetProperty(ref _Z_Position_Stop, value); } } private float _Z_Velocity_Stop; /// /// Z轴终点速度 /// public float Z_Velocity_Stop { get { return _Z_Velocity_Stop; } set { SetProperty(ref _Z_Velocity_Stop, value); } } private float _U_Position; /// /// U轴位置 /// public float U_Position { get { return _U_Position; } set { SetProperty(ref _U_Position, value); } } private float _U_Velocity; /// /// U轴速度 /// public float U_Velocity { get { return _U_Velocity; } set { SetProperty(ref _U_Velocity, value); } } private float _R_Position; /// /// R轴位置 /// public float R_Position { get { return _R_Position; } set { SetProperty(ref _R_Position, value); } } private float _R_Velocity; /// /// R轴速度 /// public float R_Velocity { get { return _R_Velocity; } set { SetProperty(ref _R_Velocity, value); } } private float _Torque; /// /// 扭矩值 /// public float Torque { get { return _Torque; } set { SetProperty(ref _Torque, value); } } private Int16 _Feeder; /// /// Feeder编号 /// public Int16 Feeder { get { return _Feeder; } set { SetProperty(ref _Feeder, value); } } private Int16 _ScrewProNum; /// /// 电批程序号 /// public Int16 ScrewProNum { get { return _ScrewProNum; } set { SetProperty(ref _ScrewProNum, value); } } //描述 private string _Description; /// /// 点位描述 /// public string Description { get { return _Description; } set { SetProperty(ref _Description, value); } } private Guid _VisionProcessID; /// /// 视觉流程ID /// public Guid VisionProcessID { get { return _VisionProcessID; } set { SetProperty(ref _VisionProcessID, value); } } private string _VisionProcessName; /// /// 视觉流程名称 /// public string VisionProcessName { get { return _VisionProcessName; } set { SetProperty(ref _VisionProcessName, value); } } private float _X_Offset; /// /// X轴补偿值 /// public float X_Offset { get { return _X_Offset; } set { SetProperty(ref _X_Offset, value); } } private float _Y_Offset; /// /// Y轴补偿值 /// public float Y_Offset { get { return _Y_Offset; } set { SetProperty(ref _Y_Offset, value); } } private float _Z_Start_Offset; /// /// Z轴起点补偿值 /// public float Z_Start_Offset { get { return _Z_Start_Offset; } set { SetProperty(ref _Z_Start_Offset, value); } } private float _Z_Stop_Offset; /// /// Z轴终点补偿值 /// public float Z_Stop_Offset { get { return _Z_Stop_Offset; } set { SetProperty(ref _Z_Stop_Offset, value); } } private float _U_Offset; /// /// U轴补偿值 /// public float U_Offset { get { return _U_Offset; } set { SetProperty(ref _U_Offset, value); } } private float _R_Offset; /// /// R轴补偿值 /// public float R_Offset { get { return _R_Offset; } set { SetProperty(ref _R_Offset, value); } } public PlcPoint() { Number = 0; X_Position = 0; X_Velocity = 0; Y_Position = 0; Y_Velocity = 0; Z_Position_Start = 0; Z_Velocity_Start = 0; Z_Position_Stop = 0; Z_Velocity_Stop = 0; U_Position = 0; U_Velocity = 0; R_Position = 0; R_Velocity = 0; Torque = 0; Feeder = 0; ScrewProNum = 0; Description = string.Empty; X_Offset = 0; Y_Offset = 0; Z_Start_Offset = 0; Z_Stop_Offset = 0; U_Offset = 0; R_Offset = 0; } public PlcPoint Clone() { return new PlcPoint { Number = this.Number, Label = this.Label, X_Position = this.X_Position, X_Velocity = this.X_Velocity, Y_Position = this.Y_Position, Y_Velocity = this.Y_Velocity, Z_Position_Start = this.Z_Position_Start, Z_Velocity_Start = this.Z_Velocity_Start, Z_Position_Stop = this.Z_Position_Stop, Z_Velocity_Stop = this.Z_Velocity_Stop, U_Position = this.U_Position, U_Velocity = this.U_Velocity, R_Position = this.R_Position, R_Velocity = this.R_Velocity, Torque = this.Torque, Feeder = this.Feeder, ScrewProNum = this.ScrewProNum, Description = this.Description, VisionProcessID = this.VisionProcessID, VisionProcessName = this.VisionProcessName, X_Offset = this.X_Offset, Y_Offset = this.Y_Offset, Z_Start_Offset = this.Z_Start_Offset, Z_Stop_Offset = this.Z_Stop_Offset, U_Offset = this.U_Offset, R_Offset = this.R_Offset }; } /// /// 将点位数据写入到PLC地址 /// /// /// /// public async Task WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC) { Dictionary nodeValues = new Dictionary(); nodeValues.Add(string.Format(plcAddress.X_Position.Address, Number), X_Position + X_Offset); nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, Number), X_Velocity); nodeValues.Add(string.Format(plcAddress.Y_Position.Address, Number), Y_Position + Y_Offset); nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, Number), Y_Velocity); nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start + Z_Start_Offset); nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start); nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop + Z_Stop_Offset); nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop); nodeValues.Add(string.Format(plcAddress.U_Position.Address, Number), U_Position + U_Offset); nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, Number), U_Velocity); nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position + R_Offset); nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity); nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque); nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder); nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum); return await pLC.WriteNodesAsync(nodeValues); } /// /// 将点位数据写入到PLC地址 /// /// /// /// public async Task WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC,int index) { Dictionary nodeValues = new Dictionary(); nodeValues.Add(string.Format(plcAddress.X_Position.Address, index), X_Position + X_Offset); nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, index), X_Velocity); nodeValues.Add(string.Format(plcAddress.Y_Position.Address, index), Y_Position + Y_Offset); nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, index), Y_Velocity); nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, index), Z_Position_Start + Z_Start_Offset); nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, index), Z_Velocity_Start); nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, index), Z_Position_Stop + Z_Stop_Offset); nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, index), Z_Velocity_Stop); nodeValues.Add(string.Format(plcAddress.U_Position.Address, index), U_Position + U_Offset); nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, index), U_Velocity); nodeValues.Add(string.Format(plcAddress.R_Position.Address, index), R_Position + R_Offset); nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, index), R_Velocity); nodeValues.Add(string.Format(plcAddress.Torque.Address, index), Torque); nodeValues.Add(string.Format(plcAddress.Feeder.Address, index), Feeder); nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, index), ScrewProNum); return await pLC.WriteNodesAsync(nodeValues); } /// /// 将点位数据写入到PLC地址 /// /// /// /// public async Task WriteToPlcAddressEx(PlcPointAddress plcAddress, OpcUaClientPLC pLC) { Dictionary nodeValues = new Dictionary(); //nodeValues.Add(string.Format(plcAddress.X_Position.Address, Number), X_Position); //nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, Number), X_Velocity); //nodeValues.Add(string.Format(plcAddress.Y_Position.Address, Number), Y_Position); //nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, Number), Y_Velocity); //nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start); //nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start); //nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop); //nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop); //nodeValues.Add(string.Format(plcAddress.U_Position.Address, Number), U_Position); //nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, Number), U_Velocity); //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position); //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity); //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque); nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder); nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum); return await pLC.WriteNodesAsync(nodeValues); } } }