From 9365e076e7e7b3a249fa229071cf3588c0f883f8 Mon Sep 17 00:00:00 2001 From: Michael Hoffmeister Date: Sat, 6 Jan 2024 12:48:42 +0100 Subject: [PATCH] * modbus v0.1 working --- .../AidInterfaceStatus.cs | 2 +- .../AssetInterfaceAnyUiControl.cs | 49 +++++++++++++++++-- src/AasxPluginAssetInterfaceDesc/Plugin.cs | 2 +- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs b/src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs index cd804d39..69dfbeb1 100644 --- a/src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs +++ b/src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs @@ -169,7 +169,7 @@ public void UpdateItemValue(AidModbusConnection conn, AidIfxItemStatus item) if (item.FormData.Modbus_function.Trim().ToLower() == "readholdingregisters") { // readHoldingRegisters - id = conn.Client.ReadHoldingRegisters(99, address, quantity).ToArray(); + id = conn.Client.ReadHoldingRegisters(99, address, 2 * quantity).ToArray(); // time conn.LastActive = DateTime.Now; } diff --git a/src/AasxPluginAssetInterfaceDesc/AssetInterfaceAnyUiControl.cs b/src/AasxPluginAssetInterfaceDesc/AssetInterfaceAnyUiControl.cs index aa2ddcf2..0cb6750b 100644 --- a/src/AasxPluginAssetInterfaceDesc/AssetInterfaceAnyUiControl.cs +++ b/src/AasxPluginAssetInterfaceDesc/AssetInterfaceAnyUiControl.cs @@ -37,6 +37,7 @@ public class AssetInterfaceAnyUiControl private AssetInterfaceOptions _options = null; private PluginEventStack _eventStack = null; private AnyUiStackPanel _panel = null; + private AasxPluginBase _plugin = null; private AidAllInterfaceStatus _allInterfaceStatus = null; @@ -73,6 +74,7 @@ public void Start( AssetInterfaceOptions theOptions, PluginEventStack eventStack, AnyUiStackPanel panel, + AasxPluginBase plugin, AidAllInterfaceStatus ifxStatus) { // internal members @@ -82,6 +84,7 @@ public void Start( _options = theOptions; _eventStack = eventStack; _panel = panel; + _plugin = plugin; _allInterfaceStatus = ifxStatus; // some required logos @@ -112,6 +115,7 @@ public static AssetInterfaceAnyUiControl FillWithAnyUiControls( AssetInterfaceOptions options, PluginEventStack eventStack, object opanel, + AasxPluginBase plugin, AidAllInterfaceStatus ifxStatus) { // access @@ -126,7 +130,7 @@ public static AssetInterfaceAnyUiControl FillWithAnyUiControls( // factory this object var aidCntl = new AssetInterfaceAnyUiControl(); - aidCntl.Start(log, package, sm, options, eventStack, panel, ifxStatus); + aidCntl.Start(log, package, sm, options, eventStack, panel, plugin, ifxStatus); // return shelf return aidCntl; @@ -239,11 +243,40 @@ protected void RenderPanelInner( var grid = view.Add(uitk.AddSmallGrid(rows: 3, cols: 2, colWidths: new[] { "110:", "*" })); uitk.AddSmallLabelTo(grid, 0, 0, content: "Debug:"); + AnyUiUIElement.RegisterControl( uitk.AddSmallButtonTo(grid, 0, 1, margin: new AnyUiThickness(2), setHeight: 21, padding: new AnyUiThickness(2, 0, 2, 0), - content: "Test .."), + content: "Create status items"), + (o) => + { + try + { + // build up data structures + _allInterfaceStatus.InterfaceStatus = PrepareAidInformation(sm); + + // trigger a complete redraw, as the regions might emit + // events or not, depending on this flag + return new AnyUiLambdaActionPluginUpdateAnyUi() + { + PluginName = _plugin?.GetPluginName(), + UpdateMode = AnyUiRenderMode.All, + UseInnerGrid = true + }; + } + catch (Exception ex) + { + ; + } + return new AnyUiLambdaActionNone(); + }); + + AnyUiUIElement.RegisterControl( + uitk.AddSmallButtonTo(grid, 1, 1, + margin: new AnyUiThickness(2), setHeight: 21, + padding: new AnyUiThickness(2, 0, 2, 0), + content: "Single update .."), (o) => { try @@ -253,6 +286,15 @@ protected void RenderPanelInner( //var byteData = client.ReadHoldingRegisters(99, 1, 8); _allInterfaceStatus?.UpdateValuesSingleShot(); + + // trigger a complete redraw, as the regions might emit + // events or not, depending on this flag + return new AnyUiLambdaActionPluginUpdateAnyUi() + { + PluginName = _plugin?.GetPluginName(), + UpdateMode = AnyUiRenderMode.All, + UseInnerGrid = true + }; } catch (Exception ex) { @@ -261,8 +303,7 @@ protected void RenderPanelInner( return new AnyUiLambdaActionNone(); }); - // get SM data and - _allInterfaceStatus.InterfaceStatus = PrepareAidInformation(sm); + // get SM data and RenderTripleRowData(view, uitk, _allInterfaceStatus.InterfaceStatus); } diff --git a/src/AasxPluginAssetInterfaceDesc/Plugin.cs b/src/AasxPluginAssetInterfaceDesc/Plugin.cs index 89fd37de..8f6f15c7 100644 --- a/src/AasxPluginAssetInterfaceDesc/Plugin.cs +++ b/src/AasxPluginAssetInterfaceDesc/Plugin.cs @@ -123,7 +123,7 @@ public class Session : PluginSessionBase // create session and call var session = _sessions.CreateNewSession(args[4]); session.AnyUiControl = AasxPluginAssetInterfaceDescription.AssetInterfaceAnyUiControl.FillWithAnyUiControls( - _log, args[0], args[1], _options, _eventStack, args[2], _allInterfaceStatus); + _log, args[0], args[1], _options, _eventStack, args[2], this, _allInterfaceStatus); // give object back var res = new AasxPluginResultBaseObject();