# libplctag.NET
**Repository Path**: leo0530/libplctag.NET
## Basic Information
- **Project Name**: libplctag.NET
- **Description**: No description available
- **Primary Language**: C#
- **License**: MPL-2.0
- **Default Branch**: #224
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2025-08-13
- **Last Updated**: 2025-08-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# libplctag.NET
[libplctag](https://github.com/libplctag/libplctag) is an open source C library for Linux, Windows and macOS using EtherNet/IP or Modbus TCP to read and write tags in PLCs.
libplctag.NET is a .NET wrapper for libplctag.
## Packages
This repository contains two .NET packages that are published to Nuget.org:
| Package | Downloads | Stable | Preview |
|-|-|-|-|
| [libplctag](https://www.nuget.org/packages/libplctag/) |  |  |  |
| [libplctag.NativeImport](https://www.nuget.org/packages/libplctag.NativeImport/) |  |  |  |
## libplctag
This is the package intended for use in .NET applications. It depends on libplctag.NativeImport to gain access to the underlying libplctag native library.
It provides an API for libplctag that should feel natural to .NET developers by supporting the following features:
* Values are strongly-typed (both Atomic types and User-Defined Types).
* Errors are thrown as Exceptions
* Async/Await
* Native resource cleanup
## libplctag.NativeImport
Most developers will not need to directly reference the Native Import library. This library automatically extracts platform-specific version of the base libplctag library needed for the libplctag .NET wrapper.
If you wish to override this behavior you can do so: [Using a non packaged version of the native libplctag library](docs/Using-a-non-packaged-version-of-the-native-libplctag-library.md)
Documentation for the base library API can be found [here](https://github.com/libplctag/libplctag/wiki/API). Further examples of its usage can be found [here](src/Examples/CSharp%20DotNetCore/NativeImportExample.cs).
The libplctag native library can be compiled for [many platforms](https://github.com/libplctag/libplctag#platform-support), and not all supported platforms are shipped with this wrapper. If you get a `TypeLoadException`, chances are that you can still use this wrapper but you will need to [supply the runtime yourself](https://github.com/libplctag/libplctag/blob/master/BUILD.md).
## Getting Started
In most cases only the libplctag package will be needed. It can be added in Visual Studio through the package manager or via the commandline:
`dotnet add package libplctag`
### Simple Example Code for an Allen-Bradley CompactLogix/ControlLogix PLC
```csharp
// Instantiate the tag with the appropriate mapper and datatype
var myTag = new TagDint()
{
//Name is the full path to tag.
Name = "PROGRAM:SomeProgram.SomeDINT",
//Gateway is the IP Address of the PLC or communication module.
Gateway = "10.10.10.10",
//Path is the location in the control plane of the CPU. Almost always "1,0".
Path = "1,0",
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
// Read the value from the PLC
int output = myTag.Read();
// Output to Console
Console.WriteLine($"Original value: SomeProgram.SomeDINT = {output}");
// Write a new value to the PLC then read it back
myTag.Write(37);
output = myTag.Read();
// Output to Console
Console.WriteLine($"Updated value: SomeProgram.SomeDINT = {output}");
```
In advanced scenarios, tags can be instantiated using generics (ex. `Tag