Skip to content

Commit

Permalink
More testing and docs updates. Adding new release
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunnink committed Nov 28, 2023
1 parent 5ce0fa4 commit 231439e
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 154 deletions.
85 changes: 74 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ The following are some high level goals this project aimed to accomplish.
4. Support strongly typed mutable tag data, so we can reference complex structures statically at compile time.

## Packages
You cna consume the library via Nuget.
You can consume the library via NuGet.
```powershell
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 will want all functionality anyway. `L5Sharp.Extensions` is no longer maintained.
> I think most people would want all functionality anyway. `L5Sharp.Extensions` is no longer maintained.
## Quick Start
1. Install package from Nuget.
```powershell
Install-Package L5Sharp
```
2. Load an L5X file using the `L5X` class static factory method like so.
2. Load an L5X file using the `L5X` class static factory methods.
```c#
var content = L5X.Load("C:\PathToMyFile\FileName.L5X");
```
Expand All @@ -52,11 +52,25 @@ Description, and Preset value in a flat list ordered by TagName.
The following is some basic examples of how you can use this library
to query and modify the L5X content.
#### Querying
Once the LogixContent is created, you can use the container properties
to get access to all of the primary L5X components,
such as `Tag`, `DataType`, `Module`, `Program`, and more.
The following shows some simple querying via the `Tags` component container.
### 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.
```c#
//Get all controller tags.
var tags = content.Tags.ToList();
Expand All @@ -67,10 +81,59 @@ var tag = content.Tags.Find("MyTag");
//Use LINQ to query further.
var results = content.Tags.Where(t => t.DataType == "TIMER");
```
#### Modifying
Modifying components is simple as well.
##### 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.
```csharp
//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.
```csharp
//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.
```csharp
//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.
removing, and updating components.

```csharp
//Add a new component.
Expand Down
76 changes: 32 additions & 44 deletions src/.idea/.idea.L5Sharp/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 231439e

Please sign in to comment.