Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chrispulman/twincatrx
A Reactive implementation of TwinCAT ADS
https://github.com/chrispulman/twincatrx
ads beckhoff reactive twincat
Last synced: 2 months ago
JSON representation
A Reactive implementation of TwinCAT ADS
- Host: GitHub
- URL: https://github.com/chrispulman/twincatrx
- Owner: ChrisPulman
- License: mit
- Created: 2022-10-04T16:44:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-11T20:49:07.000Z (3 months ago)
- Last Synced: 2024-10-11T22:23:14.007Z (3 months ago)
- Topics: ads, beckhoff, reactive, twincat
- Language: C#
- Homepage:
- Size: 601 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TwinCATRx
![License](https://img.shields.io/github/license/ChrisPulman/TwinCATRx.svg) [![Build](https://github.com/ChrisPulman/TwinCATRx/actions/workflows/BuildOnly.yml/badge.svg)](https://github.com/ChrisPulman/TwinCATRx/actions/workflows/BuildOnly.yml) ![Nuget](https://img.shields.io/nuget/dt/CP.TwinCATRx?color=pink&style=plastic) [![NuGet](https://img.shields.io/nuget/v/CP.TwinCATRx.svg?style=plastic)](https://www.nuget.org/packages/CP.TwinCATRx)
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```c#
// 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(".AString").Subscribe(data => Console.WriteLine(data));
client.Observe(".ABool").Subscribe(data => Console.WriteLine(data));
client.Observe(".AByte").Subscribe(data => Console.WriteLine(data));
client.Observe(".AInt").Subscribe(data => Console.WriteLine(data));
client.Observe(".ADInt").Subscribe(data => Console.WriteLine(data));
client.Observe(".AReal").Subscribe(data => Console.WriteLine(data));
client.Observe(".ALReal").Subscribe(data => Console.WriteLine(data));// Observe Write variables these will execute when tag is read.
client.Observe(".ArrBool").Subscribe(data => Console.WriteLine(data));
client.Observe(".ArrByte").Subscribe(data => Console.WriteLine(data));
client.Observe(".ArrInt").Subscribe(data => Console.WriteLine(data));
client.Observe(".ArrDInt").Subscribe(data => Console.WriteLine(data));
client.Observe(".ArrReal").Subscribe(data => Console.WriteLine(data));
client.Observe(".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("ABool").Subscribe(value => Console.WriteLine(value));
data.Observe("AInt").Subscribe(value => Console.WriteLine(value));
data.Observe("AString").Subscribe(value => Console.WriteLine(value));// read from structure as one time read from the first level.
var tag = data.Value("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.
});
});
```