Skip to content

Commit ca97f33

Browse files
committed
implement openplc
1 parent 1241c51 commit ca97f33

19 files changed

Lines changed: 2629 additions & 0 deletions

‎Cargo.lock‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"iectypes",
55
"plcmodel",
66
"l5x",
7+
"plcopen",
78
"iecst",
89
"plceye",
910
"plcviz",

‎plcopen/Cargo.toml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "plcopen"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Parser for PLCopen TC6 XML files (IEC 61131-3 standard exchange format)"
6+
license = "MIT"
7+
repository = "https://github.com/radevgit/plc"
8+
homepage = "https://github.com/radevgit/plc"
9+
documentation = "https://docs.rs/plcopen"
10+
readme = "README.md"
11+
keywords = ["plc", "plcopen", "iec-61131", "automation", "xml"]
12+
categories = ["parsing", "development-tools"]
13+
authors = ["radevgit"]
14+
rust-version = "1.70"
15+
16+
[dependencies]
17+
quick-xml = { version = "0.37", features = ["serialize", "overlapped-lists"] }
18+
serde = { version = "1.0", features = ["derive"] }
19+
iecst = "0.1"

‎plcopen/LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 radevgit
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎plcopen/README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# plcopen
2+
3+
Parser for PLCopen TC6 XML files - the IEC 61131-3 standard exchange format for PLC programs.
4+
5+
## Features
6+
7+
- Type-safe parsing using quick-xml and serde
8+
- Generated types from the official PLCopen TC6 XML schema (v2.01)
9+
- Support for all IEC 61131-3 languages (ST, IL, LD, FBD, SFC)
10+
11+
## Usage
12+
13+
```rust
14+
use plcopen::Project;
15+
16+
// Parse PLCopen XML file
17+
let xml = std::fs::read_to_string("project.xml")?;
18+
let project: Project = plcopen::from_str(&xml)?;
19+
println!("Project: {:?}", project);
20+
```
21+
22+
## PLCopen TC6 XML Format
23+
24+
PLCopen TC6 is an XML-based exchange format defined by the PLCopen organization
25+
for transferring PLC programs between different development environments. It supports:
26+
27+
- **Program Organization Units (POUs)**: Programs, Functions, Function Blocks
28+
- **Data Types**: Elementary types (BOOL, INT, REAL, etc.) and user-defined types
29+
- **Variables**: Input, Output, InOut, Local, Global, External
30+
- **Languages**: ST (Structured Text), IL (Instruction List), LD (Ladder), FBD (Function Block Diagram), SFC (Sequential Function Chart)
31+
32+
## License
33+
34+
MIT

‎plcopen/generated/generated.rs‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Auto-generated PLCopen types from TC6 XML schema
2+
// DO NOT EDIT - Generated by build script
3+
4+
use serde::{Serialize, Deserialize};
5+
6+
#[path = "generated_sfc.rs"]
7+
mod sfc;
8+
#[path = "generated_variables.rs"]
9+
mod variables;
10+
#[path = "generated_body.rs"]
11+
mod body;
12+
#[path = "generated_config.rs"]
13+
mod config;
14+
#[path = "generated_misc.rs"]
15+
mod misc;
16+
#[path = "generated_ladder.rs"]
17+
mod ladder;
18+
#[path = "generated_fbd.rs"]
19+
mod fbd;
20+
#[path = "generated_datatypes.rs"]
21+
mod datatypes;
22+
#[path = "generated_inline.rs"]
23+
mod inline;
24+
#[path = "generated_pou.rs"]
25+
mod pou;
26+
#[path = "generated_graphics.rs"]
27+
mod graphics;
28+
#[path = "generated_addons.rs"]
29+
mod addons;
30+
pub use self::{
31+
sfc::*,
32+
variables::*,
33+
body::*,
34+
config::*,
35+
misc::*,
36+
ladder::*,
37+
fbd::*,
38+
datatypes::*,
39+
inline::*,
40+
pou::*,
41+
graphics::*,
42+
addons::*
43+
};
44+
45+
/// Placeholder for xs:any wildcard elements
46+
/// quick-xml cannot deserialize dynamic element names, so these are skipped
47+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
48+
pub struct AnyElement;
49+
50+
/// elementaryTypes choice group
51+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
52+
pub enum ElementaryTypes {
53+
BOOL(String),
54+
BYTE(String),
55+
WORD(String),
56+
DWORD(String),
57+
LWORD(String),
58+
SINT(String),
59+
INT(String),
60+
DINT(String),
61+
LINT(String),
62+
USINT(String),
63+
UINT(String),
64+
UDINT(String),
65+
ULINT(String),
66+
REAL(String),
67+
LREAL(String),
68+
TIME(String),
69+
DATE(String),
70+
DT(String),
71+
TOD(String),
72+
String(ElementaryTypes_string_Inline),
73+
Wstring(ElementaryTypes_wstring_Inline),
74+
ANY(String),
75+
ANY_DERIVED(String),
76+
ANY_ELEMENTARY(String),
77+
ANY_MAGNITUDE(String),
78+
ANY_NUM(String),
79+
ANY_REAL(String),
80+
ANY_INT(String),
81+
ANY_BIT(String),
82+
ANY_STRING(String),
83+
ANY_DATE(String),
84+
}
85+
86+
/// derivedTypes choice group
87+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
88+
pub enum DerivedTypes {
89+
Array(DerivedTypes_array_Inline),
90+
Derived(DerivedTypes_derived_Inline),
91+
#[serde(rename = "enum")]
92+
Enumeration(DerivedTypes_enum_Inline),
93+
#[serde(rename = "struct")]
94+
Structure(VarListPlain),
95+
SubrangeSigned(DerivedTypes_subrangeSigned_Inline),
96+
SubrangeUnsigned(DerivedTypes_subrangeUnsigned_Inline),
97+
}
98+
99+
/// extended choice group
100+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
101+
pub enum Extended {
102+
Pointer(Extended_pointer_Inline),
103+
}
104+
105+
/// commonObjects choice group
106+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
107+
pub enum CommonObjects {
108+
Comment(CommonObjects_comment_Inline),
109+
Error(CommonObjects_error_Inline),
110+
Connector(CommonObjects_connector_Inline),
111+
Continuation(CommonObjects_continuation_Inline),
112+
ActionBlock(CommonObjects_actionBlock_Inline),
113+
VendorElement(CommonObjects_vendorElement_Inline),
114+
}
115+
116+
/// fbdObjects choice group
117+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
118+
pub enum FbdObjects {
119+
Block(FbdObjects_block_Inline),
120+
InVariable(FbdObjects_inVariable_Inline),
121+
OutVariable(FbdObjects_outVariable_Inline),
122+
InOutVariable(FbdObjects_inOutVariable_Inline),
123+
Label(FbdObjects_label_Inline),
124+
Jump(FbdObjects_jump_Inline),
125+
#[serde(rename = "return")]
126+
Return(FbdObjects_return_Inline),
127+
}
128+
129+
/// ldObjects choice group
130+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
131+
pub enum LdObjects {
132+
LeftPowerRail(LdObjects_leftPowerRail_Inline),
133+
RightPowerRail(LdObjects_rightPowerRail_Inline),
134+
Coil(LdObjects_coil_Inline),
135+
Contact(LdObjects_contact_Inline),
136+
}
137+
138+
/// sfcObjects choice group
139+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
140+
pub enum SfcObjects {
141+
Step(SfcObjects_step_Inline),
142+
MacroStep(SfcObjects_macroStep_Inline),
143+
JumpStep(SfcObjects_jumpStep_Inline),
144+
Transition(SfcObjects_transition_Inline),
145+
SelectionDivergence(SfcObjects_selectionDivergence_Inline),
146+
SelectionConvergence(SfcObjects_selectionConvergence_Inline),
147+
SimultaneousDivergence(SfcObjects_simultaneousDivergence_Inline),
148+
SimultaneousConvergence(SfcObjects_simultaneousConvergence_Inline),
149+
}
150+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Auto-generated PLCopen types - addons category
2+
// DO NOT EDIT - Generated by build script
3+
4+
use serde::{Serialize, Deserialize};
5+
use super::*;
6+
7+
/// addData element
8+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
9+
pub struct AddData {
10+
/// data element
11+
#[serde(rename = "data", default)]
12+
pub data: Vec<AddData_data_Inline>,
13+
}
14+
15+
/// addData_data_InlineType element
16+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
17+
pub struct AddData_data_Inline {
18+
/// name attribute
19+
#[serde(rename = "@name", default)]
20+
pub name: String,
21+
/// handleUnknown attribute
22+
#[serde(rename = "@handleUnknown", default)]
23+
pub handle_unknown: String,
24+
/// Arbitrary child elements (xs:any) - skipped during deserialization
25+
#[serde(skip)]
26+
pub children: Vec<AnyElement>,
27+
}
28+
29+
/// addDataInfo element
30+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
31+
pub struct AddDataInfo {
32+
/// info element
33+
#[serde(rename = "info", default)]
34+
pub info: Vec<AddDataInfo_info_Inline>,
35+
}
36+
37+
/// addDataInfo_info_InlineType element
38+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
39+
pub struct AddDataInfo_info_Inline {
40+
/// name attribute
41+
#[serde(rename = "@name", default)]
42+
pub name: String,
43+
/// version attribute
44+
#[serde(rename = "@version", default)]
45+
pub version: Option<String>,
46+
/// vendor attribute
47+
#[serde(rename = "@vendor", default)]
48+
pub vendor: String,
49+
/// description element
50+
#[serde(rename = "description", default)]
51+
pub description: Option<FormattedText>,
52+
}
53+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Auto-generated PLCopen types - body category
2+
// DO NOT EDIT - Generated by build script
3+
4+
use serde::{Serialize, Deserialize};
5+
use super::*;
6+
7+
/// body element
8+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
9+
pub struct Body {
10+
/// WorksheetName attribute
11+
#[serde(rename = "@WorksheetName", default)]
12+
pub worksheet_name: Option<String>,
13+
/// globalId attribute
14+
#[serde(rename = "@globalId", default)]
15+
pub global_id: Option<String>,
16+
/// IL element
17+
#[serde(rename = "IL", default)]
18+
pub il: Option<FormattedText>,
19+
/// ST element
20+
#[serde(rename = "ST", default)]
21+
pub st: Option<FormattedText>,
22+
/// FBD element
23+
#[serde(rename = "FBD", default)]
24+
pub fbd: Option<Body_FBD_Inline>,
25+
/// LD element
26+
#[serde(rename = "LD", default)]
27+
pub ld: Option<Body_LD_Inline>,
28+
/// SFC element
29+
#[serde(rename = "SFC", default)]
30+
pub sfc: Option<Body_SFC_Inline>,
31+
/// addData element
32+
#[serde(rename = "addData", default)]
33+
pub add_data: Option<AddData>,
34+
/// documentation element
35+
#[serde(rename = "documentation", default)]
36+
pub documentation: Option<FormattedText>,
37+
}
38+
39+
/// body_FBD_InlineType element
40+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
41+
pub struct Body_FBD_Inline {
42+
}
43+
44+
/// body_LD_InlineType element
45+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
46+
pub struct Body_LD_Inline {
47+
}
48+
49+
/// body_SFC_InlineType element
50+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
51+
pub struct Body_SFC_Inline {
52+
}
53+

0 commit comments

Comments
 (0)