Skip to main content
net6.0-windows10.0.17763net7.0-windows10.0.17763net8.0-windows10.0.17763.NETStandard2.0

A Reactive TwinCAT PLC Library

Published
Mar 22, 2024
2y ago
Total Downloads
15.4K
15,382

Deprecated Package Version

Reason: Other

I have moved development to a centralised Repository https://github.com/ChrisPulman/IoT-DriverCore Please use the new package for continued support and updates. NOTE: The namespaces have changed in the new package.

Suggested alternative:IoT-Driver.TwinCATRx*

Install

dotnet add package CP.TwinCATRx --version 1.2.1
ProductVersions
.NET
net6.0-windows10.0.17763net7.0-windows10.0.17763net8.0-windows10.0.17763
.NET Standard
netstandard2.0

README

TwinCATRx

License Build Nuget NuGet

A Reactive implementation of TwinCAT ADS

This is a reactive implementation of TwinCAT ADS. It is based on the TwinCAT ADS library from Beckhoff. It is a wrapper around the TwinCAT ADS library that allows you to use the TwinCAT ADS library in a reactive way. It is based on the Reactive Extensions (Rx) library.

Currently it does not support the following features:

  • Arrays of string
  • Arrays of string in structures
    // Create Client
    var client = new RxTcAdsClient();
    var settings = new Settings { AdsAddress = "5.35.59.10.1.1", Port = 801, SettingsId = "Default" };

    // Add notification variables
    // Structures
    settings.AddNotification(".Tag1");
    settings.AddNotification(".Tag2");
    settings.AddNotification(".Tag3");
    settings.AddNotification(".AString", arraySize: 80);
    settings.AddNotification(".ABool");
    settings.AddNotification(".AByte");
    settings.AddNotification(".AInt");
    settings.AddNotification(".ADInt");
    settings.AddNotification(".AReal");
    settings.AddNotification(".ALReal");

    // Add Write variables, these can be read too using client.Read("TagName")
    // NOT SUPPORTED: arrays of string
    ////settings.AddWriteVariable(".ArrString", 11));
    settings.AddWriteVariable(".ArrBool", 11);
    settings.AddWriteVariable(".ArrByte", 11);
    settings.AddWriteVariable(".ArrInt", 11);
    settings.AddWriteVariable(".ArrDInt", 11);
    settings.AddWriteVariable(".ArrReal", 11);
    settings.AddWriteVariable(".ArrLReal", 11);
    client.Connect(settings);

    // Observe notification tags simple types
    client.Observe<string>(".AString").Subscribe(data => Console.WriteLine(data));
    client.Observe<bool>(".ABool").Subscribe(data => Console.WriteLine(data));
    client.Observe<byte>(".AByte").Subscribe(data => Console.WriteLine(data));
    client.Observe<short>(".AInt").Subscribe(data => Console.WriteLine(data));
    client.Observe<int>(".ADInt").Subscribe(data => Console.WriteLine(data));
    client.Observe<float>(".AReal").Subscribe(data => Console.WriteLine(data));
    client.Observe<double>(".ALReal").Subscribe(data => Console.WriteLine(data));

    // Observe Write variables these will execute when tag is read.
    client.Observe<bool[]>(".ArrBool").Subscribe(data => Console.WriteLine(data));
    client.Observe<byte[]>(".ArrByte").Subscribe(data => Console.WriteLine(data));
    client.Observe<short[]>(".ArrInt").Subscribe(data => Console.WriteLine(data));
    client.Observe<int[]>(".ArrDInt").Subscribe(data => Console.WriteLine(data));
    client.Observe<float[]>(".ArrReal").Subscribe(data => Console.WriteLine(data));
    client.Observe<double[]>(".ArrLReal").Subscribe(data => Console.WriteLine(data));

    // Read tags of a simple type
    client.Read(".ArrBool");
    client.Read(".ArrByte");
    client.Read(".ArrInt");
    client.Read(".ArrDInt");
    client.Read(".ArrReal");
    client.Read(".ArrLReal");

    // Write a value
    client.Write(".ABool", true);

    // Create structure to store data
    var tag1 = client.CreateStruct(".Tag1", true);
    tag1.StructureReady().Subscribe(data =>
    {
        // read from structure as stream
        data.Observe<bool>("ABool").Subscribe(value => Console.WriteLine(value));
        data.Observe<short>("AInt").Subscribe(value => Console.WriteLine(value));
        data.Observe<string>("AString").Subscribe(value => Console.WriteLine(value));

        // read from structure as one time read from the first level.
        var tag = data.Value<short>("AInt");

        data.WriteValues(ht =>
        {
            // write values to structure
            ht.Value("AInt", (short)(tag + 10));
            ht.Value("AString", $"Int Value {tag + 10}");
            
            // Values are written from the structure to the PLC upon return.
        });
    });

Changes from Previous Version

No structural changes between v1.2.0 and v1.2.1.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

NuGet marks this package as deprecated and points to IoT-Driver.TwinCATRx as an alternative.Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.The published metadata declares 24 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.