Skip to content

Commit 16de351

Browse files
Added IgnoreHeartbeatOnChange configuration parameter for SHDR Adapters to toggle whether PING data is sent even if data has been received.
1 parent f52f483 commit 16de351

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

agent/Modules/MTConnect.NET-AgentModule-ShdrAdapter/Module.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private void AddAdapter(IShdrAdapterClientConfiguration configuration, IDevice d
106106

107107
// Create new SHDR Adapter Client to read from SHDR stream
108108
var adapterClient = new ShdrAdapterClient(configuration, _mtconnectAgent, device, idSuffix);
109+
adapterClient.IgnoreHeartbeatOnChange = configuration.IgnoreHeartbeatOnChange;
109110
_adapters.Add(adapterClient);
110111

111112
adapterClient.Connected += AdapterConnected;

agent/Modules/MTConnect.NET-AgentModule-ShdrAdapter/README-Nuget.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ modules:
3636

3737
* `outputConnectionInformation` - Gets or Sets whether the Connection Information (Host / Port) is output to the Agent to be collected by a client
3838

39+
* `ignoreHeartbeatOnChange` - Gets or Sets whether Heartbeat PING requests are not sent if data has been received within the Heartbeat period. Default is TRUE
40+
3941

4042
## Contribution / Feedback
4143
- Please use the [Issues](https://github.com/TrakHound/MTConnect.NET/issues) tab to create issues for specific problems that you may encounter

agent/Modules/MTConnect.NET-AgentModule-ShdrAdapter/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ modules:
5454

5555
* `outputConnectionInformation` - Gets or Sets whether the Connection Information (Host / Port) is output to the Agent to be collected by a client
5656

57+
* `ignoreHeartbeatOnChange` - Gets or Sets whether Heartbeat PING requests are not sent if data has been received within the Heartbeat period. Default is TRUE
58+
5759

5860
## Contribution / Feedback
5961
- Please use the [Issues](https://github.com/TrakHound/MTConnect.NET/issues) tab to create issues for specific problems that you may encounter

libraries/MTConnect.NET-SHDR/Configurations/IShdrAdapterClientConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ public interface IShdrAdapterClientConfiguration : IShdrClientConfiguration
3333
/// Gets or Sets whether the Connection Information (Host / Port) is output to the Agent to be collected by a client
3434
/// </summary>
3535
bool OutputConnectionInformation { get; }
36+
37+
/// <summary>
38+
/// Gets or Sets whether Heartbeat PING requests are not sent if data has been received within the Heartbeat period
39+
/// </summary>
40+
bool IgnoreHeartbeatOnChange { get; }
3641
}
3742
}

libraries/MTConnect.NET-SHDR/Configurations/ShdrAdapterClientConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public class ShdrAdapterClientConfiguration : ShdrClientConfiguration, IShdrAdap
4141
[JsonPropertyName("outputConnectionInformation")]
4242
public bool OutputConnectionInformation { get; set; }
4343

44+
/// <summary>
45+
/// Gets or Sets whether Heartbeat PING requests are not sent if data has been received within the Heartbeat period
46+
/// </summary>
47+
[JsonPropertyName("ignoreHeartbeatOnChange")]
48+
public bool IgnoreHeartbeatOnChange { get; set; }
49+
4450

4551
public ShdrAdapterClientConfiguration()
4652
{
@@ -49,6 +55,7 @@ public ShdrAdapterClientConfiguration()
4955
ConvertUnits = true;
5056
IgnoreObservationCase = true;
5157
OutputConnectionInformation = true;
58+
IgnoreHeartbeatOnChange = true;
5259
}
5360
}
5461
}

libraries/MTConnect.NET-SHDR/Shdr/ShdrClient.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class ShdrClient
6464
/// </summary>
6565
public int ReconnectInterval { get; set; }
6666

67+
/// <summary>
68+
/// Gets or Sets whether Heartbeat PING requests are not sent if data has been received within the Heartbeat period
69+
/// </summary>
70+
public bool IgnoreHeartbeatOnChange { get; set; }
71+
6772

6873
/// <summary>
6974
/// Raised when a client connection is established
@@ -111,6 +116,7 @@ public class ShdrClient
111116
public ShdrClient()
112117
{
113118
Id = StringFunctions.RandomString(10);
119+
IgnoreHeartbeatOnChange = true;
114120
}
115121

116122
public ShdrClient(string hostname, int port, int connectionTimeout = DefaultConnectionTimeout, int reconnectInterval = DefaultReconnectInterval)
@@ -120,6 +126,7 @@ public ShdrClient(string hostname, int port, int connectionTimeout = DefaultConn
120126
Port = port;
121127
ConnectionTimeout = connectionTimeout;
122128
ReconnectInterval = reconnectInterval;
129+
IgnoreHeartbeatOnChange = true;
123130
}
124131

125132
public ShdrClient(string hostname, int port, string deviceKey, int connectionTimeout = DefaultConnectionTimeout, int reconnectInterval = DefaultReconnectInterval)
@@ -130,11 +137,13 @@ public ShdrClient(string hostname, int port, string deviceKey, int connectionTim
130137
DeviceKey = deviceKey;
131138
ConnectionTimeout = connectionTimeout;
132139
ReconnectInterval = reconnectInterval;
140+
IgnoreHeartbeatOnChange = true;
133141
}
134142

135143
public ShdrClient(ShdrClientConfiguration configuration)
136144
{
137145
Id = StringFunctions.RandomString(10);
146+
IgnoreHeartbeatOnChange = true;
138147

139148
if (configuration != null)
140149
{
@@ -254,7 +263,7 @@ private async Task ListenForAdapter(CancellationToken cancel)
254263
}
255264

256265
// Send PING Heartbeat if needed
257-
if (((now - lastResponse) > _heartbeat * 10000) && ((now - _lastHeartbeat) > _heartbeat * 10000))
266+
if ((!IgnoreHeartbeatOnChange || ((now - lastResponse) > _heartbeat * 10000)) && ((now - _lastHeartbeat) > _heartbeat * 10000))
258267
{
259268
messageBytes = Encoding.ASCII.GetBytes(PingMessage);
260269
stream.Write(messageBytes, 0, messageBytes.Length);

0 commit comments

Comments
 (0)