2024-05-31 10:06:49 -03:00
|
|
|
|
|
2024-05-19 14:56:08 -03:00
|
|
|
|
using CtrEditor.Simulacion;
|
2024-06-28 14:47:08 -03:00
|
|
|
|
using LibS7Adv;
|
2024-05-19 14:56:08 -03:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media;
|
2024-05-22 14:21:39 -03:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
using System.Diagnostics;
|
2024-06-30 13:17:44 -03:00
|
|
|
|
using CtrEditor.FuncionesBase;
|
2024-09-12 11:43:39 -03:00
|
|
|
|
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
|
|
|
|
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
|
|
|
|
|
using System.ComponentModel;
|
2024-05-19 14:56:08 -03:00
|
|
|
|
|
2024-05-25 07:53:34 -03:00
|
|
|
|
namespace CtrEditor.ObjetosSim
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for ucPhotocell.xaml
|
|
|
|
|
/// </summary>
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public partial class osPhotocell : osBase, IosBase
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
|
|
|
|
private simBarrera Simulation_Photocell;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
Stopwatch timer;
|
|
|
|
|
double timer_lastPositive;
|
|
|
|
|
double timer_lastNegative;
|
2024-09-12 11:43:39 -03:00
|
|
|
|
|
2024-05-19 16:38:57 -03:00
|
|
|
|
public static string NombreClase()
|
|
|
|
|
{
|
|
|
|
|
return "Photocell";
|
|
|
|
|
}
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private string nombre = NombreClase();
|
|
|
|
|
public override string Nombre
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
get => nombre;
|
|
|
|
|
set => SetProperty(ref nombre, value);
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[property: Description("Color")]
|
|
|
|
|
[property: Category("Layout:")]
|
2024-05-30 13:48:37 -03:00
|
|
|
|
Brush color;
|
2024-09-12 11:43:39 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Description("Light cut")]
|
|
|
|
|
[property: Category("Debug:")]
|
2024-05-30 13:48:37 -03:00
|
|
|
|
bool luzCortada;
|
2024-05-19 16:38:57 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
partial void OnLuzCortadaChanged(bool value)
|
2024-05-19 16:38:57 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
if (LuzCortada)
|
|
|
|
|
Color = Brushes.Blue;
|
|
|
|
|
else
|
|
|
|
|
Color = Brushes.Green;
|
2024-05-23 14:56:14 -03:00
|
|
|
|
if (Tipo_NC)
|
|
|
|
|
EscribirBitTag(TagPhotocell_OUT, !LuzCortada);
|
|
|
|
|
else
|
|
|
|
|
EscribirBitTag(TagPhotocell_OUT, LuzCortada);
|
2024-05-31 10:06:49 -03:00
|
|
|
|
if (Filter_Frecuency < 1)
|
2024-05-27 05:34:20 -03:00
|
|
|
|
{
|
|
|
|
|
Filter_Frecuency = 1;
|
|
|
|
|
Frecuency = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
Lenght_positive_pulse = (float) (timer.ElapsedMilliseconds- timer_lastPositive);
|
|
|
|
|
timer_lastNegative = timer.ElapsedMilliseconds;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
Lenght_negative_pulse = (float)(timer.ElapsedMilliseconds - timer_lastNegative);
|
|
|
|
|
timer_lastPositive = timer.ElapsedMilliseconds;
|
|
|
|
|
Lenght_FP_to_FP = Lenght_positive_pulse + Lenght_negative_pulse;
|
|
|
|
|
Frecuency = (Frecuency * (filter_Frecuency - 1) + (1000 / Lenght_FP_to_FP)) / filter_Frecuency;
|
|
|
|
|
}
|
2024-05-23 14:56:14 -03:00
|
|
|
|
|
2024-05-19 16:38:57 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:48:37 -03:00
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Description("Size of the Light.")]
|
|
|
|
|
[property: Category("Setup:")]
|
|
|
|
|
float ancho_Haz_De_Luz;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[property: Description("Distance to the neck.")]
|
|
|
|
|
[property: Category("Debug:")]
|
2024-05-30 13:48:37 -03:00
|
|
|
|
float distancia_cuello;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Description("Type of detection: Neck of the bottle or Complete bottle.")]
|
|
|
|
|
[property: Category("Setup:")]
|
2024-05-30 13:48:37 -03:00
|
|
|
|
bool detectarCuello;
|
|
|
|
|
|
|
|
|
|
partial void OnDetectarCuelloChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
if (Simulation_Photocell == null) return;
|
|
|
|
|
|
|
|
|
|
Simulation_Photocell.DetectNeck = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Description("Filter signal.")]
|
|
|
|
|
[property: Category("Setup:")]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float filter_Frecuency;
|
|
|
|
|
|
|
|
|
|
partial void OnFilter_FrecuencyChanged(float value)
|
|
|
|
|
{
|
|
|
|
|
if (value<=0)
|
|
|
|
|
Filter_Frecuency = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Category("Debug:")]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float frecuency;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Category("Debug:")]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float lenght_positive_pulse;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Category("Debug:")]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float lenght_negative_pulse;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Category("Debug:")]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float lenght_FP_to_FP;
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
[property: Description("Type Filter signal.")]
|
|
|
|
|
[property: Category("Setup:")]
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public bool tipo_NC;
|
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
partial void OnTipo_NCChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
OnLuzCortadaChanged(LuzCortada);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public string tagPhotocell_OUT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void LeftChanged(float value)
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public override void TopChanged(float value)
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 09:32:32 -03:00
|
|
|
|
public override void AnguloChanged(float value)
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 09:32:32 -03:00
|
|
|
|
public override void AltoChanged(float value)
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 09:32:32 -03:00
|
|
|
|
public override void AnchoChanged(float value)
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 09:32:32 -03:00
|
|
|
|
|
2024-05-19 14:56:08 -03:00
|
|
|
|
private void ActualizarGeometrias()
|
|
|
|
|
{
|
|
|
|
|
if (_visualRepresentation is ucPhotocell uc)
|
2024-09-12 11:43:39 -03:00
|
|
|
|
UpdateRectangle(Simulation_Photocell, uc.Photocell, Ancho_Haz_De_Luz, Ancho, Angulo);
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public osPhotocell()
|
|
|
|
|
{
|
|
|
|
|
Ancho = 1;
|
|
|
|
|
Alto = 0.03f;
|
2024-09-12 11:43:39 -03:00
|
|
|
|
Ancho_Haz_De_Luz = 0.01f;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
Frecuency = 0;
|
|
|
|
|
timer = new Stopwatch();
|
|
|
|
|
timer.Start();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateGeometryStart()
|
|
|
|
|
{
|
|
|
|
|
// Se llama antes de la simulacion
|
|
|
|
|
ActualizarGeometrias();
|
|
|
|
|
}
|
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
|
|
|
|
{
|
2024-05-30 13:48:37 -03:00
|
|
|
|
Distancia_cuello = Simulation_Photocell.Distancia;
|
|
|
|
|
if (DetectarCuello)
|
|
|
|
|
LuzCortada = Simulation_Photocell.LuzCortadaNeck;
|
|
|
|
|
else
|
|
|
|
|
LuzCortada = Simulation_Photocell.LuzCortada > 0;
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
2024-05-27 05:34:20 -03:00
|
|
|
|
public override void UpdatePLCPrimerCiclo()
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-05-27 05:34:20 -03:00
|
|
|
|
// Escribimos el valor actual al iniciar la conexion
|
|
|
|
|
// Esto es util para NC principalmente
|
|
|
|
|
|
|
|
|
|
OnLuzCortadaChanged(LuzCortada);
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
2024-06-28 14:47:08 -03:00
|
|
|
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) {
|
2024-05-19 16:38:57 -03:00
|
|
|
|
}
|
2024-05-19 14:56:08 -03:00
|
|
|
|
public override void ucLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
|
|
|
// crear el objeto de simulacion
|
2024-05-30 13:48:37 -03:00
|
|
|
|
base.ucLoaded();
|
2024-05-19 14:56:08 -03:00
|
|
|
|
|
|
|
|
|
if (_visualRepresentation is ucPhotocell uc)
|
2024-05-30 13:48:37 -03:00
|
|
|
|
Simulation_Photocell = AddBarrera(simulationManager, uc.Photocell, Alto, Ancho, Angulo, DetectarCuello);
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
public override void ucUnLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl se esta eliminando
|
|
|
|
|
// eliminar el objeto de simulacion
|
|
|
|
|
simulationManager.Remove(Simulation_Photocell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class ucPhotocell : UserControl, IDataContainer
|
|
|
|
|
{
|
|
|
|
|
public osBase? Datos { get; set; }
|
|
|
|
|
|
|
|
|
|
public ucPhotocell()
|
|
|
|
|
{
|
|
|
|
|
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) { }
|
2024-06-30 13:17:44 -03:00
|
|
|
|
public ZIndexEnum ZIndex()
|
2024-05-19 14:56:08 -03:00
|
|
|
|
{
|
2024-06-30 13:17:44 -03:00
|
|
|
|
return ZIndexEnum.Fotocelula;
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 13:17:44 -03:00
|
|
|
|
|
2024-05-19 14:56:08 -03:00
|
|
|
|
}
|
|
|
|
|
}
|