Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/guorg/gu.twincat
- Owner: GuOrg
- License: mit
- Created: 2019-12-17T15:21:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-25T16:14:17.000Z (11 months ago)
- Last Synced: 2024-03-26T07:08:22.359Z (8 months ago)
- Language: C#
- Size: 164 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
}
```