Skip to content

Commit 2147fd4

Browse files
author
Canaan Seaton
committed
another commit
1 parent e3fbdd6 commit 2147fd4

21 files changed

+533
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# Visual Studio Code Settings Folder
1616
.vscode
1717

18+
# Ignore build and distribution directories
19+
/build/
20+
/dist/
21+
1822
#pypirc
1923
*.pypirc
2024

src/build/lib/AB/Rockwell/Types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from enum import Enum
2+
3+
class CommonType:
4+
BOOL = "BOOL"
5+
SINT = "SINT"
6+
INT = "INT"
7+
DINT = "DINT"
8+
REAL = "REAL"
9+
STRING = "STRING"
10+
COUNTER = "COUNTER"
11+
TIMER = "TIMER"
12+
13+
class UserDefinedTypes:
14+
ALARM = "ST_Alarms"
15+
ONE_BUTTON = "PB_OneButton"
16+
TWO_BUTTON = "PB_TwoButton"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
import os
8+
from AB.Rockwell.XML.Tools import *
9+
10+
class Base_Template():
11+
'''
12+
Base Template Template:
13+
See L5X Manual for Details,
14+
USED FOR INHERITANCE ONLY
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self):
19+
#Initialize Member Attributes
20+
self.root = None
21+
22+
def checkIfChild(self, nodeTag):
23+
assert type(nodeTag) == str
24+
for node in self.root:
25+
if node.tag == nodeTag: return True
26+
return False
27+
28+
def setAttribute(self, kwargs):
29+
for key in kwargs:
30+
if not key in self.root.keys():
31+
raise KeyError("%s has No Attribute: <%s>" % (self.root.tag, key))
32+
33+
for key in kwargs:
34+
self.root.set(key, kwargs[key])
35+
36+
def setDescription(self, Description):
37+
assert type(Description) == str
38+
if self.Desc == None:
39+
self.Desc = etree.SubElement(self.root, 'Description')
40+
self.root.append(self.Desc)
41+
self.Desc.text = etree.CDATA(Description)
42+
43+
def setParent(self, parent):
44+
pass
45+
46+
def getLocalRoot(self):
47+
return self.root
48+
49+
def __str__(self):
50+
return etree.tostring(self.root, pretty_print = True, xml_declaration = True, encoding = "UTF-8", standalone = "yes")
51+
52+
def writeToFile(self, fileName = os.getcwd() + "/L5X_Printable.L5X"):
53+
tree = etree.ElementTree(self.root)
54+
tree.write(fileName, pretty_print = True, xml_declaration = True, encoding = "UTF-8", standalone = "yes")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Controller(Base_Template):
11+
'''
12+
Controller Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a Controller.
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self, Name, Use = "Context", Description = ""):
19+
#Initialize Member Attributes
20+
assert isValidTag(Name)
21+
self.root = etree.Element('Controller')
22+
if Description != "":
23+
self.Desc = etree.SubElement(self.root, 'Description')
24+
self.setDescription(Description)
25+
self.root.append(self.Desc)
26+
27+
def addDatatype(self, Datatype):
28+
assert etree.iselement(Datatype.getLocalRoot()) and Datatype.getLocalRoot().tag == "Datatype"
29+
if not self.checkIfChild("Datatypes"):
30+
self.Datatypes = etree.SubElement(self.root, "Datatypes")
31+
self.Datatypes.append(Datatype.getLocalRoot())
32+
33+
def addModule(self, Module):
34+
assert etree.iselement(Module.getLocalRoot()) and Module.getLocalRoot().tag == "Module"
35+
if not self.checkIfChild("Modules"):
36+
self.Modules = etree.SubElement(self.root, "Modules")
37+
self.Modules.append(Module.getLocalRoot())
38+
39+
40+
def addAddOnInstructionDefinition(self, AddOnInstructionDefinition):
41+
assert etree.iselement(AddOnInstructionDefinition.getLocalRoot()) and AddOnInstructionDefinition.getLocalRoot().tag == "AddOnInstructionDefinition"
42+
if not self.checkIfChild("AddOnInstructionDefinitions"):
43+
self.AddOnInstructionDefinitions = etree.SubElement(self.root, "AddOnInstructionDefinitions")
44+
self.AddOnInstructionDefinitions.append(AddOnInstructionDefinition.getLocalRoot())
45+
46+
def addTag(self, Tag):
47+
assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag == "Tag"
48+
if not self.checkIfChild("Tags"):
49+
self.Tags = etree.SubElement(self.root, "Tags")
50+
self.Tags.append(Tag.getLocalRoot())
51+
52+
def addProgram(self, Program):
53+
assert etree.iselement(Program.getLocalRoot()) and Program.getLocalRoot().tag == "Program"
54+
if not self.checkIfChild("Programs"):
55+
self.Programs = etree.SubElement(self.root, "Programs")
56+
self.Programs.append(Program.getLocalRoot())
57+
58+
def addTask(self, Task):
59+
assert etree.iselement(Task.getLocalRoot()) and Task.getLocalRoot().tag == "Task"
60+
if not self.checkIfChild("Tasks"):
61+
self.Tasks = etree.SubElement(self.root, "Tasks")
62+
self.Tasks.append(Task.getLocalRoot())
63+
64+
def setParent(self, parent):
65+
assert etree.iselement(parent) and parent.tag == "Members"
66+
parent.append(self.getLocalRoot())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Datatype(Base_Template):
11+
'''
12+
UDT Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a datatype.
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self, TypeName, Description = ""):
19+
#Initialize Member Attributes
20+
assert isValidTag(TypeName)
21+
self.root = etree.Element("Datatype")
22+
self.root.set("Name", TypeName)
23+
self.root.set("Family", "NoFamily")
24+
self.root.set("Class", "User")
25+
if Description != "":
26+
self.Desc = etree.SubElement(self.root, 'Description')
27+
self.setDescription(Description)
28+
self.root.append(self.Desc)
29+
30+
self.Members = etree.SubElement(self.root, "Members")
31+
32+
def getMembersRoot(self):
33+
return self.Members
34+
35+
def addMember(self, member):
36+
self.Members.append(member.getLocalRoot())
37+
38+
def setParent(self, parent):
39+
assert etree.iselement(parent) and parent.tag == "DatatTypes"
40+
parent.append(self.root)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Member(Base_Template):
11+
'''
12+
Member Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a member.
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self, TagName, DataType, Hidden = False, Description = "", Radix = "Decimal", ArrayLength = 0, Target = "", BitNumber = 0):
19+
#Initialize Member Attributes
20+
assert isValidTag(TagName)
21+
if DataType == "BOOL": DataType = "BIT"
22+
self.root = etree.Element('Member')
23+
self.root.set("Name", TagName)
24+
self.root.set("Datatype", str(DataType))
25+
self.root.set("Dimension",str(ArrayLength))
26+
self.root.set("Radix", Radix)
27+
if DataType == "BIT":
28+
#Reference Rockwell Manuals for Bit Overlays for details on the following assertion.
29+
if Target == "": raise ValueError("Data of Type BOOL<BIT> Must have a Target: eg. target = 'ZZZZZZZZZZSample0'")
30+
self.root.set("Hidden", "false")
31+
self.root.set("Target", Target)
32+
self.root.set("BitNumber", str(BitNumber))
33+
elif Hidden == True:
34+
self.root.set("Hidden", "true")
35+
else:
36+
self.root.set("Hidden", "false")
37+
self.root.set("ExternalAccess", "Read/Write")
38+
if Description != "":
39+
self.Desc = etree.SubElement(self.root, 'Description')
40+
self.setDescription(Description)
41+
self.root.append(self.Desc)
42+
43+
def setParent(self, parent):
44+
assert etree.iselement(parent) and parent.tag == "Members"
45+
parent.append(self.getLocalRoot())
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Program(Base_Template):
11+
'''
12+
Program Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a program.
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self, Name, Type = "Normal", Description = ""):
19+
#Initialize Member Attributes
20+
assert isValidTag(Name)
21+
self.root = etree.Element("Program")
22+
self.root.set("Name", Name)
23+
self.root.set("Type", Type)
24+
if Description != "":
25+
self.Desc = etree.SubElement(self.root, 'Description')
26+
self.setDescription(Description)
27+
self.root.append(self.Desc)
28+
29+
def setMainRoutine(self, RoutineName):
30+
assert type(RoutineName) == str
31+
self.root.set("MainRoutineName", RoutineName)
32+
33+
def addRoutine(self, Routine):
34+
assert etree.iselement(Routine.getLocalRoot()) and Routine.getLocalRoot().tag == "Routine"
35+
if not self.checkIfChild("Routines"):
36+
self.Routines = etree.SubElement(self.root, "Routines")
37+
self.Routines.append(Routine.getLocalRoot())
38+
39+
def addTag(self, Tag):
40+
assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag == "Tag"
41+
if not self.checkIfChild("Tags"):
42+
self.Tags = etree.SubElement(self.root, "Tags")
43+
self.Tags.append(Tag.getLocalRoot())
44+
45+
def setParent(self, parent):
46+
assert etree.iselement(parent) and parent.tag == "Programs"
47+
parent.append(self.root)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Project(Base_Template):
11+
'''
12+
Project Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a project.
15+
----------------------------------------------------------
16+
This class should always serve as the base class.
17+
----------------------------------------------------------
18+
For Information on this see the provided L5X Manual from Rockwell
19+
'''
20+
def __init__(self, SchemaRevision = "1.0", SoftwareRevision = "30.00"):
21+
#Initialize Member Attributes
22+
self.root = etree.Element("RSLogix5000Content")
23+
self.root.set("SchemaRevision", SchemaRevision)
24+
self.root.set("SoftwareRevision", SoftwareRevision)
25+
26+
def getControllerRoot(self):
27+
return self.Controller
28+
29+
def setController(self, Controller):
30+
assert etree.iselement(Controller.getLocalRoot()) and Controller.getLocalRoot().tag == "Controller"
31+
self.root.append(Controller.getLocalRoot())
32+
33+
def setAttribute(self, kwargs):
34+
for key in kwargs:
35+
self.root.set(key, kwargs[key])
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
try:
2+
import lxml
3+
from lxml import etree
4+
except ImportError as e:
5+
print e.message
6+
7+
from AB.Rockwell.XML.Tools import *
8+
from Base_Template import Base_Template
9+
10+
class Routine(Base_Template):
11+
'''
12+
Routine Template:
13+
See L5X Manual for Details,
14+
These members are to be used when defining a ladder routine.
15+
----------------------------------------------------------
16+
For Information on this see the provided L5X Manual from Rockwell
17+
'''
18+
def __init__(self, Name, Description = ""):
19+
#Initialize Member Attributes
20+
assert isValidTag(Name)
21+
self.root = etree.Element("Routine")
22+
self.root.set("Name", Name)
23+
self.root.set("Type", "RLL")
24+
if Description != "":
25+
self.Desc = etree.SubElement(self.root, 'Description')
26+
self.setDescription(Description)
27+
self.root.append(self.Desc)
28+
29+
def addRung(self, Rung):
30+
assert etree.iselement(Rung.getLocalRoot()) and Rung.getLocalRoot().tag == "Rung"
31+
if not self.checkIfChild("RLLContent"):
32+
self.RLLContent = etree.SubElement(self.root, "RLLContent")
33+
self.RLLContent.append(Rung.getLocalRoot())
34+
35+
def setParent(self, parent):
36+
assert etree.iselement(parent) and parent.tag == "Routines"
37+
parent.append(self.root)

0 commit comments

Comments
 (0)