|
| 1 | +# l5x |
| 2 | + |
| 3 | +A Rust library for parsing Rockwell Automation L5X files exported from Studio 5000 Logix Designer. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Fast, type-safe parsing** using quick-xml and serde |
| 8 | +- **Complete L5X schema support** - 247 types generated from the official XSD |
| 9 | +- **RLL (Relay Ladder Logic) parsing** - parse ladder logic instructions into AST |
| 10 | +- **Tag reference extraction** - find all tag references in rungs |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Add to your `Cargo.toml`: |
| 15 | + |
| 16 | +```toml |
| 17 | +[dependencies] |
| 18 | +l5x = "0.3" |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +### Parse an L5X file |
| 24 | + |
| 25 | +```rust |
| 26 | +use l5x::Project; |
| 27 | + |
| 28 | +let xml = std::fs::read_to_string("project.L5X")?; |
| 29 | +let project: Project = l5x::from_str(&xml)?; |
| 30 | + |
| 31 | +// Access controller information |
| 32 | +println!("Controller: {}", project.controller.name); |
| 33 | + |
| 34 | +// Iterate over programs |
| 35 | +for program in &project.controller.programs.program { |
| 36 | + println!("Program: {}", program.name); |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Parse ladder logic rungs |
| 41 | + |
| 42 | +```rust |
| 43 | +use l5x::rll::parse_rung; |
| 44 | + |
| 45 | +let rung = parse_rung("XIC(Start)OTE(Motor);"); |
| 46 | + |
| 47 | +// Extract tag references |
| 48 | +for tag in rung.tag_references() { |
| 49 | + println!("Tag: {} ({})", tag.name, if tag.is_write { "write" } else { "read" }); |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### Access tags and data types |
| 54 | + |
| 55 | +```rust |
| 56 | +use l5x::Project; |
| 57 | + |
| 58 | +let project: Project = l5x::from_str(&xml)?; |
| 59 | + |
| 60 | +// Controller-scoped tags |
| 61 | +if let Some(tags) = &project.controller.tags { |
| 62 | + for tag in &tags.tag { |
| 63 | + println!("Tag: {} : {}", tag.name, tag.data_type); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +// User-defined types |
| 68 | +if let Some(datatypes) = &project.controller.data_types { |
| 69 | + for dt in &datatypes.data_type { |
| 70 | + println!("DataType: {}", dt.name); |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## L5X File Format |
| 76 | + |
| 77 | +L5X is an XML-based export format for Rockwell Automation PLCs. This crate supports: |
| 78 | + |
| 79 | +- **Controllers**: ControlLogix, CompactLogix |
| 80 | +- **Programs**: with routines in RLL, ST, FBD, SFC |
| 81 | +- **Tags**: Controller and program-scoped |
| 82 | +- **Data Types**: Built-in and user-defined (UDTs) |
| 83 | +- **Add-On Instructions (AOIs)** |
| 84 | +- **Modules**: I/O configuration |
| 85 | +- **Tasks**: Continuous, periodic, event |
| 86 | + |
| 87 | +## RLL Instruction Support |
| 88 | + |
| 89 | +The RLL parser handles standard ladder logic syntax: |
| 90 | + |
| 91 | +- **Instructions**: XIC, XIO, OTE, OTL, OTU, TON, TOF, CTU, CTD, MOV, ADD, etc. |
| 92 | +- **Branches**: Parallel and series connections |
| 93 | +- **Expressions**: Arithmetic and comparison in CMP, CPT, etc. |
| 94 | +- **Arrays**: Multi-dimensional with literal or tag indices |
| 95 | +- **Structured tags**: Member access (e.g., `Timer.DN`) |
| 96 | + |
| 97 | +## Disclaimer |
| 98 | + |
| 99 | +This is an independent open-source project and is not affiliated with, endorsed by, sponsored by, or associated with Rockwell Automation, Inc. or any of its subsidiaries or affiliates. |
| 100 | + |
| 101 | +"Rockwell Automation", "Allen-Bradley", "Studio 5000", "Logix Designer", "ControlLogix", and "CompactLogix" are trademarks of Rockwell Automation, Inc. |
| 102 | + |
0 commit comments