Push Changes from Techcrafters Repo
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogMotorControl.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogMotorControl : UserControl
|
||||
{
|
||||
public AnalogMotorControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
namespace HMIToolkit;
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogMotorControl.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogMotorControl : UserControl
|
||||
{
|
||||
public AnalogMotorControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -2,82 +2,81 @@
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class AnalogMotorControlVM : ObservableObject
|
||||
{
|
||||
public sealed partial class AnalogMotorControlVM : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM StartButton { get; private set; }
|
||||
public HMIControlButtonVM StopButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
public AnalogValueVM? Setpoint { get; private set; }
|
||||
public AnalogValueVM? ProcessValue { get; private set; }
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM StartButton { get; private set; }
|
||||
public HMIControlButtonVM StopButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
public AnalogValueVM? Setpoint { get; private set; }
|
||||
public AnalogValueVM? ProcessValue { get; private set; }
|
||||
|
||||
private readonly string? _variableName;
|
||||
private readonly string? _variableName;
|
||||
|
||||
private IAdsManager? _adsManager;
|
||||
private IAdsManager? _adsManager;
|
||||
|
||||
public AnalogMotorControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
StartButton = new HMIControlButtonVM();
|
||||
StopButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
Setpoint = new AnalogValueVM();
|
||||
ProcessValue = new AnalogValueVM();
|
||||
}
|
||||
public AnalogMotorControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
StartButton = new HMIControlButtonVM();
|
||||
StopButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
Setpoint = new AnalogValueVM();
|
||||
ProcessValue = new AnalogValueVM();
|
||||
}
|
||||
|
||||
public AnalogMotorControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
StartButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStartButton");
|
||||
StopButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStopButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
Setpoint = new AnalogValueVM(_adsManager, _variableName + ".stSetpoint", false);
|
||||
ProcessValue = new AnalogValueVM(_adsManager, _variableName + ".stProcessValue", true);
|
||||
public AnalogMotorControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
StartButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStartButton");
|
||||
StopButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStopButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
Setpoint = new AnalogValueVM(_adsManager, _variableName + ".stSetpoint", false);
|
||||
ProcessValue = new AnalogValueVM(_adsManager, _variableName + ".stProcessValue", true);
|
||||
|
||||
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
|
||||
StartButton?.Dispose();
|
||||
StartButton = null;
|
||||
StartButton?.Dispose();
|
||||
StartButton = null;
|
||||
|
||||
StopButton?.Dispose();
|
||||
StopButton = null;
|
||||
StopButton?.Dispose();
|
||||
StopButton = null;
|
||||
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
|
||||
Setpoint?.Dispose();
|
||||
Setpoint = null;
|
||||
Setpoint?.Dispose();
|
||||
Setpoint = null;
|
||||
|
||||
ProcessValue?.Dispose();
|
||||
ProcessValue = null;
|
||||
}
|
||||
ProcessValue?.Dispose();
|
||||
ProcessValue = null;
|
||||
}
|
||||
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,31 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class AnalogRangeValidator : ValidationRule
|
||||
{
|
||||
public sealed partial class AnalogRangeValidator : ValidationRule
|
||||
{
|
||||
public float Min { get; set; }
|
||||
public float Min { get; set; }
|
||||
|
||||
public float Max { get; set; }
|
||||
public float Max { get; set; }
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
float analogValue = 0;
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
float analogValue = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (((string)value).Length > 0)
|
||||
analogValue = float.Parse((string)value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ValidationResult(false, $"Illegal characters or {e.Message}");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (((string)value).Length > 0)
|
||||
analogValue = float.Parse((string)value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ValidationResult(false, $"Illegal characters or {e.Message}");
|
||||
}
|
||||
|
||||
if ((analogValue < Min) || (analogValue > Max))
|
||||
return new ValidationResult(false, $"Please enter a value in the range: {Min}-{Max}.");
|
||||
if ((analogValue < Min) || (analogValue > Max))
|
||||
return new ValidationResult(false, $"Please enter a value in the range: {Min}-{Max}.");
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogValue : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogValue : UserControl
|
||||
{
|
||||
public bool IsReadonly { get; set; }
|
||||
public bool IsReadonly { get; set; }
|
||||
|
||||
public AnalogValue()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
public AnalogValue()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,22 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValveControl.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogValveControl : UserControl
|
||||
{
|
||||
public AnalogValveControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
namespace HMIToolkit;
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValveControl.xaml
|
||||
/// </summary>
|
||||
public partial class AnalogValveControl : UserControl
|
||||
{
|
||||
public AnalogValveControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -2,82 +2,81 @@
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class AnalogValveControlVM : ObservableObject
|
||||
{
|
||||
public sealed partial class AnalogValveControlVM : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM? OpenButton { get; private set; }
|
||||
public HMIControlButtonVM? CloseButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
public AnalogValueVM? Setpoint { get; private set; }
|
||||
public AnalogValueVM? ProcessValue { get; private set; }
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM? OpenButton { get; private set; }
|
||||
public HMIControlButtonVM? CloseButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
public AnalogValueVM? Setpoint { get; private set; }
|
||||
public AnalogValueVM? ProcessValue { get; private set; }
|
||||
|
||||
private readonly string? _variableName;
|
||||
private readonly string? _variableName;
|
||||
|
||||
private IAdsManager? _adsManager;
|
||||
private IAdsManager? _adsManager;
|
||||
|
||||
public AnalogValveControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
OpenButton = new HMIControlButtonVM();
|
||||
CloseButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
Setpoint = new AnalogValueVM();
|
||||
ProcessValue = new AnalogValueVM();
|
||||
}
|
||||
public AnalogValveControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
OpenButton = new HMIControlButtonVM();
|
||||
CloseButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
Setpoint = new AnalogValueVM();
|
||||
ProcessValue = new AnalogValueVM();
|
||||
}
|
||||
|
||||
public AnalogValveControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
OpenButton = new HMIControlButtonVM(_adsManager, _variableName + ".stOpenButton");
|
||||
CloseButton = new HMIControlButtonVM(_adsManager, _variableName + ".stCloseButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
Setpoint = new AnalogValueVM(_adsManager, _variableName + ".stSetpoint", false);
|
||||
ProcessValue = new AnalogValueVM(_adsManager, _variableName + ".stProcessValue", true);
|
||||
public AnalogValveControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
OpenButton = new HMIControlButtonVM(_adsManager, _variableName + ".stOpenButton");
|
||||
CloseButton = new HMIControlButtonVM(_adsManager, _variableName + ".stCloseButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
Setpoint = new AnalogValueVM(_adsManager, _variableName + ".stSetpoint", false);
|
||||
ProcessValue = new AnalogValueVM(_adsManager, _variableName + ".stProcessValue", true);
|
||||
|
||||
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
|
||||
OpenButton?.Dispose();
|
||||
OpenButton = null;
|
||||
OpenButton?.Dispose();
|
||||
OpenButton = null;
|
||||
|
||||
CloseButton?.Dispose();
|
||||
CloseButton = null;
|
||||
CloseButton?.Dispose();
|
||||
CloseButton = null;
|
||||
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
|
||||
Setpoint?.Dispose();
|
||||
Setpoint = null;
|
||||
Setpoint?.Dispose();
|
||||
Setpoint = null;
|
||||
|
||||
ProcessValue?.Dispose();
|
||||
ProcessValue = null;
|
||||
}
|
||||
ProcessValue?.Dispose();
|
||||
ProcessValue = null;
|
||||
}
|
||||
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@
|
||||
<Setter Property="Width" Value="Auto" />
|
||||
</Style>
|
||||
</d:DesignerProperties.DesignStyle>
|
||||
|
||||
<Border BorderThickness="2" BorderBrush="White">
|
||||
<Grid Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="55" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -72,5 +72,6 @@
|
||||
<Button x:Name="btnManual" DataContext="{Binding ManualButton}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Grid.Row="1" Grid.Column="1" Content="Man" FontSize="35" Height="100" Width="180" Margin="0,-5,0,-5"/>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
|
||||
@@ -13,23 +13,22 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für BinaryValveControl.xaml
|
||||
/// </summary>
|
||||
public partial class BinaryValveControl : UserControl
|
||||
{
|
||||
public BinaryValveControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
namespace HMIToolkit;
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaktionslogik für BinaryValveControl.xaml
|
||||
/// </summary>
|
||||
public partial class BinaryValveControl : UserControl
|
||||
{
|
||||
public BinaryValveControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -4,67 +4,66 @@ using Heisig.HMI.AdsManager;
|
||||
|
||||
// {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.OpenButton}
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class BinaryValveControlVM : ObservableObject, IDisposable
|
||||
{
|
||||
public sealed partial class BinaryValveControlVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
[ObservableProperty]
|
||||
private string sName = "No Name";
|
||||
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM OpenButton { get; private set; }
|
||||
public HMIControlButtonVM CloseButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
public HMIControlButtonVM? AutomaticButton { get; private set; }
|
||||
public HMIControlButtonVM? ManualButton { get; private set; }
|
||||
public HMIControlButtonVM OpenButton { get; private set; }
|
||||
public HMIControlButtonVM CloseButton { get; private set; }
|
||||
public IntlkControlVM? Interlocks { get; private set; }
|
||||
|
||||
private readonly string? _variableName;
|
||||
private readonly string? _variableName;
|
||||
|
||||
private IAdsManager? _adsManager;
|
||||
private IAdsManager? _adsManager;
|
||||
|
||||
public BinaryValveControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
OpenButton = new HMIControlButtonVM();
|
||||
CloseButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
}
|
||||
public BinaryValveControlVM()
|
||||
{
|
||||
AutomaticButton = new HMIControlButtonVM();
|
||||
ManualButton = new HMIControlButtonVM();
|
||||
OpenButton = new HMIControlButtonVM();
|
||||
CloseButton = new HMIControlButtonVM();
|
||||
Interlocks = new IntlkControlVM();
|
||||
}
|
||||
|
||||
public BinaryValveControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
OpenButton = new HMIControlButtonVM(_adsManager, _variableName + ".stOpenButton");
|
||||
CloseButton = new HMIControlButtonVM(_adsManager, _variableName + ".stCloseButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
public BinaryValveControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
AutomaticButton = new HMIControlButtonVM(_adsManager, _variableName + ".stAutomaticButton");
|
||||
ManualButton = new HMIControlButtonVM(_adsManager, _variableName + ".stManualButton");
|
||||
OpenButton = new HMIControlButtonVM(_adsManager, _variableName + ".stOpenButton");
|
||||
CloseButton = new HMIControlButtonVM(_adsManager, _variableName + ".stCloseButton");
|
||||
Interlocks = new IntlkControlVM(_adsManager, _variableName + ".stInterlock");
|
||||
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
_adsManager.Register(_variableName + ".sName", NameChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".sName", NameChanged);
|
||||
_adsManager = null;
|
||||
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
AutomaticButton?.Dispose();
|
||||
AutomaticButton = null;
|
||||
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
ManualButton?.Dispose();
|
||||
ManualButton = null;
|
||||
|
||||
OpenButton?.Dispose();
|
||||
OpenButton?.Dispose();
|
||||
|
||||
CloseButton?.Dispose();
|
||||
CloseButton?.Dispose();
|
||||
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
}
|
||||
Interlocks?.Dispose();
|
||||
Interlocks = null;
|
||||
}
|
||||
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NameChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
SName = (string)e.Value;
|
||||
}
|
||||
}
|
||||
@@ -3,23 +3,22 @@ using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public class BoolToBrushConverter : IValueConverter
|
||||
{
|
||||
public class BoolToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (targetType != typeof(Brush))
|
||||
throw new InvalidOperationException("The target must be a brush");
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (targetType != typeof(Brush))
|
||||
throw new InvalidOperationException("The target must be a brush");
|
||||
|
||||
bool temp = bool.Parse(value.ToString()!);
|
||||
bool temp = bool.Parse(value.ToString()!);
|
||||
|
||||
return (temp ? Brushes.DarkGreen : Brushes.DarkRed);
|
||||
}
|
||||
return (temp ? Brushes.DarkGreen : Brushes.DarkRed);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
@@ -3,72 +3,71 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class HMIControlButtonVM : ObservableObject, IDisposable
|
||||
{
|
||||
public sealed partial class HMIControlButtonVM : ObservableObject, IDisposable
|
||||
{
|
||||
private IAdsManager? _adsManager;
|
||||
private readonly string _variableName;
|
||||
private IAdsManager? _adsManager;
|
||||
private readonly string _variableName;
|
||||
|
||||
// Action triggered when the button is about to be clicked
|
||||
public event EventHandler? ButtonClickedStarted;
|
||||
// Action triggered when the button is about to be clicked
|
||||
public event EventHandler? ButtonClickedStarted;
|
||||
|
||||
// Action triggered when the button is done being clicked
|
||||
public event EventHandler? ButtonClickedEnded;
|
||||
// Action triggered when the button is done being clicked
|
||||
public event EventHandler? ButtonClickedEnded;
|
||||
|
||||
// Event when button feedback changed
|
||||
public event EventHandler? FeedbackChanged;
|
||||
// Event when button feedback changed
|
||||
public event EventHandler? FeedbackChanged;
|
||||
|
||||
// Event when release changed
|
||||
public event EventHandler? ReleaseChanged;
|
||||
// Event when release changed
|
||||
public event EventHandler? ReleaseChanged;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool xRelease;
|
||||
[ObservableProperty]
|
||||
private bool xRelease;
|
||||
|
||||
// 0 = none, 1 = active, 2 = pending, 3 = waring, 4 = error
|
||||
[ObservableProperty]
|
||||
private short iFeedback;
|
||||
// 0 = none, 1 = active, 2 = pending, 3 = waring, 4 = error
|
||||
[ObservableProperty]
|
||||
private short iFeedback;
|
||||
|
||||
public HMIControlButtonVM()
|
||||
{
|
||||
_variableName = string.Empty;
|
||||
XRelease = false;
|
||||
IFeedback = 4;
|
||||
}
|
||||
public HMIControlButtonVM()
|
||||
{
|
||||
_variableName = string.Empty;
|
||||
XRelease = false;
|
||||
IFeedback = 4;
|
||||
}
|
||||
|
||||
public HMIControlButtonVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
public HMIControlButtonVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
_adsManager.Register(_variableName + ".xRelease", XReleaseCahnged);
|
||||
_adsManager.Register(_variableName + ".iFeedback", IFeedbackChanged);
|
||||
}
|
||||
_adsManager.Register(_variableName + ".xRelease", XReleaseCahnged);
|
||||
_adsManager.Register(_variableName + ".iFeedback", IFeedbackChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".xRelease", XReleaseCahnged);
|
||||
_adsManager?.Deregister(_variableName + ".iFeedback", IFeedbackChanged);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName + ".xRelease", XReleaseCahnged);
|
||||
_adsManager?.Deregister(_variableName + ".iFeedback", IFeedbackChanged);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ButtonClicked()
|
||||
{
|
||||
ButtonClickedStarted?.Invoke(this, EventArgs.Empty);
|
||||
_adsManager?.WriteValue(_variableName + ".xRequest", true);
|
||||
ButtonClickedEnded?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
[RelayCommand]
|
||||
private void ButtonClicked()
|
||||
{
|
||||
ButtonClickedStarted?.Invoke(this, EventArgs.Empty);
|
||||
_adsManager?.WriteValue(_variableName + ".xRequest", true);
|
||||
ButtonClickedEnded?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void XReleaseCahnged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
XRelease = (bool)e.Value;
|
||||
ReleaseChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
private void XReleaseCahnged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
XRelease = (bool)e.Value;
|
||||
ReleaseChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void IFeedbackChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
IFeedback = (short)e.Value;
|
||||
FeedbackChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void IFeedbackChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
IFeedback = (short)e.Value;
|
||||
FeedbackChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,22 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für ProcessIntlkButtonControl.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkButtonControl : UserControl
|
||||
{
|
||||
public IntlkButtonControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
namespace HMIToolkit;
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaktionslogik für ProcessIntlkButtonControl.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkButtonControl : UserControl
|
||||
{
|
||||
public IntlkButtonControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,22 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetails.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetails : UserControl
|
||||
{
|
||||
public IntlkDetails()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
namespace HMIToolkit;
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetails.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetails : UserControl
|
||||
{
|
||||
public IntlkDetails()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -5,147 +5,146 @@ using System.Windows.Controls;
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
public sealed partial class IntlkDetailsVM : ObservableObject, IDisposable
|
||||
{
|
||||
public sealed partial class IntlkDetailsVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string interlockName;
|
||||
[ObservableProperty]
|
||||
private string interlockName;
|
||||
|
||||
[ObservableProperty]
|
||||
private BitArray interlockStatus;
|
||||
[ObservableProperty]
|
||||
private BitArray interlockStatus;
|
||||
|
||||
[ObservableProperty]
|
||||
private string[] interlockNames;
|
||||
[ObservableProperty]
|
||||
private string[] interlockNames;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsLeft;
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsLeft;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsRight;
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsRight;
|
||||
|
||||
[ObservableProperty]
|
||||
private Visibility isVisible;
|
||||
[ObservableProperty]
|
||||
private Visibility isVisible;
|
||||
|
||||
private readonly BoolToBrushConverter boolToBrushConverter = new();
|
||||
private readonly BoolToBrushConverter boolToBrushConverter = new();
|
||||
|
||||
private readonly int numIntlksLeftSide;
|
||||
private readonly int numIntlksRightSide;
|
||||
private readonly int numIntlksLeftSide;
|
||||
private readonly int numIntlksRightSide;
|
||||
|
||||
private readonly string _variableNameStatus;
|
||||
private readonly string _variableNameNames;
|
||||
private readonly string _variableNameStatus;
|
||||
private readonly string _variableNameNames;
|
||||
|
||||
private IAdsManager? _adsManager;
|
||||
private IAdsManager? _adsManager;
|
||||
|
||||
public IntlkDetailsVM()
|
||||
{
|
||||
interlockName = "Interlocks";
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
Array.Fill(interlockNames, "Not used");
|
||||
public IntlkDetailsVM()
|
||||
{
|
||||
interlockName = "Interlocks";
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
Array.Fill(interlockNames, "Not used");
|
||||
|
||||
// Split all interlocks into two parts
|
||||
numIntlksLeftSide = (int)Math.Ceiling(HMIConstants.NumInterlocks * 0.5);
|
||||
numIntlksRightSide = HMIConstants.NumInterlocks - numIntlksLeftSide;
|
||||
// Split all interlocks into two parts
|
||||
numIntlksLeftSide = (int)Math.Ceiling(HMIConstants.NumInterlocks * 0.5);
|
||||
numIntlksRightSide = HMIConstants.NumInterlocks - numIntlksLeftSide;
|
||||
|
||||
listBoxItemsLeft = new ListBoxItem[numIntlksLeftSide];
|
||||
listBoxItemsRight = new ListBoxItem[numIntlksRightSide];
|
||||
listBoxItemsLeft = new ListBoxItem[numIntlksLeftSide];
|
||||
listBoxItemsRight = new ListBoxItem[numIntlksRightSide];
|
||||
|
||||
_variableNameStatus = System.String.Empty;
|
||||
_variableNameNames = System.String.Empty;
|
||||
_variableNameStatus = System.String.Empty;
|
||||
_variableNameNames = System.String.Empty;
|
||||
|
||||
// CreateContent();
|
||||
}
|
||||
// CreateContent();
|
||||
}
|
||||
|
||||
public IntlkDetailsVM(IAdsManager adsManager, string variableNameStatus, string variableNameNames, string intlkName) : this()
|
||||
{
|
||||
interlockName = intlkName;
|
||||
_variableNameStatus = variableNameStatus;
|
||||
_variableNameNames = variableNameNames;
|
||||
_adsManager = adsManager;
|
||||
public IntlkDetailsVM(IAdsManager adsManager, string variableNameStatus, string variableNameNames, string intlkName) : this()
|
||||
{
|
||||
interlockName = intlkName;
|
||||
_variableNameStatus = variableNameStatus;
|
||||
_variableNameNames = variableNameNames;
|
||||
_adsManager = adsManager;
|
||||
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
|
||||
_adsManager.Register(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager.Register(_variableNameNames, InterlockNamesChanged);
|
||||
}
|
||||
_adsManager.Register(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager.Register(_variableNameNames, InterlockNamesChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager?.Deregister(_variableNameNames, InterlockNamesChanged);
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager?.Deregister(_variableNameNames, InterlockNamesChanged);
|
||||
|
||||
_adsManager = null;
|
||||
}
|
||||
_adsManager = null;
|
||||
}
|
||||
|
||||
/*private void CreateContent()
|
||||
{
|
||||
// Create left side
|
||||
for (int i = 0; i < HMIConstants.NumInterlocks; i++)
|
||||
{
|
||||
// Create the stack panel
|
||||
StackPanel stackPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal
|
||||
};
|
||||
/*private void CreateContent()
|
||||
{
|
||||
// Create left side
|
||||
for (int i = 0; i < HMIConstants.NumInterlocks; i++)
|
||||
{
|
||||
// Create the stack panel
|
||||
StackPanel stackPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal
|
||||
};
|
||||
|
||||
// Create the box
|
||||
// <Rectangle Width="10" Height="10" Fill="{Binding Path=InterlockStatus[10], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
Rectangle rectangle = new Rectangle
|
||||
{
|
||||
Width = 10,
|
||||
Height = 10,
|
||||
RadiusX = 2,
|
||||
RadiusY = 2
|
||||
};
|
||||
// Create the box
|
||||
// <Rectangle Width="10" Height="10" Fill="{Binding Path=InterlockStatus[10], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
Rectangle rectangle = new Rectangle
|
||||
{
|
||||
Width = 10,
|
||||
Height = 10,
|
||||
RadiusX = 2,
|
||||
RadiusY = 2
|
||||
};
|
||||
|
||||
// Create binding
|
||||
Binding binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockStatus[" + i + "]"),
|
||||
Converter = boolToBrushConverter,
|
||||
};
|
||||
// Create binding
|
||||
Binding binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockStatus[" + i + "]"),
|
||||
Converter = boolToBrushConverter,
|
||||
};
|
||||
|
||||
// Set binding
|
||||
rectangle.SetBinding(Rectangle.FillProperty, binding);
|
||||
// Set binding
|
||||
rectangle.SetBinding(Rectangle.FillProperty, binding);
|
||||
|
||||
// Create label
|
||||
Label label = new();
|
||||
binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockNames[" + i + "]")
|
||||
};
|
||||
label.SetBinding(Label.ContentProperty, binding);
|
||||
// Create label
|
||||
Label label = new();
|
||||
binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockNames[" + i + "]")
|
||||
};
|
||||
label.SetBinding(Label.ContentProperty, binding);
|
||||
|
||||
// Add items to stack panel
|
||||
stackPanel.Children.Add(rectangle);
|
||||
stackPanel.Children.Add(label);
|
||||
// Add items to stack panel
|
||||
stackPanel.Children.Add(rectangle);
|
||||
stackPanel.Children.Add(label);
|
||||
|
||||
// Add stack panel to listbox items
|
||||
ListBoxItem tempListBoxItem = new()
|
||||
{
|
||||
Content = stackPanel
|
||||
};
|
||||
if (i < numIntlksLeftSide)
|
||||
ListBoxItemsLeft[i] = tempListBoxItem;
|
||||
else
|
||||
ListBoxItemsRight[i - numIntlksLeftSide] = tempListBoxItem;
|
||||
}
|
||||
// Add stack panel to listbox items
|
||||
ListBoxItem tempListBoxItem = new()
|
||||
{
|
||||
Content = stackPanel
|
||||
};
|
||||
if (i < numIntlksLeftSide)
|
||||
ListBoxItemsLeft[i] = tempListBoxItem;
|
||||
else
|
||||
ListBoxItemsRight[i - numIntlksLeftSide] = tempListBoxItem;
|
||||
}
|
||||
|
||||
}*/
|
||||
}*/
|
||||
|
||||
private void InterlockStatusChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
ushort temp = (ushort)e.Value;
|
||||
InterlockStatus = new BitArray(BitConverter.GetBytes(temp));
|
||||
}
|
||||
private void InterlockStatusChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
ushort temp = (ushort)e.Value;
|
||||
InterlockStatus = new BitArray(BitConverter.GetBytes(temp));
|
||||
}
|
||||
|
||||
private void InterlockNamesChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
InterlockNames = (string[])e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void InterlockNamesChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
InterlockNames = (string[])e.Value;
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,15 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
namespace HMIToolkit;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetailsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetailsWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetailsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetailsWindow : Window
|
||||
{
|
||||
public IntlkDetailsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
public IntlkDetailsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -1,218 +1,216 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
// PLC - C#
|
||||
// --------
|
||||
// int - short
|
||||
// word - ushort
|
||||
namespace HMIToolkit;
|
||||
// PLC - C#
|
||||
// --------
|
||||
// int - short
|
||||
// word - ushort
|
||||
|
||||
// Constants for interaction with data
|
||||
public static class HMIConstants
|
||||
{
|
||||
public const int StringLength = 81;
|
||||
public const int NumInterlocks = 16;
|
||||
}
|
||||
// Constants for interaction with data
|
||||
public static class HMIConstants
|
||||
{
|
||||
public const int StringLength = 81;
|
||||
public const int NumInterlocks = 16;
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogValue
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogValue
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
|
||||
// 1 = Ok, 2 = Error
|
||||
public short iStatus;
|
||||
// 1 = Ok, 2 = Error
|
||||
public short iStatus;
|
||||
|
||||
public float rValue;
|
||||
public float rValue;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sUnit;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sUnit;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIControlButton
|
||||
{
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xRequest;
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIControlButton
|
||||
{
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xRequest;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xRelease;
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xRelease;
|
||||
|
||||
public short iFeedback;
|
||||
}
|
||||
public short iFeedback;
|
||||
}
|
||||
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIInterlock
|
||||
{
|
||||
public ushort wProcessINTLKStatus;
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIInterlock
|
||||
{
|
||||
public ushort wProcessINTLKStatus;
|
||||
|
||||
public ushort wSafeyINTLKStatus;
|
||||
public ushort wSafeyINTLKStatus;
|
||||
|
||||
public ushort wProcessINTLKUsed;
|
||||
public ushort wProcessINTLKUsed;
|
||||
|
||||
public ushort wSafeyINTLKUsed;
|
||||
public ushort wSafeyINTLKUsed;
|
||||
|
||||
// 16 * String(80) = 81 bytes a 16 indexes
|
||||
// combined in one string because reading a two dimensional array is not possible
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = HMIConstants.StringLength * HMIConstants.NumInterlocks)]
|
||||
public byte[] asProcessINTLKName;
|
||||
// 16 * String(80) = 81 bytes a 16 indexes
|
||||
// combined in one string because reading a two dimensional array is not possible
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = HMIConstants.StringLength * HMIConstants.NumInterlocks)]
|
||||
public byte[] asProcessINTLKName;
|
||||
|
||||
// 16 * String(80) = 81 bytes a 16 indexes
|
||||
// combined in one string because reading a two dimensional array is not possible
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = HMIConstants.StringLength * HMIConstants.NumInterlocks)]
|
||||
public byte[] asSafetyINTLKName;
|
||||
// 16 * String(80) = 81 bytes a 16 indexes
|
||||
// combined in one string because reading a two dimensional array is not possible
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = HMIConstants.StringLength * HMIConstants.NumInterlocks)]
|
||||
public byte[] asSafetyINTLKName;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xProcessINTLKOk;
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xProcessINTLKOk;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xSafetyINTLKOk;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xSafetyINTLKOk;
|
||||
}
|
||||
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIValveData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIValveData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
|
||||
public HMIControlButton stAutomaticButton;
|
||||
public HMIControlButton stAutomaticButton;
|
||||
|
||||
public HMIControlButton stManualButton;
|
||||
public HMIControlButton stManualButton;
|
||||
|
||||
public HMIControlButton stOpenButton;
|
||||
public HMIControlButton stOpenButton;
|
||||
|
||||
public HMIControlButton stCloseButton;
|
||||
public HMIControlButton stCloseButton;
|
||||
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
|
||||
public HMIInterlock stInterlock;
|
||||
public HMIInterlock stInterlock;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogValveData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogValveData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
|
||||
public HMIControlButton stAutomaticButton;
|
||||
public HMIControlButton stAutomaticButton;
|
||||
|
||||
public HMIControlButton stManualButton;
|
||||
public HMIControlButton stManualButton;
|
||||
|
||||
public HMIControlButton stOpenButton;
|
||||
public HMIControlButton stOpenButton;
|
||||
|
||||
public HMIControlButton stCloseButton;
|
||||
public HMIControlButton stCloseButton;
|
||||
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
|
||||
public HMIInterlock stInterlock;
|
||||
public HMIInterlock stInterlock;
|
||||
|
||||
HMIAnalogValue stSetpoint;
|
||||
HMIAnalogValue stSetpoint;
|
||||
|
||||
HMIAnalogValue stProcessValue;
|
||||
HMIAnalogValue stProcessValue;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogMotorData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIAnalogMotorData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
|
||||
public HMIControlButton stAutomaticButton;
|
||||
public HMIControlButton stAutomaticButton;
|
||||
|
||||
public HMIControlButton stManualButton;
|
||||
public HMIControlButton stManualButton;
|
||||
|
||||
public HMIControlButton stStartButton;
|
||||
public HMIControlButton stStartButton;
|
||||
|
||||
public HMIControlButton stStopButton;
|
||||
public HMIControlButton stStopButton;
|
||||
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
// 1 = Opened, 2 = Opening/Closing, 3 = Closed, 4 = Error
|
||||
public short iStatus;
|
||||
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
// 1 = Automatic mode, 2 = Manual mode
|
||||
public short iCurrentMode;
|
||||
|
||||
public HMIAnalogValue stSetpoint;
|
||||
public HMIAnalogValue stSetpoint;
|
||||
|
||||
public HMIAnalogValue stProcessValue;
|
||||
public HMIAnalogValue stProcessValue;
|
||||
|
||||
public HMIInterlock stInterlock;
|
||||
public HMIInterlock stInterlock;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIOrpSensorData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
// TwinCAT2 Pack = 1, TwinCAT 3 Pack = 0
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
public struct HMIOrpSensorData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HMIConstants.StringLength)]
|
||||
public string sName;
|
||||
|
||||
// 1 = Ok, 2 = Error
|
||||
public short iStatus;
|
||||
// 1 = Ok, 2 = Error
|
||||
public short iStatus;
|
||||
|
||||
public float rValuePH;
|
||||
public float rValuePH;
|
||||
|
||||
public float rValueTemp;
|
||||
public float rValueTemp;
|
||||
|
||||
public float rValueORP;
|
||||
public float rValueORP;
|
||||
|
||||
public float rValueDLI;
|
||||
public float rValueDLI;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool xUsed;
|
||||
}
|
||||
|
||||
static class HMIUtilities
|
||||
{
|
||||
// Converts the interlock byte array into a string array
|
||||
public static string[] GetInterlockStringArray(byte[] byteArray)
|
||||
{
|
||||
string[] temp = new string[HMIConstants.NumInterlocks];
|
||||
int size;
|
||||
static class HMIUtilities
|
||||
{
|
||||
// Converts the interlock byte array into a string array
|
||||
public static string[] GetInterlockStringArray(byte[] byteArray)
|
||||
{
|
||||
string[] temp = new string[HMIConstants.NumInterlocks];
|
||||
int size;
|
||||
|
||||
// Check if byteArray is of correct size
|
||||
if (byteArray.Length != (HMIConstants.StringLength * HMIConstants.NumInterlocks))
|
||||
return temp;
|
||||
// Check if byteArray is of correct size
|
||||
if (byteArray.Length != (HMIConstants.StringLength * HMIConstants.NumInterlocks))
|
||||
return temp;
|
||||
|
||||
for (int i = 0; i < HMIConstants.NumInterlocks; i++)
|
||||
{
|
||||
// Calculate length of string by finding the 0 terminator so the unused bytes get truncated
|
||||
size = Array.IndexOf(byteArray, (byte)0, i * HMIConstants.StringLength) - (i * HMIConstants.StringLength);
|
||||
for (int i = 0; i < HMIConstants.NumInterlocks; i++)
|
||||
{
|
||||
// Calculate length of string by finding the 0 terminator so the unused bytes get truncated
|
||||
size = Array.IndexOf(byteArray, (byte)0, i * HMIConstants.StringLength) - (i * HMIConstants.StringLength);
|
||||
|
||||
// Check if we found a valid 0 terminator
|
||||
if (size >= 0)
|
||||
// Build string from byteArray with calculated size
|
||||
temp[i] = Encoding.ASCII.GetString(byteArray, i * HMIConstants.StringLength, size);
|
||||
else
|
||||
// No valid 0 string terminator was found so return an empty string
|
||||
temp[i] = "";
|
||||
}
|
||||
// Check if we found a valid 0 terminator
|
||||
if (size >= 0)
|
||||
// Build string from byteArray with calculated size
|
||||
temp[i] = Encoding.ASCII.GetString(byteArray, i * HMIConstants.StringLength, size);
|
||||
else
|
||||
// No valid 0 string terminator was found so return an empty string
|
||||
temp[i] = "";
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user