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; public float X_Position { get { return _X_Position; } set { SetProperty(ref _X_Position, value); } } private float _X_Velocity; public float X_Velocity { get { return _X_Velocity; } set { SetProperty(ref _X_Velocity, value); } } private float _Y_Position; public float Y_Position { get { return _Y_Position; } set { SetProperty(ref _Y_Position, value); } } private float _Y_Velocity; public float Y_Velocity { get { return _Y_Velocity; } set { SetProperty(ref _Y_Velocity, value); } } private float _Z_Position_Start; public float Z_Position_Start { get { return _Z_Position_Start; } set { SetProperty(ref _Z_Position_Start, value); } } private float _Z_Velocity_Start; public float Z_Velocity_Start { get { return _Z_Velocity_Start; } set { SetProperty(ref _Z_Velocity_Start, value); } } private float _Z_Position_Stop; public float Z_Position_Stop { get { return _Z_Position_Stop; } set { SetProperty(ref _Z_Position_Stop, value); } } private float _Z_Velocity_Stop; public float Z_Velocity_Stop { get { return _Z_Velocity_Stop; } set { SetProperty(ref _Z_Velocity_Stop, value); } } private float _U_Position; public float U_Position { get { return _U_Position; } set { SetProperty(ref _U_Position, value); } } private float _U_Velocity; public float U_Velocity { get { return _U_Velocity; } set { SetProperty(ref _U_Velocity, value); } } private float _R_Position; public float R_Position { get { return _R_Position; } set { SetProperty(ref _R_Position, value); } } private float _R_Velocity; 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; 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); } } 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; } 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 }; } /// /// 将点位数据写入到PLC地址 /// /// /// /// public async Task WriteToPlcAddress(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); } /// /// 将点位数据写入到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); } } }