Skip to content

Add unified Rockwell PLC file parser supporting L5X, L5K, and ACD formats#1

Open
FishmanL wants to merge 3 commits intomasterfrom
claude/rockwell-plc-file-support-zynwD
Open

Add unified Rockwell PLC file parser supporting L5X, L5K, and ACD formats#1
FishmanL wants to merge 3 commits intomasterfrom
claude/rockwell-plc-file-support-zynwD

Conversation

@FishmanL
Copy link
Contributor

Summary

This PR adds comprehensive support for parsing Rockwell/Allen-Bradley PLC files in multiple formats (L5X, L5K, ACD) into the ontology pipeline. Previously, only pre-exported .sc files were supported. Now the system can directly ingest native Rockwell project files and automatically detect their format.

Key Changes

  • New L5K Parser (scripts/l5k_parser.py): Full ASCII text project file parser that converts L5K format into SCFile objects. Handles controller definitions, data types, tags, programs, routines, and add-on instructions with proper scope tracking.

  • New ACD Parser (scripts/acd_parser.py): Binary project file parser with fallback support. Uses acd-tools library when available, otherwise extracts embedded XML from the ACD archive and parses with L5X parser.

  • Unified Rockwell Handler (scripts/rockwell_export.py): Auto-detection and routing system that identifies file format (L5X, L5K, ACD, RSS) and dispatches to appropriate parser. Provides consistent interface for single files and directory processing.

  • Enhanced L5X Parser (scripts/l5x_export.py): Extended to handle full-project L5X files (not just component exports). Added extraction of controller-scoped tags, programs, tasks, and routines with proper hierarchy preservation.

  • Ontology Pipeline Integration (scripts/ontology_analyzer.py): New analyze_rockwell_file() method integrates Rockwell file analysis into the existing ontology workflow. Auto-detects format and processes through standard SCFile pipeline.

  • Comprehensive Test Suite (tests/test_rockwell_parsers.py): 434-line test suite covering format detection, parsing of real-world L5X/L5K samples, tag extraction, routine parsing, and cross-format consistency.

  • Real-World Test Samples: Added 8 real L5X files from GitHub (AOI_AVERAGE, AOI_DEBOUNCER, AOI_CV_CONTROL, AOI_RAMP_BASIC, AOI_METER_ORIFICE, Op_Interlock, Op_Permissive) plus synthetic L5X/L5K samples for comprehensive coverage.

  • UI Updates: Updated Electron UI file filters and labels to reflect support for L5X, L5K, and ACD formats.

  • PowerShell Ingestion Script (rockwell-ingest.ps1): Windows automation script for batch processing Rockwell files with format auto-detection.

Implementation Details

  • Format Detection: Extension-based with content validation (XML signature for L5X, IE_VER keyword for L5K, ZIP structure for ACD)
  • Scope Tracking: L5K parser maintains proper nesting of controller → datatype → tag → program → routine hierarchy
  • Tag Direction Mapping: Converts Usage attributes (Input/Output/InOut) to standard direction enums
  • Fallback Strategy: ACD parser gracefully degrades to XML extraction if acd-tools unavailable
  • Comment Sanitization: L5K parser handles multi-line comments and CDATA sections
  • Array Handling: Proper dimension parsing for array tags with bounds calculation

All parsers output to the same SCFile data structure, enabling seamless integration with existing ontology analysis, Claude AI processing, and Neo4j storage.

https://claude.ai/code/session_01EwxozRVY1P6ZfDHtQbNHQk

Extends the ontology ingestion pipeline beyond L5X-only to handle all
Rockwell/Allen-Bradley PLC file formats with auto-detection.

New parsers:
- l5k_parser.py: Parses L5K ASCII text projects (CONTROLLER/DATATYPE/
  TAG/PROGRAM/ROUTINE blocks) into SCFile objects
- acd_parser.py: Parses ACD binary archives via acd-tools library with
  fallback XML extraction when library is unavailable
- rockwell_export.py: Unified entry point that auto-detects format from
  extension/content and routes to the appropriate parser

Enhanced L5X support:
- Full project parsing (Programs, controller-scoped Tags, FBD/SFC routines)
- L5XParser class returns SCFile objects directly for pipeline integration
- New _export_program_from_l5x and _export_controller_tags functions

Pipeline integration:
- ontology_analyzer.py: --rockwell flag, auto-detection for .L5X/.L5K/.ACD
- analyze_rockwell_file() and analyze_rockwell_directory() methods
- Frontend file dialogs updated to accept L5K and ACD formats
- Backend IPC handler passes --rockwell for native Rockwell files

Also includes:
- rockwell-ingest.ps1: Unified PowerShell driver for all Rockwell formats
- Sample L5K and L5X full-project test files (water treatment, conveyor)

https://claude.ai/code/session_01EwxozRVY1P6ZfDHtQbNHQk
…ssing)

- Add 7 real Rockwell L5X files from GitHub (AOI_DEBOUNCER, AOI_RAMP_BASIC,
  AOI_CV_CONTROL, AOI_AVERAGE, AOI_METER_ORIFICE, Op_Interlock, Op_Permissive)
- Create comprehensive test suite covering format detection, L5X parsing,
  L5K parsing, unified parser, and .sc export with 30 automated tests
- Fix multi-line description/comment handling in .sc export (_sanitize_comment)
- Tests verify: tag extraction, rung/comment parsing, structured text content,
  multi-component files, UDT dependencies, and round-trip export

https://claude.ai/code/session_01EwxozRVY1P6ZfDHtQbNHQk
…ional array parsing

New test samples (7 TargetTypes covered):
- Controller: basetest (1756-L75), EXAMPLE_FACTORY (1769-L33ER), L5x_Creation (minimal + populated)
- Program: pycomm3 (467KB, comprehensive tags), Buffertank ISA-88 (1MB), CIP (950KB), Snake Game
- Routine: PushButton (Ladder), Ladder minimal, TimeAndDate (Structured Text)
- Rung: PackML state handler single rung
- Module: Pilz Safety module config
- DataType: Sample UDT
- AOI: ISA-88 PackML state machine

Parser fix: Handle multi-dimensional array Dimensions attributes (e.g. "10 10", "2 4")
which are space-separated in L5X, generating proper "0..9,0..9" bounds notation.

All 30 tests passing with 22 subtests (one per L5X file).

https://claude.ai/code/session_01EwxozRVY1P6ZfDHtQbNHQk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments