Introducing libplctag.NET 1.0.0 - PLC communications via C#/VB

jkoplo

Member
Join Date
Sep 2020
Location
Flagstaff, AZ
Posts
2
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#:

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
 
I've been test driving this using vb.net for 2 days now and really like it. I do have a few questions.

Do you have a MODBUS example you could share?

I'm currently using a ML1000 via a 1761-NET-ENI. I'm finding that I need to create a tag, read or write using that tag, then dispose the tag. Subsequent reads/writes to a tag that have already been used usually error for me. I think this may be due to the connection limit the ENI imposes. Thoughts?

Thank you for your work on this.
 
So I'm impressed if you got it working with modbus - both of us developing the dotnet wrapper only had CompactLogix PLCs to test against and haven't fully thought through modbus usage. The underlying C library has absolutely been tested against modbus quite a bit, so it should work fine if our initialization is good.

Can you post an example of your modbus usage or even open a Github issue?

If you can't get modbus working in our higher level library, you can drop down to libplctag.NativeImport and follow Kyle's C documentation since the functions are thinly wrapped one-for-one in that library.
 

Similar Topics

Tri-Test is a small tool for testing your Tristation (main software for programming Triconex controllers) application using a script based...
Replies
3
Views
2,804
Hoping someone can give me some guidance or confirmation of what I need to do. We have a FactoryTalk SE program that I need to change the IP...
Replies
0
Views
25
Can we use a Simotion D455 ethernet port x127 as a gate, to access S7-1500 plc Tia Portal program ? In the Simatic manager, we used Netpro to do...
Replies
2
Views
68
"Hello! Good day! Excuse me, I have a question regarding the 1761-NET-ENI. RSLinx has already detected it but it's not connecting to the PLC...
Replies
4
Views
124
So I have a sort of unique situation where I'm wanting to run a PF755 from the IO and over ethernet. Of course, this comes with it's own set of...
Replies
9
Views
252
Back
Top Bottom