jkoplo
Member
During the covid quarantine I've been working on an open-source project in my spare time to make it possible to communicate with PLCs (mostly Allen-Bradley) using dotnet (C# or VB). It's a wrapper around the amazing libplctag library that's written in low-level C. I worked with another C# developer (Timyhac) as well as the main libplctag developer (Kyle Hayes) to create what we think is the best way to connect to PLCs using .NET.
Here's an example of reading/writing a tag using C#:
There's more information and background about the library in my blog post: https://dev.to/jkoplo/introducing-libplctag-net-1-0-0-plc-communications-via-c-vb-2g5f
The library is available on NuGet: https://www.nuget.org/packages/libplctag/
The sourcecode is on GitHub: https://github.com/libplctag/libplctag.NET
Here's an example of reading/writing a tag using C#:
Code:
//Instantiate the tag with the proper mapper and datatype
var myTag = new Tag<DintPlcMapper, int>()
{
Name = "PROGRAM:SomeProgram.SomeDINT",
Gateway = "10.10.10.10",
Path = "1,0",
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
//Initialize the tag to set up structures and prepare for read/write
//This is optional as an optimization before using the tag
//If omitted, the tag will initialize on the first Read() or Write()
myTag.Initialize();
//The value is held locally and only synchronized on Read() or Write()
myTag.Value = 3737;
//Transfer Value to PLC
myTag.Write();
//Transfer from PLC to Value
myTag.Read();
//Write to console
int myDint = myTag.Value;
Console.WriteLine(myDint);
There's more information and background about the library in my blog post: https://dev.to/jkoplo/introducing-libplctag-net-1-0-0-plc-communications-via-c-vb-2g5f
The library is available on NuGet: https://www.nuget.org/packages/libplctag/
The sourcecode is on GitHub: https://github.com/libplctag/libplctag.NET