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,811
Hello guys i'm working with an s7 1200 plc with an ET 200S expansion module. The problem is that i can't find the plc when searching in the...
Replies
1
Views
101
Good morning everyone I’m currently working on a omron device net and have a nord drive that fell off the network. I have limit knowledge in...
Replies
2
Views
78
Hi. We've been asked to do an upgrade on plant, consisting on a PLC upgrade. This involves replacing a 1747-SDN module to a 1769-SDN, in a network...
Replies
0
Views
65
Anyone have a idea of what would cause a failure of all nodes (buckets) of an AB Device Net MCC upon a power cycle of the main feeder for that MCC?
Replies
16
Views
541
Back
Top Bottom