114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using LibS7Adv;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using CtrEditor.FuncionesBase;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucTanque.xaml
|
|
/// </summary>
|
|
public partial class osTanque : osBase, IosBase
|
|
{
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Tanque";
|
|
}
|
|
private string nombre = NombreClase();
|
|
public override string Nombre
|
|
{
|
|
get => nombre;
|
|
set => SetProperty(ref nombre, value);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public float capacidad_Litros;
|
|
[ObservableProperty]
|
|
public bool ingreso_Abierto;
|
|
[ObservableProperty]
|
|
public bool salida_Abierta;
|
|
[ObservableProperty]
|
|
public string tagNivel_Word;
|
|
[ObservableProperty]
|
|
public string tagIngresoAbierto_Bool;
|
|
[ObservableProperty]
|
|
public string tagSalidaAbierta_Bool;
|
|
[ObservableProperty]
|
|
public float velocidad_Ingreso;
|
|
[ObservableProperty]
|
|
public float velocidad_Salida;
|
|
[ObservableProperty]
|
|
public float min_OUT_Scaled;
|
|
[ObservableProperty]
|
|
public float max_OUT_Scaled;
|
|
[ObservableProperty]
|
|
public float level;
|
|
|
|
public osTanque()
|
|
{
|
|
Ancho = 0.30f;
|
|
Alto = 0.30f;
|
|
Max_OUT_Scaled = 27648;
|
|
Min_OUT_Scaled = 0;
|
|
}
|
|
|
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
|
{
|
|
EscribirWordTagScaled(TagNivel_Word, Level, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
|
|
Ingreso_Abierto = LeerBitTag(TagIngresoAbierto_Bool);
|
|
Salida_Abierta = LeerBitTag(TagSalidaAbierta_Bool);
|
|
}
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
|
{
|
|
if (Salida_Abierta && Level > 0)
|
|
{
|
|
var l_por_milisegundo = Velocidad_Salida / 60000.0f;
|
|
Level -= l_por_milisegundo * elapsedMilliseconds;
|
|
if (Level < 0) Level = 0;
|
|
}
|
|
if (Ingreso_Abierto && Level < 100)
|
|
{
|
|
var l_por_milisegundo = Velocidad_Ingreso / 60000.0f;
|
|
Level += l_por_milisegundo * elapsedMilliseconds;
|
|
if (Level > 100) Level = 100;
|
|
}
|
|
}
|
|
public override void ucLoaded()
|
|
{
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
base.ucLoaded();
|
|
|
|
}
|
|
}
|
|
|
|
public partial class ucTanque : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucTanque()
|
|
{
|
|
InitializeComponent();
|
|
this.Loaded += OnLoaded;
|
|
this.Unloaded += OnUnloaded;
|
|
}
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucLoaded();
|
|
}
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucUnLoaded();
|
|
}
|
|
public void Highlight(bool State) { }
|
|
public ZIndexEnum ZIndex()
|
|
{
|
|
return ZIndexEnum.Generadores;
|
|
}
|
|
}
|
|
}
|