Skip to content

Commit

Permalink
Merge pull request #208 from rudoc/master
Browse files Browse the repository at this point in the history
Split MonitoredItemCreateRequest array to chunks
  • Loading branch information
awcullen authored Aug 5, 2021
2 parents 5935207 + 15c28f6 commit a7d8da1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion UaClient/ServiceModel/Ua/SubscriptionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,21 @@ private async Task StateMachineAsync(CancellationToken token = default)
if (items.Count > 0)
{
var requests = items.Select(m => new MonitoredItemCreateRequest { ItemToMonitor = new ReadValueId { NodeId = ExpandedNodeId.ToNodeId(m.NodeId, this.InnerChannel.NamespaceUris), AttributeId = m.AttributeId, IndexRange = m.IndexRange }, MonitoringMode = m.MonitoringMode, RequestedParameters = new MonitoringParameters { ClientHandle = m.ClientId, DiscardOldest = m.DiscardOldest, QueueSize = m.QueueSize, SamplingInterval = m.SamplingInterval, Filter = m.Filter } }).ToArray();

//split requests array to MaxMonitoredItemsPerCall chunks
int maxmonitoreditemspercall = 100;
MonitoredItemCreateRequest[] requests_chunk;
int chunk_size;
for (int i_chunk = 0; i_chunk < requests.Length; i_chunk += maxmonitoreditemspercall)
{
chunk_size = Math.Min(maxmonitoreditemspercall, requests.Length - i_chunk);
requests_chunk = new MonitoredItemCreateRequest[chunk_size];
Array.Copy(requests, i_chunk, requests_chunk, 0, chunk_size);

var itemsRequest = new CreateMonitoredItemsRequest
{
SubscriptionId = id,
ItemsToCreate = requests,
ItemsToCreate = requests_chunk,
};
var itemsResponse = await this.innerChannel.CreateMonitoredItemsAsync(itemsRequest);

Expand All @@ -593,6 +604,7 @@ private async Task StateMachineAsync(CancellationToken token = default)
}
}
}
}

this.progress.Report(CommunicationState.Opened);

Expand Down

0 comments on commit a7d8da1

Please sign in to comment.