Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guorg/gu.twincat

For communication with BeckHoff TwinCAT PLC
https://github.com/guorg/gu.twincat

Last synced: about 4 hours ago
JSON representation

For communication with BeckHoff TwinCAT PLC

Awesome Lists containing this project

README

        

# Gu.TwinCat
For communication with Beckhoff TwinCAT PLC

## Sample

```cs
public sealed class Plc : IDisposable
{
private readonly AdsClient client;
private readonly ReadFromAdsSymbol value3 = SymbolFactory.ReadInt32("Plc.Value3");
private readonly ReadFromAdsSymbol value4 = SymbolFactory.ReadSingle("Plc.Value4", x => Angle.FromDegrees(x));
private readonly WriteToAdsSymbol value5 = SymbolFactory.WriteInt32("Plc.Value5");
private readonly WriteToAdsSymbol value6 = SymbolFactory.WriteSingle("Plc.Value6", x => x.Degrees);

public Plc()
{
this.client = new AdsClient(
new AutoReconnectSettings(
address: new AmsAddress("1.2.3.4.5.6", 851),
reconnectInterval: AdsTimeSpan.FromSeconds(1),
inactiveSymbolHandling: InactiveSymbolHandling.Throw));

this.Subscription1 = this.client.Subscribe(
SymbolFactory.ReadInt32("Plc.Value1"),
AdsTransMode.OnChange,
AdsTimeSpan.FromMilliseconds(100));

this.Subscription2 = this.client.Subscribe(
SymbolFactory.ReadSingle(
"Plc.Value2",
x => Angle.FromDegrees(x)),
AdsTransMode.OnChange,
AdsTimeSpan.FromMilliseconds(100));
}

public Subscription Subscription1 { get; }

public Subscription Subscription2 { get; }

public int Value3() => this.client.Read(this.value3);

public Angle Value4() => this.client.Read(this.value4);

public void SetValue5(int value) => this.client.Write(this.value5, value);

public void SetValue6(Angle value) => this.client.Write(this.value6, value);

public void Dispose()
{
this.client.Dispose();
this.Subscription1.Dispose();
this.Subscription2.Dispose();
}
}

public struct Angle
{
public readonly float Degrees;

public Angle(float degrees)
{
this.Degrees = degrees;
}

...
public static Angle FromDegrees(float value) => new Angle(value);
}
```