diff --git a/Samples/pac4200.td.jsonld b/Samples/pac4200.td.jsonld
index 63f509f..9c721c2 100644
--- a/Samples/pac4200.td.jsonld
+++ b/Samples/pac4200.td.jsonld
@@ -20,7 +20,7 @@
"Thing"
],
"name": "modbus-pac4200-sn324",
- "base": "modbus+tcp://192.168.178.100:502/1",
+ "base": "modbus+tcp://192.168.178.94:502/1",
"title": "Siemens SENTRON PAC4200",
"properties": {
"VoltageL1-N": {
diff --git a/UAEdgeTranslator.csproj b/UAEdgeTranslator.csproj
index 01841c8..51cf206 100644
--- a/UAEdgeTranslator.csproj
+++ b/UAEdgeTranslator.csproj
@@ -33,4 +33,8 @@
+
+
+
+
diff --git a/UANodeManager.cs b/UANodeManager.cs
index c4b23cc..403ebd3 100644
--- a/UANodeManager.cs
+++ b/UANodeManager.cs
@@ -424,6 +424,8 @@ private bool CreateAssetNode(string assetName, out NodeState assetNode)
return StatusCodes.BadNodeIdUnknown;
}
+ string assetName = asset.DisplayName.Text;
+
_fileManagers.Remove(assetId);
DeleteNode(SystemContext, assetId);
@@ -431,22 +433,33 @@ private bool CreateAssetNode(string assetName, out NodeState assetNode)
IEnumerable WoTFiles = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "settings"), "*.jsonld");
foreach (string file in WoTFiles)
{
- try
+ string fileName = Path.GetFileNameWithoutExtension(file);
+ if (fileName == assetName)
{
- string fileName = Path.GetFileNameWithoutExtension(file);
- if (fileName == NodeId.ToExpandedNodeId(assetId, Server.NamespaceUris).ToString())
- {
- File.Delete(file);
+ File.Delete(file);
+ }
+ }
- _ = Task.Run(() => HandleServerRestart());
+ if (_tags.ContainsKey(assetName))
+ {
+ _tags.Remove(assetName);
+ }
- return ServiceResult.Good;
- }
+ if (_assets.ContainsKey(assetName))
+ {
+ _assets.Remove(assetName);
+ }
+
+ int i = 0;
+ while (i < _uaVariables.Count)
+ {
+ if (_uaVariables.Keys.ToArray()[i].StartsWith(assetName))
+ {
+ _uaVariables.Remove(_uaVariables.Keys.ToArray()[i]);
}
- catch (Exception ex)
+ else
{
- Log.Logger.Error(ex.Message, ex);
- return new ServiceResult(ex);
+ i++;
}
}
@@ -459,9 +472,11 @@ public void AddNodesForWoTProperties(NodeState parent, string contents)
// parse WoT TD file contents
ThingDescription td = JsonConvert.DeserializeObject(contents);
- List namespaceUris = new(NamespaceUris)
+ string newNamespace = "http://opcfoundation.org/UA/" + td.Name + "/";
+ List namespaceUris = new(NamespaceUris);
+ if (!namespaceUris.Contains(newNamespace))
{
- "http://opcfoundation.org/UA/" + td.Name + "/"
+ namespaceUris.Add(newNamespace);
};
foreach (object ns in td.Context)
@@ -537,8 +552,10 @@ private void AddNodeForModbusRegister(NodeState assetFolder, KeyValuePair 0)
{
- ExtensionObject complexTypeInstance = new();
- complexTypeInstance.TypeId = opcuaType.NodeId;
+ ExtensionObject complexTypeInstance = new()
+ {
+ TypeId = opcuaType.NodeId
+ };
BinaryEncoder encoder = new(ServiceMessageContext.GlobalContext);
foreach (StructureField field in ((StructureDefinition)opcuaType?.DataTypeDefinition?.Body).Fields)
@@ -640,10 +657,9 @@ private string AssetConnectionTest(ThingDescription td, out byte unitId)
assetInterface = client;
}
- string assetId = td.Title + " [" + td.Name + "]";
- _assets.Add(assetId, assetInterface);
+ _assets.Add(td.Name, assetInterface);
- return assetId;
+ return td.Name;
}
private ExpandedNodeId ParseExpandedNodeId(string nodeString)
@@ -701,7 +717,8 @@ private BaseDataVariableState CreateVariable(NodeState parent, string name, Expa
private void UpdateNodeValues(object assetNameObject)
{
- while (!_shutdown)
+ bool assetDeleted = false;
+ while (!_shutdown && !assetDeleted)
{
Thread.Sleep(1000);
@@ -710,7 +727,8 @@ private void UpdateNodeValues(object assetNameObject)
string assetId = (string)assetNameObject;
if (string.IsNullOrEmpty(assetId) || !_tags.ContainsKey(assetId) || !_assets.ContainsKey(assetId))
{
- throw new Exception("Cannot find asset: " + assetId);
+ assetDeleted = true;
+ continue;
}
foreach (AssetTag tag in _tags[assetId])