Skip to content

Commit

Permalink
* add SMT HierStruct V1.1
Browse files Browse the repository at this point in the history
* fix BOM plugin
  • Loading branch information
festo-i40 committed Jul 25, 2024
1 parent a8d4ffa commit 0178fbc
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 78 deletions.
12 changes: 9 additions & 3 deletions src/AasxCsharpLibrary/Extensions/ExtendSubmodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,21 @@ public static Key GetSemanticKey(this Submodel submodel)

/// <summary>
/// If instance, return semanticId as one key.
/// If template, return identification as key.
/// If template, return either semanticId or identification as key.
/// </summary>
public static IReference GetSemanticRef(this Submodel submodel)
{
if (submodel.Kind == ModellingKind.Instance)
return submodel.SemanticId;
else
return new Reference(ReferenceTypes.ModelReference, new[] {
new Key(KeyTypes.Submodel, submodel.Id) }.Cast<IKey>().ToList());
{
// MIHO updated this on 2024-07-25
if (submodel.SemanticId?.IsValid() == true)
return submodel.SemanticId.Copy();
else
return new Reference(ReferenceTypes.ModelReference, new[] {
new Key(KeyTypes.Submodel, submodel.Id) }.Cast<IKey>().ToList());
}
}

public static List<ISubmodelElement> SmeForWrite(this Submodel submodel)
Expand Down
1 change: 1 addition & 0 deletions src/AasxPackageExplorer/AasxPackageExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="SSharp.Net" Version="1.0.1" />
<PackageReference Include="Workstation.UaClient" Version="3.2.3" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
Expand Down
1 change: 1 addition & 0 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Workstation.ServiceModel.Ua;
using static AasxPackageLogic.DispEditHelperBasics;
using Aas = AasCore.Aas3_0;
using ExhaustiveMatch = ExhaustiveMatching.ExhaustiveMatch;
Expand Down
4 changes: 2 additions & 2 deletions src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_ProductChangeNotification\\IDTA_02036-1-0_SMT_ProductChangeNotification_Examples_v08.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_ProductChangeNotification\\SMT_ProductChangeNotification_Draft_v20_spiel.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_ProductChangeNotification\\IDTA_02036-1-0_SMT_ProductChangeNotification_Examples_v08.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
"AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\00_FestoDemoBox-Module-2-Kopie.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work_spiel.aasx",
Expand All @@ -54,7 +54,7 @@
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\bugfix\\techdata-prod-class-larger.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\2023_AID1.0_Template_Rework_MIHO.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\aid-test-2.aasx",
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\aid-test-3_new_opcua.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\aid-test-3_new_opcua.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\Aid-HMI-2024_v1.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\aid\\robotic_cell_for_demo_suitcase_new-v3.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\IDTA 02006-2-1_Template_Digital Nameplate_V3_Demo_ExportSMT - Kopie.aasx",
Expand Down
32 changes: 26 additions & 6 deletions src/AasxPluginAssetInterfaceDesc/AasOpcUaClient2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ This source code may use other Open Source software components (see LICENSE.txt)

namespace AasxPluginAssetInterfaceDescription
{
public class HandledNodeId
{
public uint Handle;
public NodeId Nid;

public HandledNodeId() { }

public HandledNodeId(uint handle, NodeId nid)
{
Handle = handle;
Nid = nid;
}
}

public class AasOpcUaClient2
{
const int ReconnectPeriod = 10;
Expand Down Expand Up @@ -124,7 +138,7 @@ public NodeId CreateNodeId(string nodeName, string ns)

public NodeId ParseAndCreateNodeId(string input)
{
throw new NotImplementedException();
return NodeId.Parse(input);
}

public async Task<string> ReadSubmodelElementValueAsStringAsync(string nodeName)
Expand Down Expand Up @@ -186,8 +200,8 @@ public async Task<DataValue> ReadNodeIdAsync(NodeId nid)
}

public async Task<IDisposable> SubscribeNodeIdsAsync(
NodeId[] nids,
Action<NodeId, string> handler,
HandledNodeId[] nids,
Action<uint, DataValue> handler,
int publishingInterval = 1000)
{
if (_channel == null || nids == null || _channel.State != CommunicationState.Opened || handler == null)
Expand All @@ -213,13 +227,13 @@ public async Task<IDisposable> SubscribeNodeIdsAsync(
{
// NodeId = NodeId.Parse("ns=4;s=|var|CODESYS Control Win V3.Application.PLC_PRG.step_curr"),
// NodeId = NodeId.Parse("ns=4;s=|var|CODESYS Control Win V3.Application.PLC_PRG.cycle_countdown"),
NodeId = nid,
NodeId = nid.Nid,
AttributeId = AttributeIds.Value
},
MonitoringMode = MonitoringMode.Reporting,
RequestedParameters = new MonitoringParameters
{
ClientHandle = 1201,
ClientHandle = nid.Handle,
SamplingInterval = -1,
QueueSize = 0,
DiscardOldest = true
Expand Down Expand Up @@ -251,10 +265,16 @@ public async Task<IDisposable> SubscribeNodeIdsAsync(
{
foreach (var min in dcn.MonitoredItems)
{
handler?.Invoke(null, "");
if (min.Value == null)
continue;
handler?.Invoke(min.ClientHandle, min.Value);
Console.WriteLine($"sub: {pr.SubscriptionId}; handle: {min.ClientHandle}; value: {min.Value}");
}
}
},
ex =>
{
Console.WriteLine($"IObserver handled exception '{ex.GetType()}'. {ex.Message}");
});

return token;
Expand Down
4 changes: 3 additions & 1 deletion src/AasxPluginAssetInterfaceDesc/AidHttpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public class AidHttpConnection : AidBaseConnection
{
public HttpClient Client;

override public bool Open()
override public async Task<bool> Open()
{
// pretty simple
Client = new HttpClient();

if (TimeOutMs >= 10)
Client.Timeout = new TimeSpan(0, 0, 0, 0, milliseconds: (int)TimeOutMs);

await Task.Yield();

return true;
}

Expand Down
47 changes: 32 additions & 15 deletions src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ public class AidBaseConnection

public Action<Aas.ISubmodelElement> AnimateSingleValueChange = null;

virtual public bool Open()
virtual public async Task<bool> Open()
{
await Task.Yield();
return false;
}

Expand Down Expand Up @@ -489,7 +490,7 @@ public UInt64 SumValueChanges()
/// <summary>
/// Will connect to each target once, get values and will disconnect again.
/// </summary>
public void UpdateValuesSingleShot()
public async Task UpdateValuesSingleShot()
{
// access allowed
if (ContinousRun)
Expand Down Expand Up @@ -517,7 +518,7 @@ public void UpdateValuesSingleShot()
continue;

// open it
if (!conn.Open())
if (!(await conn.Open()))
continue;
ifc.Connection = conn;

Expand All @@ -526,18 +527,34 @@ public void UpdateValuesSingleShot()
ifc.ValueChanges += (UInt64)conn.UpdateItemValue(item);

// go thru all items (async)
var task = Task.Run(async () =>
if (false)
{
// see: https://www.hanselman.com/blog/parallelforeachasync-in-net-6
await Parallel.ForEachAsync(
ifc.Items.Values,
new ParallelOptions() { MaxDegreeOfParallelism = 10 },
async (item, token) =>
{
ifc.ValueChanges += (UInt64)(await ifc.Connection.UpdateItemValueAsync(item));
});
});
task.Wait();
var clientDescription = new Workstation.ServiceModel.Ua.ApplicationDescription
{
ApplicationName = "AASX Package Explorer",
ApplicationUri = $"urn:{System.Net.Dns.GetHostName()}:AASX Package Explorer",
ApplicationType = Workstation.ServiceModel.Ua.ApplicationType.Client
};

var _channel = new Workstation.ServiceModel.Ua.Channels.ClientSessionChannel(
clientDescription,
null, // no x509 certificates
new Workstation.ServiceModel.Ua.AnonymousIdentity(),
"opc.tcp://localhost:4840/freeopcua/server/",
Workstation.ServiceModel.Ua.SecurityPolicyUris.None); // no encryption

// try opening a session and reading a few nodes.
await _channel.OpenAsync();
}

// see: https://www.hanselman.com/blog/parallelforeachasync-in-net-6
await Parallel.ForEachAsync(
ifc.Items.Values,
new ParallelOptions() { MaxDegreeOfParallelism = 10 },
async (item, token) =>
{
ifc.ValueChanges += (UInt64)(await ifc.Connection.UpdateItemValueAsync(item));
});
}
}

Expand Down Expand Up @@ -588,7 +605,7 @@ public async Task StartContinousRunAsync()
continue;

// open it
if (!conn.Open())
if (!(await conn.Open()))
{
ifc.SetLogLine(StoredPrint.Color.Red, $"Endpoint connot be opened: {ifc.EndpointBase}.");
continue;
Expand Down
5 changes: 4 additions & 1 deletion src/AasxPluginAssetInterfaceDesc/AidModbusConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AidModbusConnection : AidBaseConnection
{
public ModbusTcpClient Client;

override public bool Open()
override public async Task<bool> Open()
{
try
{
Expand All @@ -38,6 +38,9 @@ override public bool Open()
Client.ConnectTimeout = (int)TimeOutMs;
Client.Connect(new IPEndPoint(IPAddress.Parse(TargetUri.Host), TargetUri.Port));
LastActive = DateTime.Now;

await Task.Yield();

return true;
} catch (Exception ex)
{
Expand Down
6 changes: 2 additions & 4 deletions src/AasxPluginAssetInterfaceDesc/AidMqttConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AidMqttConnection : AidBaseConnection

protected Dictionary<string, string> _subscribedTopics = new Dictionary<string, string>();

override public bool Open()
override public async Task<bool> Open()
{
try
{
Expand All @@ -52,9 +52,7 @@ override public bool Open()
.Build();

// need to switch to async
var task = Task.Run(() => Client.ConnectAsync(options));
task.Wait();
var res = task.Result;
await Client.ConnectAsync(options);

// no subscriptions, yet
_subscribedTopics.Clear();
Expand Down
Loading

0 comments on commit 0178fbc

Please sign in to comment.