Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"iectypes",
"plcmodel",
"l5x",
"plcopen",
"iecst",
"plceye",
"plcviz",
Expand Down
19 changes: 19 additions & 0 deletions plcopen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "plcopen"
version = "0.1.0"
edition = "2021"
description = "Parser for PLCopen TC6 XML files (IEC 61131-3 standard exchange format)"
license = "MIT"
repository = "https://github.com/radevgit/plc"
homepage = "https://github.com/radevgit/plc"
documentation = "https://docs.rs/plcopen"
readme = "README.md"
keywords = ["plc", "plcopen", "iec-61131", "automation", "xml"]
categories = ["parsing", "development-tools"]
authors = ["radevgit"]
rust-version = "1.70"

[dependencies]
quick-xml = { version = "0.37", features = ["serialize", "overlapped-lists"] }
serde = { version = "1.0", features = ["derive"] }
iecst = "0.1"
21 changes: 21 additions & 0 deletions plcopen/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 radevgit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions plcopen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# plcopen

Parser for PLCopen TC6 XML files - the IEC 61131-3 standard exchange format for PLC programs.

## Features

- Type-safe parsing using quick-xml and serde
- Generated types from the official PLCopen TC6 XML schema (v2.01)
- Support for all IEC 61131-3 languages (ST, IL, LD, FBD, SFC)

## Usage

```rust
use plcopen::Project;

// Parse PLCopen XML file
let xml = std::fs::read_to_string("project.xml")?;
let project: Project = plcopen::from_str(&xml)?;
println!("Project: {:?}", project);
```

## PLCopen TC6 XML Format

PLCopen TC6 is an XML-based exchange format defined by the PLCopen organization
for transferring PLC programs between different development environments. It supports:

- **Program Organization Units (POUs)**: Programs, Functions, Function Blocks
- **Data Types**: Elementary types (BOOL, INT, REAL, etc.) and user-defined types
- **Variables**: Input, Output, InOut, Local, Global, External
- **Languages**: ST (Structured Text), IL (Instruction List), LD (Ladder), FBD (Function Block Diagram), SFC (Sequential Function Chart)

## License

MIT
150 changes: 150 additions & 0 deletions plcopen/generated/generated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Auto-generated PLCopen types from TC6 XML schema
// DO NOT EDIT - Generated by build script

use serde::{Serialize, Deserialize};

#[path = "generated_sfc.rs"]
mod sfc;
#[path = "generated_variables.rs"]
mod variables;
#[path = "generated_body.rs"]
mod body;
#[path = "generated_config.rs"]
mod config;
#[path = "generated_misc.rs"]
mod misc;
#[path = "generated_ladder.rs"]
mod ladder;
#[path = "generated_fbd.rs"]
mod fbd;
#[path = "generated_datatypes.rs"]
mod datatypes;
#[path = "generated_inline.rs"]
mod inline;
#[path = "generated_pou.rs"]
mod pou;
#[path = "generated_graphics.rs"]
mod graphics;
#[path = "generated_addons.rs"]
mod addons;
pub use self::{
sfc::*,
variables::*,
body::*,
config::*,
misc::*,
ladder::*,
fbd::*,
datatypes::*,
inline::*,
pou::*,
graphics::*,
addons::*
};

/// Placeholder for xs:any wildcard elements
/// quick-xml cannot deserialize dynamic element names, so these are skipped
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AnyElement;

/// elementaryTypes choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ElementaryTypes {
BOOL(String),
BYTE(String),
WORD(String),
DWORD(String),
LWORD(String),
SINT(String),
INT(String),
DINT(String),
LINT(String),
USINT(String),
UINT(String),
UDINT(String),
ULINT(String),
REAL(String),
LREAL(String),
TIME(String),
DATE(String),
DT(String),
TOD(String),
String(ElementaryTypes_string_Inline),
Wstring(ElementaryTypes_wstring_Inline),
ANY(String),
ANY_DERIVED(String),
ANY_ELEMENTARY(String),
ANY_MAGNITUDE(String),
ANY_NUM(String),
ANY_REAL(String),
ANY_INT(String),
ANY_BIT(String),
ANY_STRING(String),
ANY_DATE(String),
}

/// derivedTypes choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DerivedTypes {
Array(DerivedTypes_array_Inline),
Derived(DerivedTypes_derived_Inline),
#[serde(rename = "enum")]
Enumeration(DerivedTypes_enum_Inline),
#[serde(rename = "struct")]
Structure(VarListPlain),
SubrangeSigned(DerivedTypes_subrangeSigned_Inline),
SubrangeUnsigned(DerivedTypes_subrangeUnsigned_Inline),
}

/// extended choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Extended {
Pointer(Extended_pointer_Inline),
}

/// commonObjects choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CommonObjects {
Comment(CommonObjects_comment_Inline),
Error(CommonObjects_error_Inline),
Connector(CommonObjects_connector_Inline),
Continuation(CommonObjects_continuation_Inline),
ActionBlock(CommonObjects_actionBlock_Inline),
VendorElement(CommonObjects_vendorElement_Inline),
}

/// fbdObjects choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum FbdObjects {
Block(FbdObjects_block_Inline),
InVariable(FbdObjects_inVariable_Inline),
OutVariable(FbdObjects_outVariable_Inline),
InOutVariable(FbdObjects_inOutVariable_Inline),
Label(FbdObjects_label_Inline),
Jump(FbdObjects_jump_Inline),
#[serde(rename = "return")]
Return(FbdObjects_return_Inline),
}

/// ldObjects choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum LdObjects {
LeftPowerRail(LdObjects_leftPowerRail_Inline),
RightPowerRail(LdObjects_rightPowerRail_Inline),
Coil(LdObjects_coil_Inline),
Contact(LdObjects_contact_Inline),
}

/// sfcObjects choice group
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SfcObjects {
Step(SfcObjects_step_Inline),
MacroStep(SfcObjects_macroStep_Inline),
JumpStep(SfcObjects_jumpStep_Inline),
Transition(SfcObjects_transition_Inline),
SelectionDivergence(SfcObjects_selectionDivergence_Inline),
SelectionConvergence(SfcObjects_selectionConvergence_Inline),
SimultaneousDivergence(SfcObjects_simultaneousDivergence_Inline),
SimultaneousConvergence(SfcObjects_simultaneousConvergence_Inline),
}

53 changes: 53 additions & 0 deletions plcopen/generated/generated_addons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Auto-generated PLCopen types - addons category
// DO NOT EDIT - Generated by build script

use serde::{Serialize, Deserialize};
use super::*;

/// addData element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddData {
/// data element
#[serde(rename = "data", default)]
pub data: Vec<AddData_data_Inline>,
}

/// addData_data_InlineType element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddData_data_Inline {
/// name attribute
#[serde(rename = "@name", default)]
pub name: String,
/// handleUnknown attribute
#[serde(rename = "@handleUnknown", default)]
pub handle_unknown: String,
/// Arbitrary child elements (xs:any) - skipped during deserialization
#[serde(skip)]
pub children: Vec<AnyElement>,
}

/// addDataInfo element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddDataInfo {
/// info element
#[serde(rename = "info", default)]
pub info: Vec<AddDataInfo_info_Inline>,
}

/// addDataInfo_info_InlineType element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddDataInfo_info_Inline {
/// name attribute
#[serde(rename = "@name", default)]
pub name: String,
/// version attribute
#[serde(rename = "@version", default)]
pub version: Option<String>,
/// vendor attribute
#[serde(rename = "@vendor", default)]
pub vendor: String,
/// description element
#[serde(rename = "description", default)]
pub description: Option<FormattedText>,
}

53 changes: 53 additions & 0 deletions plcopen/generated/generated_body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Auto-generated PLCopen types - body category
// DO NOT EDIT - Generated by build script

use serde::{Serialize, Deserialize};
use super::*;

/// body element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Body {
/// WorksheetName attribute
#[serde(rename = "@WorksheetName", default)]
pub worksheet_name: Option<String>,
/// globalId attribute
#[serde(rename = "@globalId", default)]
pub global_id: Option<String>,
/// IL element
#[serde(rename = "IL", default)]
pub il: Option<FormattedText>,
/// ST element
#[serde(rename = "ST", default)]
pub st: Option<FormattedText>,
/// FBD element
#[serde(rename = "FBD", default)]
pub fbd: Option<Body_FBD_Inline>,
/// LD element
#[serde(rename = "LD", default)]
pub ld: Option<Body_LD_Inline>,
/// SFC element
#[serde(rename = "SFC", default)]
pub sfc: Option<Body_SFC_Inline>,
/// addData element
#[serde(rename = "addData", default)]
pub add_data: Option<AddData>,
/// documentation element
#[serde(rename = "documentation", default)]
pub documentation: Option<FormattedText>,
}

/// body_FBD_InlineType element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Body_FBD_Inline {
}

/// body_LD_InlineType element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Body_LD_Inline {
}

/// body_SFC_InlineType element
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Body_SFC_Inline {
}

Loading