L5Sharp 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package L5Sharp --version 3.0.0                
NuGet\Install-Package L5Sharp -Version 3.0.0                
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="L5Sharp" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add L5Sharp --version 3.0.0                
#r "nuget: L5Sharp, 3.0.0"                
#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.
// Install L5Sharp as a Cake Addin
#addin nuget:?package=L5Sharp&version=3.0.0

// Install L5Sharp as a Cake Tool
#tool nuget:?package=L5Sharp&version=3.0.0                

L5Sharp

A library for intuitively interacting with Rockwell's L5X import/export files.

Purpose

The purpose of this library is to offer a reusable, strongly typed, intuitive API over Rockwell's L5X schema, allowing developers to quickly modify or generate L5X content. In doing so, this library can aid in creation of tools or scripts that automate the PLC development, maintenance, or testing processes for automation engineers.

Goals

The following are some high level goals this project aimed to accomplish.

  1. Provide a simple and intuitive API, making the learning curve as low as possible.
  2. Ensure performance as much as possible without sacrificing simplicity.
  3. Make it easy and seamless to extend the API to support custom queries or functions.
  4. Support strongly typed mutable tag data, so we can reference complex structures statically at compile time.

Packages

You can consume the library via NuGet.

Install-Package L5Sharp

Previously I had two separate libraries but have since consolidated to a single package to avoid confusion and since I think most people would want all functionality anyway. L5Sharp.Extensions is no longer maintained.

Quick Start

  1. Install package from Nuget.

    Install-Package L5Sharp
    
  2. Load an L5X file using the L5X class static factory methods.

    var content = L5X.Load("C:\PathToMyFile\FileName.L5X");
    
  3. Get started by querying elements across the L5X using the Query() methods and LINQ extensions. The following query gets all tags and their nested tag members of type TIMER and returns the TagName, Description, and Preset value in a flat list ordered by TagName.

    var results = content.Query<Tag>()
                .SelectMany(t => t.Members())
                .Where(t => t.DataType == "TIMER")
                .Select(t => new {t.TagName, t.Description, Preset = t["PRE"].Value})
                .OrderBy(v => v.TagName)
                .ToList();
    

    Query<T>() returns an IEnumerable<T>, allowing for complex queries using LINQ and the strongly typed objects in the library. Since Query<T>() queries the entire L5X for the specified type, the above query will return all Tag components found, including controller and program tags.

Usage

The following is some basic examples of how you can use this library to query and modify the L5X content.

Querying

Using Container Collections

Once the L5X is created, you can use the component properties to access the LogixContainer for the specified type. This gets you simple collection APIs that allow you to query for component objects.

This library supports all primary components including the following:

  • Controller
  • DataType
  • AddOnInstruction
  • Module
  • Tag
  • Program
  • Routine
  • Task
  • Trend
  • WatchList

For example, the following shows some simple querying via the Tags component container.

//Get all controller tags. 
var tags = content.Tags.ToList();

//Get a tag by name.
var tag = content.Tags.Find("MyTag");

//Use LINQ to query further.
var results = content.Tags.Where(t => t.DataType == "TIMER");
Using Query Methods

The previous code will only return controller scoped tags since the Tags container on the root L5X represents controller scoped tag elements. To get program tags we would have to access the Tags container on a specific program.

//Get the first program in the L5X and find a tag called 'MyProgramTag'
var programTags = content.Programs.First().Tags.Find("MyProgramTag");

This is a little cumbersome. It would be nice to have a single way to query for all tags across the file and filter those results as well. And there is using the Query methods. These generic methods will return all instances of the type found in the file and allow you to further filter them using LINQ.

//Gets all tags (controller, program, module/IO)
var allTags = content.Query<Tag>().ToList();

var programTags = allTags.Where(t => t.Scope == Scope.Program);
var ioTags = allTags.Where(t => t.Name.Contains(':'));
var readWriteTags = allTags.Where(t => t.ExternalAccess == ExternalAccess.ReadWrite);
var timerTags = allTags.Where(t => t.DataType == "TIMER");
Using Index Methods

Some L5X projects can contain a lot of Tag components especially when you consider all the nested tag members as an individual tag that can be referenced in the project. If you have to perform continuous lookup of tag objects for some operation or task, that could be costly or time intensive. We need a fast way to retrieve components, and this library offers that as well.

The following methods use an internal index or set of dictionaries to quickly find a component with by name and type.

//Find a data type component by name
var tag = content.Find<DataType>("MyUserDefined");

//Get a data type component by name 
//(the different here is Get throws an exception if not found)
var tag = content.Get<DataType>("MyUserDefined");

//Get a nested tag member 
//(we don't need to specify <Tag> since it is implied with the Tagname overload)
var tag = content.Find("MyTag.Member[1].SubMember.1");

//Gets all tags with name 
//(this could be controller and/or program tags)
var tags = content.All("ScopedTag").ToList();

The above calls all operate in constant time since the components are indexed using dictionaries. The L5X is only indexed when the first call to an index method such as Find, Get or All is made. The index is cached so everytime after we don't need to recreate it. It will also be maintained internally as components are added or removed.

Modifying

Modifying components is simple as well. The same component collection interface offers methods for adding, removing, and updating components.

//Add a new component.
var tag = new Tag { Name = "MyTag", Value = 100 };
content.Tags.Add(tag);

//Remove an existing component.
var result = content.Tags.Remove("MyTag");

//Repalce an existing component.
var result = content.Tags.Find("MyTag").Replace(tag);

//Configure individual properties.
var tag = content.Tags.Get("MyTag");
tag.Value = 100;
tag.Description = "This is an update";
tag.ExternalAccess = ExternalAccess.ReadOnly;
tag.Constant = true;

//Apply update funtion to all components that satisfy a condition.
content.Tags.Update(t => t.DataType == "TIMER", t => t.Description = "Updated TIMER description");

//Save changes when done.
content.Save("C:\PathToMyOutputFile\FileName.L5X");

Release Notes

Version 2.0

This release follows from version 0.19.X. The reason for the version change is to represent this as a mostly complete and no longer a work in progress library. The reason for v2 and not v1 is because I accidentally released v1 a long time ago before backing into v0.1.

This update mostly focused on adding .NET 2.0 standard support and merging how LogixTypes were deserialized with how all other LogixElements were deserialized, which makes the entire project more uniform and gives one point for deserialization of any element/type. Most of the API surface is the same with a couple minor tweaks. You should not notice too may changes.

Highlights
  1. Adds support for .NET Standard 2.0 to make library compatible with .NET Framework applications.
  2. LogixType now implements LogixElement, making them wrap an underlying element where possible, and allowing a single base class for all types.
  3. Combined the old LogixData with the LogixSerializer to have a single point of deserialization for all elements.
  4. Created new LogixObject which implements LogixElement and moved the common L5X, Scope, Container, and methods for adding, replacing, and removing the object from the L5X.
  5. Removed AtomicType bit members to avoid exceedingly large number of member tags it would generate when attemping to all tags in a file.
  6. Removed Class and Family properties from LogixType since they are not really useful.
  7. Renamed LogixType to LogixData, as well as all derivatives to better match the L5X naming convention.

Documentation

I started working on a GitHub Page here for more in depth articles and API documentation, but it's a work in progress so bear with me. In fact it is currently out of date, so reference this readme for the most up to date information. If you think something is unclear or can be improved upon, feel free to let me know in the issues tab of the project repository.

Feedback

If you like or use this project, leave a star. If you have questions or issues, please post in the issues tab of the project repository. Any feedback is always appreciated. If you have ideas or suggestions for features or things that would make this library more useful, I welcome your idea! Just send me a message.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on L5Sharp:

Package Downloads
L5Sharp.Extensions

A library for intuitively interacting with Rockwell's L5X import/export files.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.7.1 78 11/15/2024
4.7.0 69 11/15/2024
4.6.0 84 11/14/2024
4.5.0 85 11/11/2024
4.4.0 87 10/31/2024
4.3.0 81 10/30/2024
4.2.0 126 10/8/2024
4.1.0 87 10/7/2024
4.0.0 89 10/5/2024
3.3.1 105 9/24/2024
3.3.0 130 7/29/2024
3.2.0 121 7/7/2024
3.1.0 94 7/5/2024
3.0.0 114 6/3/2024
2.3.2 90 5/9/2024
2.3.1 344 5/6/2024
2.3.0 123 5/4/2024
2.2.1 111 4/29/2024
2.2.0 117 4/23/2024
2.1.0 110 4/18/2024
2.0.0 174 4/4/2024
0.19.7 135 3/27/2024
0.19.6 232 3/22/2024
0.19.5 128 3/9/2024
0.19.4 123 2/5/2024
0.19.3 104 2/3/2024
0.19.1 116 1/16/2024
0.19.0 95 1/16/2024
0.18.3 127 1/8/2024
0.18.2 113 1/4/2024
0.18.1 111 12/29/2023
0.18.0 157 12/9/2023
0.17.0 145 12/8/2023
0.16.1 128 11/28/2023
0.16.0 124 11/28/2023
0.15.2 186 8/18/2023
0.15.1 151 8/17/2023
0.15.0 196 8/16/2023
0.14.0 195 8/9/2023
0.13.0 201 8/6/2023
0.12.0 180 8/1/2023
0.11.0 171 7/12/2023
0.10.1 235 3/31/2023
0.10.0 202 3/31/2023
0.9.2 208 3/24/2023
0.9.1 222 3/15/2023
0.9.0 226 3/15/2023
0.8.0 227 3/15/2023
0.7.0 211 3/14/2023
0.6.0 217 3/14/2023
0.5.3 221 3/13/2023
0.5.2 218 3/13/2023
0.5.0 222 3/13/2023
0.4.0 230 3/12/2023
0.3.0 233 3/5/2023
0.2.0 283 3/1/2023

LogixContainer now implements IList{T} and ICollection, slightly changes the API.
           LogixObject{T}, LogixComponent{T} created and add ILogixParsable{T} making all components and some elements able to be parsed dynamically using LogixParser extensions.
           Update TagName Concat() to reduce memory consumption.
           Added methods to AddOnInstruction for generating NeutralText and Instruction instances.