Compare commits
6
Commits
d303f0767a
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb6f461b8e | ||
|
|
82d7a5b626 | ||
|
|
00100a7dc2 | ||
|
|
3c97d974b5 | ||
|
|
2bad9b8a0b | ||
|
|
0b6b05551b |
@@ -67,6 +67,9 @@ namespace PamhagenSysCtrl {
|
||||
|
||||
public static async Task CheckForUpdates(bool showResult = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
foreach (Window w in Current.Windows) {
|
||||
if (w is UpdateDialog) return;
|
||||
}
|
||||
|
||||
try {
|
||||
var latest = await UpdateService.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
|
||||
@@ -512,6 +512,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
HashSet<IEdge> visited = [];
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
edge.Highlight = color1;
|
||||
(edge.Start as PipeJoin)?.Highlight = color1;
|
||||
if (flowArrows > MotorState.Halt) {
|
||||
var dir = edge.End == node;
|
||||
if (flowArrows == MotorState.Backward) dir = !dir;
|
||||
@@ -520,7 +521,10 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
visited.Add(edge);
|
||||
if (node is Pump) color = color2;
|
||||
TraverseSubgraph(node, (n) => n is Valve || n is ISink || n is Pump, visited, edgeAction: (s, r, e) => e.Highlight = color);
|
||||
TraverseSubgraph(node, (n) => n is Valve || n is ISink || n is Pump, visited, edgeAction: (s, r, e) => {
|
||||
(s as PipeJoin)?.Highlight = color;
|
||||
e.Highlight = color;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,6 +534,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
edgeAction: (s, r, e) => {
|
||||
if (((e.Start as Valve)?.IsOpen ?? true) && ((e.End as Valve)?.IsOpen ?? true)) {
|
||||
e.Highlight = color1;
|
||||
(e.Start as PipeJoin)?.Highlight = color1;
|
||||
(e.End as PipeJoin)?.Highlight = color1;
|
||||
if (flowArrows == MotorState.Forward || flowArrows == MotorState.Backward) {
|
||||
var dir = e.Start == s;
|
||||
if (r) dir = !dir;
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown
|
||||
], default);
|
||||
|
||||
public string? PlcPortName => Plc?.PortName;
|
||||
public T1.Status? LastPlcStatus => Plc?.LastPlcStatus;
|
||||
public T1Error? LastPlcError => Plc?.LastPlcError;
|
||||
public long? LastRttNs { get; private set; }
|
||||
|
||||
public bool IsValveOpen(int n) => !IsValveClosed(n);
|
||||
public bool IsValveClosed(int n) => Sensors.GetDS(n);
|
||||
public bool WantValveClosed(int n) => !WantValveOpen(n);
|
||||
@@ -133,14 +138,17 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
|
||||
protected async void BackgroundLoop(object? parameters) {
|
||||
while (IsRunning && Plc != null) {
|
||||
var start = DateTime.Now;
|
||||
try {
|
||||
if (ActuatorsChanged) {
|
||||
await Plc.WriteOutputs(Actuators);
|
||||
ActuatorsChanged = false;
|
||||
}
|
||||
Sensors = await Plc.ReadInputs();
|
||||
LastRttNs = (long)(DateTime.Now - start).TotalNanoseconds;
|
||||
RaiseUpdateEvent(new());
|
||||
} catch (Exception exc) {
|
||||
LastRttNs = null;
|
||||
var str = "Bei der SPS ist ein Fehler aufgetreten:\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "SPS-Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
@@ -34,6 +34,10 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
|
||||
protected readonly T1 Plc;
|
||||
|
||||
public string PortName => Plc.PortName;
|
||||
public T1.Status LastPlcStatus => Plc.LastStatus;
|
||||
public T1Error LastPlcError => Plc.LastError;
|
||||
|
||||
public PamhagenPlc(string portName, Parity parity = Parity.Odd) {
|
||||
Plc = new T1(portName, parity);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public class PipeJoin : INode {
|
||||
@@ -12,11 +11,12 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public string Label => "";
|
||||
public Brush? Highlight { get; set; }
|
||||
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
public ISet<IEdge> Outputs { get; init; }
|
||||
|
||||
private Polygon? _rect;
|
||||
private System.Windows.Shapes.Path? _rect;
|
||||
|
||||
public PipeJoin(double x, double y) {
|
||||
CenterX = x;
|
||||
@@ -26,8 +26,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
_rect = new Polygon() {
|
||||
Fill = Brushes.Black,
|
||||
_rect = new System.Windows.Shapes.Path() {
|
||||
Fill = Brushes.DarkGray,
|
||||
Stroke = Brushes.Black,
|
||||
};
|
||||
canvas.Children.Add(_rect);
|
||||
@@ -43,43 +43,66 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
var il = Inputs.Any(e => (e.Start.CenterX < CenterX && (e.Orientation || e.Start.CenterY == CenterY)) || (e.IsTwoWay && e.End.CenterX < CenterX && (e.Orientation || e.End.CenterY == CenterY)));
|
||||
var ol = Outputs.Any(e => (e.End.CenterX < CenterX && (!e.Orientation || e.End.CenterY == CenterY)) || (e.IsTwoWay && e.Start.CenterX < CenterX && (!e.Orientation || e.Start.CenterY == CenterY)));
|
||||
|
||||
var points = new List<Point> {
|
||||
new(0, 0)
|
||||
};
|
||||
if (ot && it) {
|
||||
points.AddRange([new(SIZE / 2 - POINT, 0), new(SIZE / 2, -POINT / 2), new(SIZE / 2, POINT / 2), new(SIZE / 2 + POINT, 0)]);
|
||||
} else if (ot) {
|
||||
points.AddRange([new(SIZE / 2 - POINT, 0), new(SIZE / 2, -POINT), new(SIZE / 2 + POINT, 0)]);
|
||||
} else if (it) {
|
||||
points.AddRange([new(SIZE / 2 - POINT, 0), new(SIZE / 2, POINT), new(SIZE / 2 + POINT, 0)]);
|
||||
}
|
||||
points.Add(new(SIZE, 0));
|
||||
if (or && ir) {
|
||||
points.AddRange([new(SIZE, SIZE / 2 - POINT), new(SIZE + POINT / 2, SIZE / 2), new(SIZE - POINT / 2, SIZE / 2), new(SIZE, SIZE / 2 + POINT)]);
|
||||
} else if (or) {
|
||||
points.AddRange([new(SIZE, SIZE / 2 - POINT), new(SIZE + POINT, SIZE / 2), new(SIZE, SIZE / 2 + POINT)]);
|
||||
} else if (ir) {
|
||||
points.AddRange([new(SIZE, SIZE / 2 - POINT), new(SIZE - POINT, SIZE / 2), new(SIZE, SIZE / 2 + POINT)]);
|
||||
}
|
||||
points.Add(new(SIZE, SIZE));
|
||||
if (ob && ib) {
|
||||
points.AddRange([new(SIZE / 2 + POINT, SIZE), new(SIZE / 2, SIZE + POINT / 2), new(SIZE / 2, SIZE - POINT / 2), new(SIZE / 2 - POINT, SIZE)]);
|
||||
} else if (ob) {
|
||||
points.AddRange([new(SIZE / 2 + POINT, SIZE), new(SIZE / 2, SIZE + POINT), new(SIZE / 2 - POINT, SIZE)]);
|
||||
} else if (ib) {
|
||||
points.AddRange([new(SIZE / 2 + POINT, SIZE), new(SIZE / 2, SIZE - POINT), new(SIZE / 2 - POINT, SIZE)]);
|
||||
}
|
||||
points.Add(new(0, SIZE));
|
||||
if (ol && il) {
|
||||
points.AddRange([new(0, SIZE / 2 + POINT), new(-POINT / 2, SIZE / 2), new(POINT / 2, SIZE / 2), new(0, SIZE / 2 - POINT)]);
|
||||
} else if (ol) {
|
||||
points.AddRange([new(0, SIZE / 2 + POINT), new(-POINT, SIZE / 2), new(0, SIZE / 2 - POINT)]);
|
||||
} else if (il) {
|
||||
points.AddRange([new(0, SIZE / 2 + POINT), new(POINT, SIZE / 2), new(0, SIZE / 2 - POINT)]);
|
||||
var size = new Size(SIZE / 2 * scale, SIZE / 2 * scale);
|
||||
var geo = new StreamGeometry();
|
||||
using (var ctx = geo.Open()) {
|
||||
var points = new List<Point> {
|
||||
new(0, 0)
|
||||
};
|
||||
|
||||
ctx.BeginFigure(new((SIZE / 2 - POINT) * scale, 0), true, false);
|
||||
if (ot && it) {
|
||||
points.AddRange([new(SIZE / 2, -POINT / 2), new(SIZE / 2, POINT / 2), new(SIZE / 2 + POINT, 0)]);
|
||||
} else if (ot) {
|
||||
ctx.PolyLineTo([new(SIZE / 2 * scale, -POINT * scale), new((SIZE / 2 + POINT) * scale, 0)], true, false);
|
||||
} else if (it) {
|
||||
ctx.PolyLineTo([new(SIZE / 2 * scale, POINT * scale), new((SIZE / 2 + POINT) * scale, 0)], true, false);
|
||||
} else {
|
||||
ctx.ArcTo(new((SIZE / 2 + POINT) * scale, 0), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
}
|
||||
|
||||
ctx.ArcTo(new(SIZE * scale, (SIZE / 2 - POINT) * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
points.Add(new(SIZE, 0));
|
||||
if (or && ir) {
|
||||
points.AddRange([new(SIZE, SIZE / 2 - POINT), new(SIZE + POINT / 2, SIZE / 2), new(SIZE - POINT / 2, SIZE / 2), new(SIZE, SIZE / 2 + POINT)]);
|
||||
} else if (or) {
|
||||
ctx.PolyLineTo([new((SIZE + POINT) * scale, SIZE / 2 * scale), new(SIZE * scale, (SIZE / 2 + POINT) * scale)], true, false);
|
||||
} else if (ir) {
|
||||
ctx.PolyLineTo([new((SIZE - POINT) * scale, SIZE / 2 * scale), new(SIZE * scale, (SIZE / 2 + POINT) * scale)], true, false);
|
||||
} else {
|
||||
ctx.ArcTo(new(SIZE * scale, (SIZE / 2 + POINT) * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
}
|
||||
|
||||
ctx.ArcTo(new((SIZE / 2 + POINT) * scale, SIZE * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
points.Add(new(SIZE, SIZE));
|
||||
if (ob && ib) {
|
||||
points.AddRange([new(SIZE / 2 + POINT, SIZE), new(SIZE / 2, SIZE + POINT / 2), new(SIZE / 2, SIZE - POINT / 2), new(SIZE / 2 - POINT, SIZE)]);
|
||||
} else if (ob) {
|
||||
ctx.PolyLineTo([new(SIZE / 2 * scale, (SIZE + POINT) * scale), new((SIZE / 2 - POINT) * scale, SIZE * scale)], true, false);
|
||||
} else if (ib) {
|
||||
ctx.PolyLineTo([new(SIZE / 2 * scale, (SIZE - POINT) * scale), new((SIZE / 2 - POINT) * scale, SIZE * scale)], true, false);
|
||||
} else {
|
||||
ctx.ArcTo(new((SIZE / 2 - POINT) * scale, SIZE * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
}
|
||||
|
||||
ctx.ArcTo(new(0, (SIZE / 2 + POINT) * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
points.Add(new(0, SIZE));
|
||||
if (ol && il) {
|
||||
points.AddRange([new(0, SIZE / 2 + POINT), new(-POINT / 2, SIZE / 2), new(POINT / 2, SIZE / 2), new(0, SIZE / 2 - POINT)]);
|
||||
} else if (ol) {
|
||||
ctx.PolyLineTo([new(-POINT * scale, SIZE / 2 * scale), new(0, (SIZE / 2 - POINT) * scale)], true, false);
|
||||
} else if (il) {
|
||||
ctx.PolyLineTo([new(POINT * scale, SIZE / 2 * scale), new(0, (SIZE / 2 - POINT) * scale)], true, false);
|
||||
} else {
|
||||
ctx.ArcTo(new(0, (SIZE / 2 - POINT) * scale), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
}
|
||||
|
||||
ctx.ArcTo(new((SIZE / 2 - POINT) * scale, 0), size, 0, false, SweepDirection.Clockwise, true, false);
|
||||
}
|
||||
|
||||
_rect?.Points = [.. points.Select(p => new Point(p.X * scale, p.Y * scale))];
|
||||
_rect?.StrokeThickness = 2;
|
||||
_rect?.Data = geo;
|
||||
// [.. points.Select(p => new Point(p.X * scale, p.Y * scale))];
|
||||
_rect?.StrokeThickness = Graph.ToBorder(scale);
|
||||
_rect?.SetValue(Canvas.LeftProperty, (CenterX - SIZE / 2) * scale);
|
||||
_rect?.SetValue(Canvas.TopProperty, (CenterY - SIZE / 2) * scale);
|
||||
}
|
||||
@@ -89,7 +112,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
}
|
||||
|
||||
public void Update(bool isHovering, bool isPressed) {
|
||||
_rect?.Stroke = isHovering ? Brushes.Black : Brushes.Black;
|
||||
_rect?.Fill = Highlight ?? Brushes.DarkGray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
|
||||
protected SerialPort Serial;
|
||||
|
||||
public string PortName => Serial.PortName;
|
||||
public Status LastStatus { get; private set; }
|
||||
public T1Error LastError { get; private set; }
|
||||
|
||||
public T1(string portName, Parity parity = Parity.Odd) {
|
||||
Serial = new SerialPort(portName, 9600, parity, 8, StopBits.One) {
|
||||
Handshake = Handshake.None,
|
||||
NewLine = "\r",
|
||||
ReadTimeout = 1000,
|
||||
WriteTimeout = 1000,
|
||||
ReadTimeout = 500,
|
||||
WriteTimeout = 500,
|
||||
DtrEnable = true,
|
||||
RtsEnable = true,
|
||||
Encoding = Encoding.ASCII,
|
||||
@@ -97,14 +101,16 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public async Task<Status> StatusRead() {
|
||||
await SendCommand("ST", checksum: false);
|
||||
var (_, res) = await ReceiveResponse("ST");
|
||||
return new Status((Mode)(res[3] - '0'), ((res[0] - '0') << 4) | (res[1] - '0'));
|
||||
LastStatus = new Status((Mode)(res[3] - '0'), ((res[0] - '0') << 4) | (res[1] - '0'));
|
||||
return LastStatus;
|
||||
}
|
||||
|
||||
public async Task<T1Error> ErrorStatusRead() {
|
||||
await SendCommand("ER", checksum: false);
|
||||
var (_, res) = await ReceiveResponse("ER");
|
||||
var code = Convert.ToInt32(res, 10);
|
||||
return Enum.IsDefined(typeof(T1Error), code) ? (T1Error)code : T1Error.UNKNOWN_ERROR;
|
||||
LastError = Enum.IsDefined(typeof(T1Error), code) ? (T1Error)code : T1Error.UNKNOWN_ERROR;
|
||||
return LastError;
|
||||
}
|
||||
|
||||
public Task<ushort[]> DataRead(string register, int length) {
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<Version>0.0.3</Version>
|
||||
<Version>0.0.4</Version>
|
||||
<Product>Anlagensteuerung Pamhagen</Product>
|
||||
<AssemblyTitle>Anlagensteuerung Pamhagen</AssemblyTitle>
|
||||
<AssemblyName>PamhagenSysCtrl</AssemblyName>
|
||||
@@ -16,8 +16,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="10.0.10" />
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="10.0.11" />
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.11" />
|
||||
<Reference Include="PIEHidNetCore">
|
||||
<HintPath>PIEHidNetCore.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -227,7 +227,44 @@
|
||||
</Grid>
|
||||
|
||||
<StatusBar Grid.Row="2" BorderThickness="0,1,0,0" BorderBrush="Gray">
|
||||
|
||||
<StatusBar.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
</Grid>
|
||||
</ItemsPanelTemplate>
|
||||
</StatusBar.ItemsPanel>
|
||||
<StatusBarItem>
|
||||
<TextBlock>
|
||||
SPS-Verbindung: <Run x:Name="Status_Connection" Text="-"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<Separator Grid.Column="1"/>
|
||||
<StatusBarItem Grid.Column="2">
|
||||
<TextBlock>
|
||||
SPS-Status: <Run x:Name="Status_Plc" Text="-"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<Separator Grid.Column="3"/>
|
||||
<StatusBarItem Grid.Column="4">
|
||||
<TextBlock>
|
||||
Druckluft: <Run x:Name="Status_CompressedAir" Text="-"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<Separator Grid.Column="5"/>
|
||||
<StatusBarItem Grid.Column="6">
|
||||
<TextBlock>
|
||||
Ventile offen: <Run x:Name="Status_ValvesOpen" Text="-"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PamhagenSysCtrl.Helpers;
|
||||
using PamhagenSysCtrl.Helpers.Pipeline;
|
||||
using PIEHidNetCore;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -7,10 +8,15 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace PamhagenSysCtrl.Windows {
|
||||
public partial class PlantSchemeWindow : Window {
|
||||
public partial class PlantSchemeWindow : Window, PIEDataHandler, PIEErrorHandler {
|
||||
|
||||
private const double _minMove = 50;
|
||||
|
||||
private PIEDevice[]? devices;
|
||||
private PIEDevice? xbe24;
|
||||
private byte[]? lastData;
|
||||
private Color[] lastColor = new Color[24];
|
||||
|
||||
private readonly PamhagenGraph Graph;
|
||||
|
||||
private Point? _lastMousePos;
|
||||
@@ -45,37 +51,198 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
protected Dictionary<Button, (ISource Source, Pump Pump, ISink Sink)> FastSelectPaths;
|
||||
protected Dictionary<Button, (int KeyIdx, ISource Source, Pump Pump, ISink Sink)> FastSelectPaths;
|
||||
|
||||
public PlantSchemeWindow() {
|
||||
InitializeComponent();
|
||||
Menu_Help_CheckForUpdates.IsEnabled = App.Config.UpdateUrl != null;
|
||||
Graph = new();
|
||||
Graph.Draw(SchemeCanvas, RoundedScale);
|
||||
FastSelectPaths = new Dictionary<Button, (ISource, Pump, ISink)> {
|
||||
[FastSelectButton_MW1_Press1] = (Graph.MW1, Graph.MP1, Graph.Press1),
|
||||
[FastSelectButton_MW2_Press1] = (Graph.MW2, Graph.MP2, Graph.Press1),
|
||||
[FastSelectButton_MW1_Press2] = (Graph.MW1, Graph.MP1, Graph.Press2),
|
||||
[FastSelectButton_MW2_Press2] = (Graph.MW2, Graph.MP2, Graph.Press2),
|
||||
[FastSelectButton_MW1_Tank1] = (Graph.MW1, Graph.MP1, Graph.Tank1),
|
||||
[FastSelectButton_MW2_Tank1] = (Graph.MW2, Graph.MP2, Graph.Tank1),
|
||||
[FastSelectButton_MW1_Tank2] = (Graph.MW1, Graph.MP1, Graph.Tank2),
|
||||
[FastSelectButton_MW2_Tank2] = (Graph.MW2, Graph.MP2, Graph.Tank2),
|
||||
[FastSelectButton_MW1_Tank3] = (Graph.MW1, Graph.MP1, Graph.Tank3),
|
||||
[FastSelectButton_MW2_Tank3] = (Graph.MW2, Graph.MP2, Graph.Tank3),
|
||||
[FastSelectButton_MW1_Tank4] = (Graph.MW1, Graph.MP1, Graph.Tank4),
|
||||
[FastSelectButton_MW2_Tank4] = (Graph.MW2, Graph.MP2, Graph.Tank4),
|
||||
[FastSelectButton_MW1_Tank5] = (Graph.MW1, Graph.MP1, Graph.Tank5),
|
||||
[FastSelectButton_MW2_Tank5] = (Graph.MW2, Graph.MP2, Graph.Tank5),
|
||||
FastSelectPaths = new Dictionary<Button, (int, ISource, Pump, ISink)> {
|
||||
[FastSelectButton_MW1_Press1] = (12, Graph.MW1, Graph.MP1, Graph.Press1),
|
||||
[FastSelectButton_MW2_Press1] = (18, Graph.MW2, Graph.MP2, Graph.Press1),
|
||||
[FastSelectButton_MW1_Press2] = (13, Graph.MW1, Graph.MP1, Graph.Press2),
|
||||
[FastSelectButton_MW2_Press2] = (19, Graph.MW2, Graph.MP2, Graph.Press2),
|
||||
[FastSelectButton_MW1_Tank1] = (14, Graph.MW1, Graph.MP1, Graph.Tank1),
|
||||
[FastSelectButton_MW2_Tank1] = (20, Graph.MW2, Graph.MP2, Graph.Tank1),
|
||||
[FastSelectButton_MW1_Tank2] = (15, Graph.MW1, Graph.MP1, Graph.Tank2),
|
||||
[FastSelectButton_MW2_Tank2] = (21, Graph.MW2, Graph.MP2, Graph.Tank2),
|
||||
[FastSelectButton_MW1_Tank3] = (16, Graph.MW1, Graph.MP1, Graph.Tank3),
|
||||
[FastSelectButton_MW2_Tank3] = (22, Graph.MW2, Graph.MP2, Graph.Tank3),
|
||||
[FastSelectButton_MW1_Tank4] = (17, Graph.MW1, Graph.MP1, Graph.Tank4),
|
||||
[FastSelectButton_MW2_Tank4] = (23, Graph.MW2, Graph.MP2, Graph.Tank4),
|
||||
[FastSelectButton_MW1_Tank5] = (-1, Graph.MW1, Graph.MP1, Graph.Tank5),
|
||||
[FastSelectButton_MW2_Tank5] = (-1, Graph.MW2, Graph.MP2, Graph.Tank5),
|
||||
};
|
||||
App.Plant?.Update += OnUpdate;
|
||||
InitializePaths();
|
||||
|
||||
devices = PIEDevice.EnumeratePIE();
|
||||
|
||||
if (devices.Length > 0) {
|
||||
foreach (var device in devices) {
|
||||
// XBE-24 uses the Consumer HID usage page.
|
||||
if (device.HidUsagePage == 0x0C &&
|
||||
device.WriteLength > 1) {
|
||||
xbe24 = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (xbe24 == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Open the HID interface.
|
||||
xbe24.SetupInterface();
|
||||
|
||||
// Receive input reports.
|
||||
xbe24.SetDataCallback(this);
|
||||
|
||||
// Receive device errors, e.g. unplugging.
|
||||
xbe24.SetErrorCallback(this);
|
||||
|
||||
lastData = new byte[xbe24.ReadLength];
|
||||
|
||||
MessageBox.Show($"Connected: {xbe24.ProductString}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, EventArgs evt) {
|
||||
xbe24?.CloseInterface();
|
||||
xbe24 = null;
|
||||
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, int error) {
|
||||
if (xbe24 == null || sourceDevice != xbe24)
|
||||
return;
|
||||
Dispatcher.Invoke(() => {
|
||||
ProcessXbe24Data(data);
|
||||
});
|
||||
}
|
||||
|
||||
public void HandlePIEHidError(PIEDevice sourceDevice, int error) {
|
||||
if (xbe24 == null || sourceDevice != xbe24)
|
||||
return;
|
||||
Dispatcher.Invoke(() => {
|
||||
MessageBox.Show($"XBE-24: {error}", "XBE-24", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
});
|
||||
}
|
||||
|
||||
private void ProcessXbe24Data(byte[] data) {
|
||||
if (xbe24 == null || lastData == null)
|
||||
return;
|
||||
|
||||
// XBE-24 button data starts at byte 3.
|
||||
//
|
||||
// There are 4 button bytes:
|
||||
//
|
||||
// byte 3 -> buttons 0-5
|
||||
// byte 4 -> buttons 6-11
|
||||
// byte 5 -> buttons 12-17
|
||||
// byte 6 -> buttons 18-23
|
||||
|
||||
for (int column = 0; column < 4; column++) {
|
||||
for (int row = 0; row < 6; row++) {
|
||||
int button = column * 6 + row;
|
||||
byte mask = (byte)(1 << row);
|
||||
|
||||
bool nowPressed =
|
||||
(data[3 + column] & mask) != 0;
|
||||
|
||||
bool previouslyPressed =
|
||||
(lastData[3 + column] & mask) != 0;
|
||||
|
||||
// Button was just pressed.
|
||||
if (nowPressed && !previouslyPressed) {
|
||||
OnButtonPressed(button);
|
||||
}
|
||||
|
||||
// Button was just released.
|
||||
if (!nowPressed && previouslyPressed) {
|
||||
OnButtonReleased(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Array.Copy(data, lastData, xbe24.ReadLength);
|
||||
}
|
||||
|
||||
private void OnButtonPressed(int button) {
|
||||
// Your application logic goes here.
|
||||
// 0 6 12 18
|
||||
// 1 7 13 19
|
||||
// 2 8 14 20
|
||||
// 3 9 15 21
|
||||
// 4 10 16 22
|
||||
// 5 11 17 23
|
||||
|
||||
switch (button) {
|
||||
case 2: FastSelectButton_EntryTroughStop_Click(null, null); break;
|
||||
case 8: FastSelectButton_EntryTroughStart_Click(null, null); break;
|
||||
case 3: FastSelectButton_MW2_Click(null, null); break;
|
||||
case 9: FastSelectButton_MW1_Click(null, null); break;
|
||||
case 4:
|
||||
if (FastSelectButton_MP2_Forward.IsEnabled) {
|
||||
FastSelectButton_MP2_Forward_Click(null, null);
|
||||
} else {
|
||||
SetXbeLight(4, Color.FromRgb(255, 0, 0));
|
||||
}
|
||||
break;
|
||||
case 5: if (FastSelectButton_MP2_Stop.IsEnabled) FastSelectButton_MP2_Stop_Click(null, null); break;
|
||||
case 10:
|
||||
if (FastSelectButton_MP1_Forward.IsEnabled) {
|
||||
FastSelectButton_MP1_Forward_Click(null, null);
|
||||
} else {
|
||||
SetXbeLight(10, Color.FromRgb(255, 0, 0));
|
||||
}
|
||||
break;
|
||||
case 11: if (FastSelectButton_MP1_Stop.IsEnabled) FastSelectButton_MP1_Stop_Click(null, null); break;
|
||||
case 12: FastSelectButton_Click(FastSelectButton_MW1_Press1, null); break;
|
||||
case 13: FastSelectButton_Click(FastSelectButton_MW1_Press2, null); break;
|
||||
case 14: FastSelectButton_Click(FastSelectButton_MW1_Tank1, null); break;
|
||||
case 15: FastSelectButton_Click(FastSelectButton_MW1_Tank2, null); break;
|
||||
case 16: FastSelectButton_Click(FastSelectButton_MW1_Tank3, null); break;
|
||||
case 17: FastSelectButton_Click(FastSelectButton_MW1_Tank4, null); break;
|
||||
case 18: FastSelectButton_Click(FastSelectButton_MW2_Press1, null); break;
|
||||
case 19: FastSelectButton_Click(FastSelectButton_MW2_Press2, null); break;
|
||||
case 20: FastSelectButton_Click(FastSelectButton_MW2_Tank1, null); break;
|
||||
case 21: FastSelectButton_Click(FastSelectButton_MW2_Tank2, null); break;
|
||||
case 22: FastSelectButton_Click(FastSelectButton_MW2_Tank3, null); break;
|
||||
case 23: FastSelectButton_Click(FastSelectButton_MW2_Tank4, null); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonReleased(int button) {
|
||||
// Your application logic goes here.
|
||||
}
|
||||
|
||||
private void SetXbeLight(byte button, Color col, bool flashing = false) {
|
||||
if (xbe24 == null || lastColor[button] == col)
|
||||
return;
|
||||
|
||||
byte[] data = new byte[xbe24.WriteLength];
|
||||
for (byte i = 0; i < 2; i++) {
|
||||
data[0] = 0;
|
||||
data[1] = 0xA5; // Set RGB LED
|
||||
data[2] = button;
|
||||
data[3] = i; // upper + lower LED
|
||||
data[4] = col.R; // Red
|
||||
data[5] = col.G; // Green
|
||||
data[6] = col.B; // Blue
|
||||
data[7] = flashing ? (byte)1 : (byte)0;
|
||||
|
||||
int result;
|
||||
do {
|
||||
result = xbe24.WriteData(data);
|
||||
} while (result == 404);
|
||||
}
|
||||
|
||||
lastColor[button] = col;
|
||||
}
|
||||
|
||||
private void Menu_Settings_ManualControl_Changed(object sender, RoutedEventArgs evt) {
|
||||
App.Plant?.ManualControlMode = Menu_Settings_ManualControl.IsChecked;
|
||||
if (Menu_Settings_ManualControl.IsChecked) {
|
||||
@@ -211,7 +378,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs evt) {
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs? evt) {
|
||||
if (sender is not Button b || !FastSelectPaths.TryGetValue(b, out var val))
|
||||
return;
|
||||
|
||||
@@ -470,28 +637,32 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private static void SetFastSelectButton(Button b, int m, bool disabled = false) {
|
||||
private void SetFastSelectButton(Button b, byte? keyIdx, int m, bool disabled = false) {
|
||||
b.IsEnabled = !disabled;
|
||||
if (m == 1) {
|
||||
b.Background = Brushes.MintCream;
|
||||
b.BorderBrush = Brushes.DarkGreen;
|
||||
b.Foreground = Brushes.DarkGreen;
|
||||
if (keyIdx is byte k) SetXbeLight(k, Color.FromRgb(0, 255, 0));
|
||||
} else if (m == 2) {
|
||||
b.Background = Brushes.MistyRose;
|
||||
b.BorderBrush = Brushes.DarkRed;
|
||||
b.Foreground = Brushes.DarkRed;
|
||||
if (keyIdx is byte k) SetXbeLight(k, Color.FromRgb(255, 0, 0));
|
||||
} else {
|
||||
b.Background = Brushes.LightGray;
|
||||
b.BorderBrush = Brushes.DimGray;
|
||||
b.Foreground = Brushes.Black;
|
||||
if (keyIdx is byte k) SetXbeLight(k, disabled ? Color.FromRgb(8, 8, 8) : Color.FromRgb(255, 64, 64));
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFastSelectPathButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b) {
|
||||
private void UpdateFastSelectPathButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b, byte? keyIdx) {
|
||||
var e = FastSelectPaths[b];
|
||||
SetFastSelectButton(b,
|
||||
SetFastSelectButton(b, keyIdx,
|
||||
paths.Any(p => p.Start == e.Source && p.Hops.Last().Node == e.Sink) ? (hoverPathDeactivate?.Start == e.Source && hoverPathDeactivate?.Hops.Last().Node == e.Sink) ? 2 : 1 : 0,
|
||||
e.Pump.IsActive || Graph.GetFreePath([e.Source, e.Sink], overrideStart: true) == null);
|
||||
|
||||
}
|
||||
|
||||
private ISet<INode> UpdateScheme(Point pos, bool down) {
|
||||
@@ -502,20 +673,21 @@ namespace PamhagenSysCtrl.Windows {
|
||||
foreach (var n in Graph.Nodes) {
|
||||
if (n is Pump p) {
|
||||
p.Highlight = null;
|
||||
} else if (n is PipeJoin j) {
|
||||
j.Highlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Start, App.Plant?.IsTroughAugerActive ?? false ? 1 : 0, !(App.Plant?.TroughAugerHasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Stop, App.Plant?.IsTroughAugerActive ?? false ? 0 : 2);
|
||||
SetFastSelectButton(FastSelectButton_MW1, App.Plant?.IsMW1Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MW2, App.Plant?.IsMW2Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP1_Forward, App.Plant?.MP1 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP1HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP1_Stop, App.Plant?.MP1 == MotorState.Halt ? 2 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP2_Forward, App.Plant?.MP2 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP2HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP2_Stop, App.Plant?.MP2 == MotorState.Halt ? 2 : 0);
|
||||
foreach (var b in FastSelectPaths) {
|
||||
SetFastSelectButton(b.Key, 0, false);
|
||||
}
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Start, 8, App.Plant?.IsTroughAugerActive ?? false ? 1 : 0, !(App.Plant?.TroughAugerHasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Stop, 2, App.Plant?.IsTroughAugerActive ?? false ? 0 : 2);
|
||||
SetFastSelectButton(FastSelectButton_MW1, 9, App.Plant?.IsMW1Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MW2, 3, App.Plant?.IsMW2Selected ?? false ? 1 : 0);
|
||||
|
||||
SetFastSelectButton(FastSelectButton_MP1_Forward, 10, App.Plant?.MP1 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP1HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP1_Stop, 11, App.Plant?.MP1 == MotorState.Halt ? 2 : 0);
|
||||
|
||||
SetFastSelectButton(FastSelectButton_MP2_Forward, 4, App.Plant?.MP2 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP2HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP2_Stop, 5, App.Plant?.MP2 == MotorState.Halt ? 2 : 0);
|
||||
|
||||
_hover = Graph.GetHover(pos.X, pos.Y, RoundedScale);
|
||||
var hoverButtons = FastSelectPaths.Where(b => b.Key.IsMouseOver).ToDictionary();
|
||||
@@ -582,10 +754,13 @@ namespace PamhagenSysCtrl.Windows {
|
||||
MP2_Target.FontSize = len2 > 24 ? 8 : len2 > 20 ? 10 : len2 > 16 ? 12 : len2 > 12 ? 14 : 16;
|
||||
}
|
||||
|
||||
foreach (var b in FastSelectPaths) {
|
||||
//SetFastSelectButton(b.Key, b.Value.KeyIdx == -1 ? null : (byte)b.Value.KeyIdx, 0, false);
|
||||
}
|
||||
var paths = Graph.SelectedPaths;
|
||||
if (HoveringPath is Path hp) paths = paths.Append(hp);
|
||||
foreach (var b in FastSelectPaths.Keys) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b);
|
||||
foreach (var b in FastSelectPaths) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b.Key, b.Value.KeyIdx == -1 ? null : (byte)b.Value.KeyIdx);
|
||||
}
|
||||
|
||||
Graph.Update(_hover, down);
|
||||
@@ -593,7 +768,12 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
|
||||
public void OnUpdate(object? sender, PlantEventArgs? evt) {
|
||||
if (sender is not PamhagenPlant plant) return;
|
||||
if (App.Plant is PamhagenPlant p) {
|
||||
Status_Connection.Text = $"Ja ({p.PlcPortName}" + (p.LastRttNs != null ? $", {p.LastRttNs / 1000000.0:N0} ms" : "") + ")";
|
||||
Status_Plc.Text = $"{p.LastPlcStatus?.Mode} ({p.LastPlcStatus?.Flags:X3}) / {p.LastPlcError?.GetName()} ({(int?)p.LastPlcError:0000})";
|
||||
Status_CompressedAir.Text = Enumerable.Range(1, 57).Any(p.IsValveClosed) ? "Ein" : Enumerable.Range(1, 57).Any(p.WantValveClosed) ? "Aus" : "?";
|
||||
Status_ValvesOpen.Text = Enumerable.Range(1, 57).Count(p.IsValveOpen) + " / " + Enumerable.Range(1, 57).Count(p.WantValveOpen) + " / 57";
|
||||
}
|
||||
UpdateScheme(Mouse.GetPosition(SchemeCanvas), Mouse.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ About
|
||||
**Product:** Anlagensteuerung Pamhagen
|
||||
**Description:** Interface to a LPC and graphical user interface for controlling the plant/system
|
||||
**Type:** HMI and PLC Control Software
|
||||
**Version:** 0.0.3 ([Changelog](./CHANGELOG.md))
|
||||
**Version:** 0.0.4 ([Changelog](./CHANGELOG.md))
|
||||
**License:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Source code:** https://git.necronda.net/winzer/pamhagen-sysctrl
|
||||
**Developement period:** 2026
|
||||
@@ -30,7 +30,7 @@ Packaging: [WiX Toolset](https://www.firegiant.com/wixtoolset/)
|
||||
**Produkt:** Anlagensteuerung Pamhagen
|
||||
**Beschreibung:** Schnittstelle zu einer SPS und grafische Benutzeroberfläche für die Steuerung der Anlage
|
||||
**Typ:** HMI- und SPS-Steuerungssoftware
|
||||
**Version:** 0.0.3 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||
**Version:** 0.0.4 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||
**Lizenz:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Quellcode:** https://git.necronda.net/winzer/pamhagen-sysctrl
|
||||
**Entwicklungszeitraum:** 2026
|
||||
|
||||
Reference in New Issue
Block a user