VOOZH about

URL: https://www.nuget.org/packages/MASES.PLCOnNet/

⇱ NuGet Gallery | MASES.PLCOnNet 0.13.3




👁 Image
MASES.PLCOnNet 0.13.3

dotnet add package MASES.PLCOnNet --version 0.13.3
 
 
NuGet\Install-Package MASES.PLCOnNet -Version 0.13.3
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MASES.PLCOnNet" Version="0.13.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MASES.PLCOnNet" Version="0.13.3" />
 
Directory.Packages.props
<PackageReference Include="MASES.PLCOnNet" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MASES.PLCOnNet --version 0.13.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MASES.PLCOnNet, 0.13.3"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MASES.PLCOnNet@0.13.3
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MASES.PLCOnNet&version=0.13.3
 
Install as a Cake Addin
#tool nuget:?package=MASES.PLCOnNet&version=0.13.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

title: Usage of .NET suite for PLC4X™ _description: Describes how to use PLCOnNet, set-up environment, identify the JVM™ and write good code

PLCOnNet usage

To use PLCOnNet classes the developer can write code in .NET using the same classes available in the official Java packages. If classes or methods are not available yet it is possible to use the approach synthetized in What to do if an API was not yet implemented

The following code snippets and examples are mutuated from PLC4X™ official website

Read data from PLC

The following code connects to a Siemens PLC using the s7 protocol and requests to read some tags:


const string connectionString = "s7://10.10.64.20";

using var plcConnection = PlcDriverManager.Default.ConnectionManager.GetConnection(connectionString);

if (!plcConnection.Metadata.IsReadSupported())
{
 Console.WriteLine("This connection doesn't support reading.");
 return;
}
// Create a new read request:
// - Give the single item requested an alias name
PlcReadRequest.Builder builder = plcConnection.ReadRequestBuilder();
builder.AddTagAddress("value-1", "%Q0.4:BOOL");
builder.AddTagAddress("value-2", "%Q0:BYTE");
builder.AddTagAddress("value-3", "%I0.2:BOOL");
builder.AddTagAddress("value-4", "%DB.DB1.4:INT");
PlcRequest readRequest = builder.Build();

var cf = readRequest.Execute<PlcReadResponse>();
var response = cf.Get();

foreach (Java.Lang.String tagName in response.TagNames)
{
 if (response.GetResponseCode(tagName) == PlcResponseCode.OK)
 {
 int numValues = response.GetNumberOfValues(tagName);
 // If it's just one element, output just one single line.
 if (numValues == 1)
 {
 Console.WriteLine($"Value[{tagName}]: {response.GetObject(tagName)}");
 }
 // If it's more than one element, output each in a single row.
 else
 {
 Console.WriteLine($"Value[{tagName}]:");
 for (int i = 0; i < numValues; i++)
 {
 Console.WriteLine($" - {response.GetObject(tagName, i)}");
 }
 }
 }
 // Something went wrong, to output an error message instead.
 else
 {
 Console.WriteLine($"Error[{tagName}]: {response.GetResponseCode(tagName).Name()}");
 }
}

Write data to PLC

The following code connects to a Siemens PLC using the s7 protocol and requests to write some tags:


const string connectionString = "s7://10.10.64.20";

using var plcConnection = PlcDriverManager.Default.ConnectionManager.GetConnection(connectionString);

if (!plcConnection.Metadata.IsWriteSupported())
{
 Console.WriteLine("This connection doesn't support writing.");
 return;
}
// Create a new write request:
// - Give the single item requested an alias name
// - Pass in the data you want to write (for arrays, pass in one value for every element)
PlcWriteRequest.Builder builder = plcConnection.WriteRequestBuilder();
builder.AddTagAddress("value-1", "%Q0.4:BOOL", true);
builder.AddTagAddress("value-2", "%Q0:BYTE", (byte)0xFF);
builder.AddTagAddress("value-4", "%DB.DB1.4:INT[3]", 7, 23, 42);
PlcRequest writeRequest = builder.Build();

var cf = writeRequest.Execute<PlcWriteResponse>();
var response = cf.Get();

foreach (Java.Lang.String tagName in response.TagNames)
{
 if (response.GetResponseCode(tagName) == PlcResponseCode.OK)
 {
 Console.WriteLine($"Value[{tagName}]: updated");
 }
 // Something went wrong, to output an error message instead.
 else
 {
 Console.WriteLine($"Error[{tagName}]: {response.GetResponseCode(tagName).Name()}");
 }
}

Subscribe to PLC

The following code connects to a Siemens PLC using the s7 protocol and subscribe to data change of some tags:


ConcurrentDictionary<int, PlcConsumerRegistration> _registrationMap = new();
Consumer<PlcSubscriptionEvent> _plcEvent = null;
const string connectionString = "s7://10.10.64.20";

using var plcConnection = PlcDriverManager.Default.ConnectionManager.GetConnection(connectionString);

if (!plcConnection.Metadata.IsSubscribeSupported())
{
 Console.WriteLine("This connection doesn't support subscribing.");
 return;
}
// Create a new subscription request:
// - Give the single tag requested an alias name
PlcSubscriptionRequest.Builder builder = plcConnection.SubscriptionRequestBuilder();
builder.AddChangeOfStateTagAddress("value-1", "{some address}");
builder.AddCyclicTagAddress("value-2", "{some address}", Duration.OfMillis(1000));
builder.AddEventTagAddress("value-3", "{some alarm address}");
PlcRequest subscriptionRequest = builder.Build();

var cf = subscriptionRequest.Execute<PlcSubscriptionResponse>();
var response = cf.Get();

_plcEvent ??= new Consumer<PlcSubscriptionEvent>()
{
 OnAccept = (e) =>
 {
 foreach (Java.Lang.String tagName in e.TagNames)
 {
 Console.WriteLine(e.GetPlcValue(tagName));
 }
 }
};

foreach (PlcSubscriptionHandle subscriptionHandle in response.SubscriptionHandles)
{
 var reg = subscriptionHandle.Register(_plcEvent);
 _registrationMap.GetOrAdd(reg.ConsumerId, (_) => reg); 
}

// wait many events then cleanup

foreach (var item in _registrationMap)
{
 item.Value.Unregister();
}

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Framework net462 net462 is compatible.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.13.3 102,503 3/16/2026
0.13.2 116,359 11/29/2025
0.13.1 90,215 9/23/2025
0.13.0 151 8/22/2025
0.12.3 215 8/9/2025
0.12.2 644 7/21/2025 0.12.2 is deprecated because it has critical bugs.
0.12.1 490 4/7/2025 0.12.1 is deprecated because it has critical bugs.