Giter Club home page Giter Club logo

twinrx's Introduction

NOTE

As of version 4.2.172.0, the Beckhoff ADS library for .NET also includes support for Reactive Extensions, making this library obsolete. See here for more information: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsnetref/7312584843.html&id=


Build status NuGet version

TwinRx

TwinRx is a library for connecting a .NET application with a Beckhoff TwinCAT PLC program via Reactive Extensions (Rx) over ADS.

Features

  • Create an IObservable for a PLC variable, bringing changes to the PLC variable into the Reactive world.
  • Make use of Rx's extensive event processing and querying capabilities to transform the observable into events of interest.
  • Stream (write) an existing IObservable to a PLC variable
  • Transparently reregister the notifications after a connection loss

Requires

  • .NET 4.5 or higher
  • Beckhoff TwinCAT PLC (v2 or v3)

Installation

  • Install the NuGet package "TwinRx" using the NuGet Package Manager in Visual Studio

Example code

using System;
using System.Reactive.Linq;
using TwinCAT.Ads;
using TwinRx;

var adsClient = new TcAdsClient();
adsClient.Connect(801); // 801 for TwinCAT 2, 851 for TwinCAT 3

var client = new TwinCatRxClient(adsClient);

var counter = client.ObservableFor<short>("MAIN.var1", 20);

// Print out each value as it changes
counter.Subscribe(v => Console.WriteLine("Variable is now:" + v));

// Print out 10 values at a time
var buffered = counter.Buffer(10);
buffered.Subscribe(v => Console.WriteLine("Last 10 values were:" + String.Join(" - ", v)));

// Values including timestamp
var valuesWithTimestamp = counter.Select(i => new Tuple<short, DateTime>(i, DateTime.Now));
valuesWithTimestamp.Subscribe(Console.WriteLine);

// Take a single value each second
valuesWithTimestamp
	.Sample(TimeSpan.FromSeconds(5))
	.Subscribe(Console.WriteLine);

var myString = client.ObservableFor<string>("MAIN.var2");
myString.Subscribe(Console.WriteLine);

// Write a value to the PLC periodically
var valueEverySecond = Observable
	.Interval(TimeSpan.FromSeconds(1))
	.Select(i => (short) i);
var writer = client.StreamTo("MAIN.var3", valueEverySecond);

// Only even ones
var evens = client.ObservableFor<short>("MAIN.var4").Where(i => i%2 == 0);
var evensWithTimestamp = evens
	.Timestamp()
	.Zip(evens.TimeInterval(), (valWithTimestamp, interval) => new { val = "Even value is " + valWithTimestamp, interval });
evensWithTimestamp.Subscribe(Console.WriteLine);

twinrx's People

Contributors

svroonland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twinrx's Issues

New version

Hello Svroonland,
Are you planing to release a new version of your library as a nuget package?
From what I have seen, the latest version available on nuget does not support structure, while the latest version of the code on github does.
Did you identify any issue preventing you from promoting it to a release version?
Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.