diff --git a/MainViewModel.cs b/MainViewModel.cs index e74a5f0..edd1f03 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -135,7 +135,11 @@ namespace CtrEditor { foreach (var objetoSimulable in ObjetosSimulables) + { + if (_plcViewModelData.IsConnected) + objetoSimulable.UpdatePLC(_plcViewModelData.PLCInterface); objetoSimulable.UpdateGeometry(); + } simulationManager.Step((float)_timerSimulacion.Interval.TotalMilliseconds); diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 7f6c57b..37a3a68 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -12,6 +12,7 @@ using System.Windows.Controls; using System.Windows.Data; using static System.Runtime.InteropServices.JavaScript.JSType; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -50,6 +51,7 @@ namespace CtrEditor.ObjetosSim public abstract void ConnectSimManager(SimulationManager simulationManager); public abstract void UpdateControl(); public abstract void UpdateGeometry(); + public abstract void UpdatePLC(PLCModel plc); [JsonIgnore] public UserControl? VisualRepresentation diff --git a/ObjetosSim/ucBotella.xaml.cs b/ObjetosSim/ucBotella.xaml.cs index 26a0bfe..0516460 100644 --- a/ObjetosSim/ucBotella.xaml.cs +++ b/ObjetosSim/ucBotella.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using System.Numerics; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -106,6 +107,7 @@ namespace CtrEditor.ObjetosSim // Se llama antes de la simulacion } + public override void UpdatePLC(PLCModel plc) { } public override void UpdateControl() { diff --git a/ObjetosSim/ucGuia.xaml.cs b/ObjetosSim/ucGuia.xaml.cs index 271e3f1..e2af8ce 100644 --- a/ObjetosSim/ucGuia.xaml.cs +++ b/ObjetosSim/ucGuia.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -105,6 +106,9 @@ namespace CtrEditor.ObjetosSim public override void UpdateControl() { } + public override void UpdatePLC(PLCModel plc) { } + + } diff --git a/ObjetosSim/ucTransporteCurva.xaml.cs b/ObjetosSim/ucTransporteCurva.xaml.cs index 396bfc9..997e8b1 100644 --- a/ObjetosSim/ucTransporteCurva.xaml.cs +++ b/ObjetosSim/ucTransporteCurva.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -126,6 +127,9 @@ namespace CtrEditor.ObjetosSim public override void UpdateControl() { } + public override void UpdatePLC(PLCModel plc) { } + + } diff --git a/ObjetosSim/ucTransporteGuias.xaml.cs b/ObjetosSim/ucTransporteGuias.xaml.cs index 254069c..02e5bb4 100644 --- a/ObjetosSim/ucTransporteGuias.xaml.cs +++ b/ObjetosSim/ucTransporteGuias.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -202,6 +203,7 @@ namespace CtrEditor.ObjetosSim public override void UpdateControl() { } + public override void UpdatePLC(PLCModel plc) { } } diff --git a/ObjetosSim/ucTransporteTTop.xaml.cs b/ObjetosSim/ucTransporteTTop.xaml.cs index 0ba6a65..9b94f0c 100644 --- a/ObjetosSim/ucTransporteTTop.xaml.cs +++ b/ObjetosSim/ucTransporteTTop.xaml.cs @@ -16,6 +16,7 @@ using static System.Runtime.InteropServices.JavaScript.JSType; using System.Numerics; using System.Windows.Markup; using CtrEditor.Convertidores; +using CtrEditor.Siemens; namespace CtrEditor.ObjetosSim { @@ -124,6 +125,8 @@ namespace CtrEditor.ObjetosSim // Se llama antes de la simulacion } + public override void UpdatePLC(PLCModel plc) { } + public override void UpdateControl() { diff --git a/ObjetosSim/ucVMmotorSim.xaml.cs b/ObjetosSim/ucVMmotorSim.xaml.cs index 6304a66..6bc01f7 100644 --- a/ObjetosSim/ucVMmotorSim.xaml.cs +++ b/ObjetosSim/ucVMmotorSim.xaml.cs @@ -1,4 +1,5 @@ using CtrEditor.Convertidores; +using CtrEditor.Siemens; using System; using System.Collections.Generic; using System.Linq; @@ -89,6 +90,7 @@ namespace CtrEditor.ObjetosSim public osVMmotorSim() { Tamano = 0.30f; + PLC_NumeroMotor = 31; } public override void ConnectSimManager(SimulationManager simulationManager) @@ -99,9 +101,11 @@ namespace CtrEditor.ObjetosSim // Se llama antes de la simulacion } + public override void UpdatePLC(PLCModel plc) { } public override void UpdateControl() { + } } diff --git a/Siemens/PLCControl.xaml.cs b/Siemens/PLCControl.xaml.cs index d20f2f4..dc4107a 100644 --- a/Siemens/PLCControl.xaml.cs +++ b/Siemens/PLCControl.xaml.cs @@ -25,19 +25,21 @@ namespace CtrEditor.Siemens /// public class PLCViewModel : INotifyPropertyChanged { - private readonly PLCModel _plcModel; + public readonly PLCModel PLCInterface; private readonly DispatcherTimer _timer; private string _cpuTime; private string _connectionStatus = "offline"; private string _ip = "10.1.30.11"; private string _name = "PLC"; private string lastError; + public bool IsConnected { get; private set; } public event PropertyChangedEventHandler PropertyChanged; public PLCViewModel() { - _plcModel = new PLCModel(); + IsConnected = false; + PLCInterface = new PLCModel(); _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000) }; _timer.Tick += (s, e) => Refresh(); @@ -101,38 +103,40 @@ namespace CtrEditor.Siemens private void Connect() { // Implementa la conexión utilizando PLCModel - _plcModel.Instance = SimulationRuntimeManager.CreateInterface(Name); - _plcModel.Instance.OnSoftwareConfigurationChanged += Instance_OnSoftwareConfigurationChanged; + PLCInterface.Instance = SimulationRuntimeManager.CreateInterface(Name); + PLCInterface.Instance.OnSoftwareConfigurationChanged += Instance_OnSoftwareConfigurationChanged; //_plcModel.Instance.CommunicationInterface = ECommunicationInterface.Softbus; - if (_plcModel.Instance != null) + if (PLCInterface.Instance != null) { - _plcModel.UpdateTagList(); + PLCInterface.UpdateTagList(); _timer.Start(); ConnectionStatus = "connected"; + IsConnected = true; } } private void Instance_OnSoftwareConfigurationChanged(IInstance instance, SOnSoftwareConfigChangedParameter event_param) { - _plcModel.UpdateTagList(); + PLCInterface.UpdateTagList(); } private void Disconnect() { + IsConnected = false; _timer.Stop(); ConnectionStatus = "offline"; - _plcModel.Instance = null; + PLCInterface.Instance = null; } private void Refresh() { - if (_plcModel.Instance != null) + if (PLCInterface.Instance != null) { - CpuTime = _plcModel.LeerInt16("\"DB HMI\".CPU_Scan_Time")?.ToString() ?? "N/A"; - LastError = _plcModel.LastError; + CpuTime = PLCInterface.LeerInt16("\"DB HMI\".CPU_Scan_Time")?.ToString() ?? "N/A"; + LastError = PLCInterface.LastError; } }