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 { public int Number { get; set; } public float X_Position { get; set; } public float X_Velocity { get; set; } public float Y_Position { get; set; } public float Y_Velocity { get; set; } public float Z_Position_Start { get; set; } public float Z_Velocity_Start { get; set; } public float Z_Position_Stop { get; set; } public float Z_Velocity_Stop { get; set; } public float U_Position { get; set; } public float U_Velocity { get; set; } public float R_Position { get; set; } public float R_Velocity { get; set; } public float Torque { get; set; } public Int16 Feeder { get; set; } public Int16 ScrewProNum { get; set; } 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, 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 }; } /// /// 将点位数据写入到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); } } }