Skip to content

Commit

Permalink
Improve speed further by extending the read area based upon the PLC type
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 27, 2023
1 parent 4c86ec5 commit 4a19fce
Show file tree
Hide file tree
Showing 29 changed files with 3,663 additions and 3,548 deletions.
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.1",
"version": "1.1.1",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
61 changes: 48 additions & 13 deletions src/S7PlcRx.TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,65 @@
using S7PlcRx;

var plc = new RxS7(S7PlcRx.Enums.CpuType.S71500, "172.16.17.1", 0, 1, interval: 5);
////for (var i = 0; i < 60; i++)

const string Tag0_To_99 = nameof(Tag0_To_99);
const string StringArea = nameof(StringArea);
////for (var i = 0; i < 100; i++)
{
plc.AddUpdateTagItem<double[]>("Tag0_To_59", "DB103.DBD0", 59);
plc.AddUpdateTagItem<double[]>(Tag0_To_99, "DB103.DBD0", 99);
plc.AddUpdateTagItem<byte[]>(StringArea, "DB101.DBB0", 264).SetTagNoPoll(true);
}

plc.IsConnected.Subscribe(x =>
{
if (x)
{
Console.WriteLine("Connected");
var v = plc.Value<byte[]>(StringArea);
}
else
{
Console.WriteLine("Disconnected");
}
});

////plc.Observe<double>("Tag0").Subscribe(x => Console.WriteLine($"Tag0: {x}"));
////plc.Observe<double>("Tag1").Subscribe(x => Console.WriteLine($"Tag1: {x}"));

plc.ReadTime.Select(x => TimeSpan.FromTicks(x).TotalMilliseconds).Buffer(200).Select(x => x.Average()).CombineLatest(
plc.ObserveAll.TagToDictionary<double[]>())
var count = 0;
plc.ReadTime
.Select(x => TimeSpan.FromTicks(x).TotalMilliseconds)
.TimeInterval()
.Buffer(200)
.Select(x => (ExectionTime: x.Select(x => x.Interval.TotalMilliseconds).Average(), Value: x.Select(x => x.Value).Average()))
.CombineLatest(
plc.Observe<double[]>(Tag0_To_99).ToTagValue(Tag0_To_99))
.Subscribe(values =>
{
var sb = new StringBuilder();
sb.Append("Read time: ").Append(values.First).Append(" / ");
foreach (var kvp in values.Second)
count++;
if (count % 200 == 0)
{
sb.Append("Key = ").Append(kvp.Key);
for (var i = 0; i < kvp.Value.Length; i++)
count = 0;
var sb = new StringBuilder();
sb.Append("Read time: ").Append(values.First).Append(" ms");
if (values.First.Value > 5)
{
sb.Append(", Value").Append(i).Append(" = ").Append(kvp.Value[i]).Append(" / ");
Console.ForegroundColor = ConsoleColor.Red;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
}

Console.WriteLine(sb.ToString());
Console.ResetColor();
sb.Clear().Append("Tag = ").Append(values.Second.Tag);
for (var i = 0; i < values.Second.Value.Length; i++)
{
sb.Append(", Value").Append(i).Append(" = ").Append(values.Second.Value[i]).Append(" / ");
}
}

Console.WriteLine(sb.ToString());
Console.WriteLine(sb.ToString());
}
});

////plc.ReadTime.Select(x => TimeSpan.FromTicks(x).TotalMilliseconds).Buffer(200).Select(x => x.Average()).Subscribe(time => Console.WriteLine($"Read time: {time}"));
Expand Down
47 changes: 23 additions & 24 deletions src/S7PlcRx/Core/PLCRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@

using S7PlcRx.Enums;

namespace S7PlcRx.Core
namespace S7PlcRx.Core;

/// <summary>
/// PLC Request.
/// </summary>
internal class PLCRequest
{
/// <summary>
/// PLC Request.
/// Initializes a new instance of the <see cref="PLCRequest"/> class.
/// </summary>
internal class PLCRequest
/// <param name="request">The request.</param>
/// <param name="tag">The tag.</param>
public PLCRequest(PLCRequestType request, Tag? tag)
{
/// <summary>
/// Initializes a new instance of the <see cref="PLCRequest"/> class.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="tag">The tag.</param>
public PLCRequest(PLCRequestType request, Tag? tag)
{
Request = request;
Tag = tag;
}
Request = request;
Tag = tag;
}

/// <summary>
/// Gets the request.
/// </summary>
/// <value>The request.</value>
public PLCRequestType Request { get; }
/// <summary>
/// Gets the request.
/// </summary>
/// <value>The request.</value>
public PLCRequestType Request { get; }

/// <summary>
/// Gets the tag.
/// </summary>
/// <value>The tag.</value>
public Tag? Tag { get; }
}
/// <summary>
/// Gets the tag.
/// </summary>
/// <value>The tag.</value>
public Tag? Tag { get; }
}
Loading

0 comments on commit 4a19fce

Please sign in to comment.