PLC Communications Made Easy with libplctag.NET 1.0.0 in C# and VB

Question:

Amidst the COVID-19 lockdown, I have devoted my spare time to developing an open-source project aimed at enabling communication with Programmable Logic Controllers (PLCs), primarily Allen-Bradley, through dotnet (C# or VB). This project serves as a wrapper for the libplctag library, which is coded in low-level C. I collaborated with another C# developer, Timyhac, and the main developer of libplctag, Kyle Hayes, to devise what we believe to be the most efficient method for interfacing with PLCs using .NET. Here is an illustration of how to read/write a tag using C#: ``` //Instantiate the tag with the appropriate mapper and data type var myTag = new Tag() { 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 configure structures and prepare for read/write //This step is optional for optimizing tag usage //If skipped, initialization will occur during the first Read() or Write() myTag.Initialize(); //The value is stored locally and synchronized only during Read() or Write() myTag.Value = 3737; //Transfer Value to PLC myTag.Write(); //Transfer from PLC to Value myTag.Read(); //Display on console int myDint = myTag.Value; Console.WriteLine(myDint); ``` For more details and background information about the library, you can refer to my blog post titled "Introducing libplctag .NET 1.0.0: PLC Communications via C# & VB." Additionally, the library can be accessed on NuGet at https://www.nuget.org/packages/libplctag and its source code is available on GitHub at https://github.com/libplctag/libplctag.NET.

Top Replies

I will definitely take a look at it. I am a bit hesitant about connecting to C bindings though, as it can make cross-platform compatibility more challenging.

I have been experimenting with vb.net for the past two days and am really enjoying it. I do have a couple of inquiries. Is there a MODBUS example available that you could provide? Currently, I am utilizing a ML1000 with a 1761-NET-ENI. I have noticed that I need to create a tag, perform a read or write operation using that tag, and then dispose of the tag. When attempting subsequent reads/writes to a tag that has already been used, I often encounter errors. I suspect that this issue may be related to the connection limit enforced by the ENI. Any thoughts on this matter? Thank you for your efforts on this project.

I am truly impressed by your success in utilizing modbus with our dotnet wrapper. During our development process, we only had CompactLogix PLCs available for testing and did not fully consider modbus integration. However, the underlying C library has undergone extensive modbus testing, so it should function properly if our initialization is correct. If you are able, could you please share an example of how you are using modbus, or open a Github issue? If you encounter difficulties with modbus in our higher level library, you can always revert to libplctag.NativeImport and refer to Kyle's C documentation, as the functions are directly mapped in that library.

Are you looking for a Visual Basic 2022 example code snippet?

During the COVID quarantine, I dedicated my spare time to developing an open-source project aimed at facilitating communication with PLCs, particularly Allen-Bradley models, using dotnet (C# or VB). This project serves as a wrapper for the highly efficient libplctag library, which is coded in low-level C. Collaborating with another skilled C# developer (Timyhac) and the primary libplctag developer (Kyle Hayes), we have successfully crafted a reliable method for interfacing with PLCs through .NET. Below is a snippet illustrating how to read and write tags using C#: //Instantiate the tag with the necessary mapper and data type var myTag = new Tag() { 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 for optimal read/write operations //Optional step for enhancing performance before usage //If skipped, the tag will initialize during the first Read() or Write() myTag.Initialize(); //The value is locally stored and synchronized only during Read() or Write() myTag.Value = 3737; //Send Value to PLC myTag.Write(); //Retrieve from PLC to Value myTag.Read(); //Display on console int myDint = myTag.Value; Console.WriteLine(myDint); For more details and context about the library, refer to my blog post: Introducing libplctag.NET 1.0.0 - Enhancing PLC Connectivity with C#/VB The library is accessible on NuGet with version 1.5.2: libplctag 1.5.2 To view the source code, visit the project repository on GitHub: GitHub - libplctag/libplctag.NET: Simplifying PLC communication with a .NET wrapper Do you require guidance on establishing a connection with a MicroLogix 1000 via an RS232 connection?

This is genuinely impressive work you've done here, my commendations to Timyhac, Kyle Hayes, and yourself. The clear implementation and efficient interface with PLCs with .NET are highly useful, particularly for us working with Allen-Bradley. The initialize optimization and the local synchronization of Value during Read() or Write() will certainly streamline many tasks. I'll definitely delve deeper into your blog post and have a more detailed look at the NuGet package and GitHub source code. Great use of lockdown time and a worthwhile contribution to open source - thanks for sharing this.

It's extraordinary to see the innovations we can come up with during trying times like this lockdown. The open-source project you've undertaken really bridges the gap between PLCs and .NET. It seems like a gamechanger for anyone working in related fields. Kudos to you and your collaborators, particularly for focusing on user optimization with features like optional tag initialization. I'll surely be checking out both your blog post and the library on NuGet and GitHub. Cheers to the entire team behind this, looking forward to seeing more updates and improvements in the future.

This sounds like an incredible project! The ability to interface with PLCs through .NET really opens up a lot of possibilities for automation and industrial applications. I appreciate how you’ve utilized the libplctag library as a foundation; that should make integrating PLCs much easier for developers comfortable with C#. I'm especially interested in the performance aspects you mentioned collaborating with Kyle on. Have you encountered any challenges so far in making the wrapper efficient, and how has the community responded to your work?

Wow, that sounds like an incredible project! It's so cool to see open-source initiatives thriving during the lockdown, especially in areas like PLC communications that can really benefit from modern programming languages. I love how you've collaborated with others to enhance the capabilities of libplctag; it's always inspiring to see developers come together to tackle complex challenges. I’m excited to check out your blog post and dive into the library on NuGet. It could really streamline some of the PLC integrations I’m working on. Keep up the great work!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: 1. What is libplctag.NET 1.0.0 and how does it facilitate communication with PLCs in C and VB?

Answer: - libplctag.NET 1.0.0 is an open-source project that serves as a wrapper for the libplctag library, enabling communication with Programmable Logic Controllers (PLCs), primarily Allen-Bradley, through dotnet (C or VB). It provides an efficient method for interfacing with PLCs using .NET.

FAQ: 2. Who are the key collaborators involved in the development of libplctag.NET 1.0.0?

Answer: - The project was developed in collaboration with another C developer named Timyhac and the main developer of libplctag, Kyle Hayes.

FAQ: 3. How can tags be read and written using libplctag.NET 1.0.0 in C?

Answer: - Tags can be read and written using libplctag.NET 1.0.0 in C by instantiating the tag with the appropriate mapper and data type, initializing the tag for configuration, setting the value locally, performing write and read operations, and accessing the value for further processing.

FAQ: 4. Where can I find more information and resources related to libplctag.NET 1.0.0?

Answer: - You can refer to the blog post titled "Introducing libplctag .NET 1.0.0: PLC Communications via C & VB" for

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  â†’