diff --git a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs index 0708de6..831e12e 100644 --- a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs +++ b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs @@ -2,11 +2,13 @@ using CtrEditor.FuncionesBase; using LibS7Adv; using Newtonsoft.Json; +using System.ComponentModel; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Media; + namespace CtrEditor.ObjetosSim { /// @@ -59,6 +61,16 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] public float tiempoRampa; + [ObservableProperty] + [property: Description("Enable read of the Motor encoder simulated on PLC.")] + [property: Category("Encoder:")] + bool motor_With_Encoder; + + [ObservableProperty] + [property: Description("Actual Value of the encoder position.")] + [property: Category("Encoder:")] + public float actual_Position; + partial void OnTiempoRampaChanged(float value) { if (value < 0.1f) @@ -204,9 +216,14 @@ namespace CtrEditor.ObjetosSim // Add timestamp to trace when the read occurs var timestamp = DateTime.Now; - - // Read ControlWord and track the raw response - var rawResponse = plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ControlWord"); + + if (Data.Motor_With_Encoder) + Data.Actual_Position = (float)plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ActualPosition"); + else + Data.Actual_Position = 0; + + // Read ControlWord and track the raw response + var rawResponse = plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ControlWord"); int controlWord = rawResponse ?? 0; var control = VMMotorBitPacker.UnpackControlWord(controlWord); diff --git a/ObjetosSim/SensoresComandos/ucEncoderMotor.xaml.cs b/ObjetosSim/SensoresComandos/ucEncoderMotor.xaml.cs index d2a6f8d..183155a 100644 --- a/ObjetosSim/SensoresComandos/ucEncoderMotor.xaml.cs +++ b/ObjetosSim/SensoresComandos/ucEncoderMotor.xaml.cs @@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim public partial class osEncoderMotor : osBase, IosBase { private osBase Motor = null; - private Stopwatch Stopwatch = new Stopwatch(); - private double stopwatch_last = 0; public static string NombreClase() { @@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim Pulsos_Por_Vuelta = 360; // Por defecto, un pulso por grado Ratio_Giros_50hz = 1; // Por defecto, 1 giro por cada 50Hz Color_oculto = Brushes.Gray; - Stopwatch.Start(); } public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) diff --git a/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs b/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs index 2054945..5463210 100644 --- a/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs +++ b/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs @@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim public partial class osEncoderMotorLineal : osBase, IosBase { private osBase Motor = null; - private Stopwatch Stopwatch = new Stopwatch(); - private double stopwatch_last = 0; public static string NombreClase() { @@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim { Pulsos_Por_Hz = 3000; // Por defecto, un pulso por grado Color_oculto = Brushes.Gray; - Stopwatch.Start(); } public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) @@ -100,7 +97,8 @@ namespace CtrEditor.ObjetosSim Valor_Actual = (int)value; return; } - } else if (Motor != null && Motor is osVMmotorSim motor) + } + else if (Motor != null && Motor is osVMmotorSim motor) { VelocidadActual = motor.Velocidad; @@ -116,7 +114,10 @@ namespace CtrEditor.ObjetosSim float incrementoPulsos = pulsosPorHz * segundosTranscurridos; // Actualizar valor del encoder - Valor_Actual = (Valor_Actual + incrementoPulsos); + if (motor.Motor_With_Encoder) + Valor_Actual = motor.Actual_Position; + else + Valor_Actual = (Valor_Actual + incrementoPulsos); // Actualizar color basado en si está girando Color_oculto = Math.Abs(pulsosPorHz) > 0.01f ? Brushes.LightGreen : Brushes.Gray; diff --git a/ObjetosSim/TagsSignals/ucBoolTag.xaml b/ObjetosSim/TagsSignals/ucBoolTag.xaml index 0e79d2b..c80696b 100644 --- a/ObjetosSim/TagsSignals/ucBoolTag.xaml +++ b/ObjetosSim/TagsSignals/ucBoolTag.xaml @@ -1,17 +1,14 @@ - + - + - + @@ -26,18 +23,14 @@ - - diff --git a/ObjetosSim/TagsSignals/ucBoolTag.xaml.cs b/ObjetosSim/TagsSignals/ucBoolTag.xaml.cs index 97b1beb..2bdaef7 100644 --- a/ObjetosSim/TagsSignals/ucBoolTag.xaml.cs +++ b/ObjetosSim/TagsSignals/ucBoolTag.xaml.cs @@ -39,6 +39,9 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] public bool estado; + [ObservableProperty] + public bool show_Description; + partial void OnEstadoChanged(bool value) { EscribirBitTag(Tag, value); @@ -69,6 +72,7 @@ namespace CtrEditor.ObjetosSim tag = "%M50.0"; Descripcion = "Nombre del Tag"; Color = Colors.LightBlue; + Show_Description = true; } public override void UpdatePLCPrimerCiclo() diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index ba8e1a4..83aefc9 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -7,7 +7,7 @@ using LibS7Adv; using nkast.Aether.Physics2D.Common; using PaddleOCRSharp; using Siemens.Simatic.Simulation.Runtime; -using System.ComponentModel; +using System.ComponentModel; // Para poder usar [property: Category ... using System.Diagnostics; using System.IO; using System.Windows;