Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Nov 25, 2023
1 parent 98297d8 commit 3eacea9
Show file tree
Hide file tree
Showing 27 changed files with 1,101 additions and 319 deletions.
55 changes: 55 additions & 0 deletions adapter/MTConnect-Adapter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using MTConnect.Assets.CuttingTools.Measurements;
using MTConnect.Assets.CuttingTools;

namespace MTConnect.Applications
{
Expand Down Expand Up @@ -41,6 +43,7 @@ public static void Main(string[] args)

var x = 0;
var i = 0;
var j = 0d;

while (true)
{
Expand Down Expand Up @@ -87,6 +90,10 @@ public static void Main(string[] args)
app.DataSource.AddObservation(timeSeries);


app.DataSource.AddAsset(CuttingTool(j));
j += 23.3455;


//switch (i)
//{
// case 0:
Expand Down Expand Up @@ -117,6 +124,54 @@ public static void Main(string[] args)

}

public static CuttingToolAsset CuttingTool(double toolLifeValue)
{
var tool = new CuttingToolAsset();
tool.SerialNumber = "12345678946";
tool.AssetId = "5.12";
tool.ToolId = "12";

var cuttingToolLifeCycle = new CuttingToolLifeCycle
{
//Location = new Location
//{
// Type = LocationType.SPINDLE
//},
ProgramToolNumber = "12",
ProgramToolGroup = "5"
};

var measurements = new List<IMeasurement>();
measurements.Add(new FunctionalLengthMeasurement(7.6543));
measurements.Add(new CuttingDiameterMaxMeasurement(0.375));
cuttingToolLifeCycle.Measurements = measurements;


//tool.CuttingToolLifeCycle.CuttingItems.Add(new CuttingItem
//{
// ItemId = "12.1",
// Indices = "1",
//});

var cutterStatuses = new List<CutterStatusType>();
cutterStatuses.Add(CutterStatusType.AVAILABLE);
cutterStatuses.Add(CutterStatusType.NEW);
cutterStatuses.Add(CutterStatusType.MEASURED);
cuttingToolLifeCycle.CutterStatus = cutterStatuses;

var toolLife = new ToolLife();
toolLife.Value = toolLifeValue;
cuttingToolLifeCycle.ToolLife = new IToolLife[] { toolLife };

//tool.CuttingToolLifeCycle.ToolLife = new ToolLife();

tool.CuttingToolLifeCycle = cuttingToolLifeCycle;

tool.Timestamp = DateTime.Now;

return tool;
}


private static void PrintConsoleHeader()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public MTConnectAdapterApplication(IMTConnectDataSource dataSource)
if (_dataSource != null)
{
_dataSource.ObservationAdded += DataSourceObservationAdded;
_dataSource.AssetAdded += DataSourceAssetAdded;
}

ServiceLabel = DefaultServiceLabel;
Expand Down Expand Up @@ -292,6 +293,8 @@ public void StartAdapter(IAdapterApplicationConfiguration configuration, bool ve
{
var adapter = new MTConnectAdapter(configuration.WriteInterval, configuration.EnableBuffer);
adapter.WriteObservationsFunction = module.AddObservations;
adapter.WriteAssetsFunction = module.AddAssets;
adapter.WriteDevicesFunction = module.AddDevices;
adapter.Start();

_adapters.Remove(module.Id);
Expand Down Expand Up @@ -475,12 +478,25 @@ private void DataSourceObservationAdded(object sender, IObservationInput observa
{
foreach (var adapter in adapters)
{
//adapter.Value.SendObservation(observation);
adapter.Value.AddObservation(observation);
}
}
}

private void DataSourceAssetAdded(object sender, IAssetInput asset)
{
Dictionary<string, IMTConnectAdapter> adapters;
lock (_lock) adapters = _adapters;

if (!adapters.IsNullOrEmpty())
{
foreach (var adapter in adapters)
{
adapter.Value.AddAsset(asset);
}
}
}

#endregion

#region "Help"
Expand Down
3 changes: 1 addition & 2 deletions adapter/Modules/MTConnect.NET-MQTT-AdapterModule/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using MQTTnet;
using MQTTnet.Client;
using MTConnect.Adapters;
using MTConnect.Assets;
using MTConnect.Configurations;
using MTConnect.Devices;
using MTConnect.Input;
Expand Down Expand Up @@ -180,7 +179,7 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
return true;
}

public override bool AddAssets(IEnumerable<IAsset> assets)
public override bool AddAssets(IEnumerable<IAssetInput> assets)
{
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion adapter/Modules/MTConnect.NET-SHDR-AdapterModule/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
return true;
}

public override bool AddAssets(IEnumerable<IAsset> assets)
public override bool AddAssets(IEnumerable<IAssetInput> assets)
{
foreach (var asset in assets)
{
var shdrModel = new ShdrAsset(asset.Asset);
var shdrLine = shdrModel.ToString();
WriteLine(shdrLine);
Console.WriteLine(shdrLine);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static void Render(MTConnectModel mtconnectModel, string outputPath)
break;
case "Assets.CuttingTools.CuttingToolLifeCycle": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.CuttingItem": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.ToolLife": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.Measurement":
((ClassModel)template).IsPartial = true;
((ClassModel)template).IsAbstract = false;
Expand Down
22 changes: 22 additions & 0 deletions src/MTConnect.NET-Common/Adapters/IMTConnectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using MTConnect.Input;
using System;
using System.Collections.Generic;

namespace MTConnect.Adapters
{
Expand Down Expand Up @@ -83,5 +84,26 @@ public interface IMTConnectAdapter
bool SendObservation(string dataItemId, object value, long timestamp);

bool SendObservation(IObservationInput observation);


/// <summary>
/// Add the specified MTConnect Asset
/// </summary>
/// <param name="asset">The Asset to add</param>
void AddAsset(IAssetInput asset);

/// <summary>
/// Remove the specified Asset using the SHDR command @REMOVE_ASSET@
/// </summary>
/// <param name="assetId">The AssetId of the Asset to remove</param>
/// <param name="timestamp">The timestamp to send as part of the SHDR command</param>
void RemoveAsset(string assetId, long timestamp = 0);

/// <summary>
/// Remove all Assets of the specified Type using the SHDR command @REMOVE_ALL_ASSETS@
/// </summary>
/// <param name="assetType">The Type of the Assets to remove</param>
/// <param name="timestamp">The timestamp to send as part of the SHDR command</param>
void RemoveAllAssets(string assetType, long timestamp = 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IMTConnectAdapterModule

bool AddObservations(IEnumerable<IObservationInput> observations);

bool AddAssets(IEnumerable<IAsset> assets);
bool AddAssets(IEnumerable<IAssetInput> assets);

bool AddDevices(IEnumerable<IDevice> devices);
}
Expand Down
20 changes: 0 additions & 20 deletions src/MTConnect.NET-Common/Adapters/IMTConnectAdapterPipeline.cs

This file was deleted.

Loading

0 comments on commit 3eacea9

Please sign in to comment.