Skip to content

Commit

Permalink
another commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Canaan Seaton committed Jan 25, 2018
1 parent e3fbdd6 commit 2147fd4
Show file tree
Hide file tree
Showing 21 changed files with 533 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# Visual Studio Code Settings Folder
.vscode

# Ignore build and distribution directories
/build/
/dist/

#pypirc
*.pypirc

16 changes: 16 additions & 0 deletions src/build/lib/AB/Rockwell/Types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from enum import Enum

class CommonType:
BOOL = "BOOL"
SINT = "SINT"
INT = "INT"
DINT = "DINT"
REAL = "REAL"
STRING = "STRING"
COUNTER = "COUNTER"
TIMER = "TIMER"

class UserDefinedTypes:
ALARM = "ST_Alarms"
ONE_BUTTON = "PB_OneButton"
TWO_BUTTON = "PB_TwoButton"
54 changes: 54 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Base_Template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

import os
from AB.Rockwell.XML.Tools import *

class Base_Template():
'''
Base Template Template:
See L5X Manual for Details,
USED FOR INHERITANCE ONLY
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self):
#Initialize Member Attributes
self.root = None

def checkIfChild(self, nodeTag):
assert type(nodeTag) == str
for node in self.root:
if node.tag == nodeTag: return True
return False

def setAttribute(self, kwargs):
for key in kwargs:
if not key in self.root.keys():
raise KeyError("%s has No Attribute: <%s>" % (self.root.tag, key))

for key in kwargs:
self.root.set(key, kwargs[key])

def setDescription(self, Description):
assert type(Description) == str
if self.Desc == None:
self.Desc = etree.SubElement(self.root, 'Description')
self.root.append(self.Desc)
self.Desc.text = etree.CDATA(Description)

def setParent(self, parent):
pass

def getLocalRoot(self):
return self.root

def __str__(self):
return etree.tostring(self.root, pretty_print = True, xml_declaration = True, encoding = "UTF-8", standalone = "yes")

def writeToFile(self, fileName = os.getcwd() + "/L5X_Printable.L5X"):
tree = etree.ElementTree(self.root)
tree.write(fileName, pretty_print = True, xml_declaration = True, encoding = "UTF-8", standalone = "yes")
66 changes: 66 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Controller(Base_Template):
'''
Controller Template:
See L5X Manual for Details,
These members are to be used when defining a Controller.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Name, Use = "Context", Description = ""):
#Initialize Member Attributes
assert isValidTag(Name)
self.root = etree.Element('Controller')
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def addDatatype(self, Datatype):
assert etree.iselement(Datatype.getLocalRoot()) and Datatype.getLocalRoot().tag == "Datatype"
if not self.checkIfChild("Datatypes"):
self.Datatypes = etree.SubElement(self.root, "Datatypes")
self.Datatypes.append(Datatype.getLocalRoot())

def addModule(self, Module):
assert etree.iselement(Module.getLocalRoot()) and Module.getLocalRoot().tag == "Module"
if not self.checkIfChild("Modules"):
self.Modules = etree.SubElement(self.root, "Modules")
self.Modules.append(Module.getLocalRoot())


def addAddOnInstructionDefinition(self, AddOnInstructionDefinition):
assert etree.iselement(AddOnInstructionDefinition.getLocalRoot()) and AddOnInstructionDefinition.getLocalRoot().tag == "AddOnInstructionDefinition"
if not self.checkIfChild("AddOnInstructionDefinitions"):
self.AddOnInstructionDefinitions = etree.SubElement(self.root, "AddOnInstructionDefinitions")
self.AddOnInstructionDefinitions.append(AddOnInstructionDefinition.getLocalRoot())

def addTag(self, Tag):
assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag == "Tag"
if not self.checkIfChild("Tags"):
self.Tags = etree.SubElement(self.root, "Tags")
self.Tags.append(Tag.getLocalRoot())

def addProgram(self, Program):
assert etree.iselement(Program.getLocalRoot()) and Program.getLocalRoot().tag == "Program"
if not self.checkIfChild("Programs"):
self.Programs = etree.SubElement(self.root, "Programs")
self.Programs.append(Program.getLocalRoot())

def addTask(self, Task):
assert etree.iselement(Task.getLocalRoot()) and Task.getLocalRoot().tag == "Task"
if not self.checkIfChild("Tasks"):
self.Tasks = etree.SubElement(self.root, "Tasks")
self.Tasks.append(Task.getLocalRoot())

def setParent(self, parent):
assert etree.iselement(parent) and parent.tag == "Members"
parent.append(self.getLocalRoot())
40 changes: 40 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Datatype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Datatype(Base_Template):
'''
UDT Template:
See L5X Manual for Details,
These members are to be used when defining a datatype.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, TypeName, Description = ""):
#Initialize Member Attributes
assert isValidTag(TypeName)
self.root = etree.Element("Datatype")
self.root.set("Name", TypeName)
self.root.set("Family", "NoFamily")
self.root.set("Class", "User")
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

self.Members = etree.SubElement(self.root, "Members")

def getMembersRoot(self):
return self.Members

def addMember(self, member):
self.Members.append(member.getLocalRoot())

def setParent(self, parent):
assert etree.iselement(parent) and parent.tag == "DatatTypes"
parent.append(self.root)
45 changes: 45 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Member.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Member(Base_Template):
'''
Member Template:
See L5X Manual for Details,
These members are to be used when defining a member.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, TagName, DataType, Hidden = False, Description = "", Radix = "Decimal", ArrayLength = 0, Target = "", BitNumber = 0):
#Initialize Member Attributes
assert isValidTag(TagName)
if DataType == "BOOL": DataType = "BIT"
self.root = etree.Element('Member')
self.root.set("Name", TagName)
self.root.set("Datatype", str(DataType))
self.root.set("Dimension",str(ArrayLength))
self.root.set("Radix", Radix)
if DataType == "BIT":
#Reference Rockwell Manuals for Bit Overlays for details on the following assertion.
if Target == "": raise ValueError("Data of Type BOOL<BIT> Must have a Target: eg. target = 'ZZZZZZZZZZSample0'")
self.root.set("Hidden", "false")
self.root.set("Target", Target)
self.root.set("BitNumber", str(BitNumber))
elif Hidden == True:
self.root.set("Hidden", "true")
else:
self.root.set("Hidden", "false")
self.root.set("ExternalAccess", "Read/Write")
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def setParent(self, parent):
assert etree.iselement(parent) and parent.tag == "Members"
parent.append(self.getLocalRoot())
47 changes: 47 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Program(Base_Template):
'''
Program Template:
See L5X Manual for Details,
These members are to be used when defining a program.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Name, Type = "Normal", Description = ""):
#Initialize Member Attributes
assert isValidTag(Name)
self.root = etree.Element("Program")
self.root.set("Name", Name)
self.root.set("Type", Type)
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def setMainRoutine(self, RoutineName):
assert type(RoutineName) == str
self.root.set("MainRoutineName", RoutineName)

def addRoutine(self, Routine):
assert etree.iselement(Routine.getLocalRoot()) and Routine.getLocalRoot().tag == "Routine"
if not self.checkIfChild("Routines"):
self.Routines = etree.SubElement(self.root, "Routines")
self.Routines.append(Routine.getLocalRoot())

def addTag(self, Tag):
assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag == "Tag"
if not self.checkIfChild("Tags"):
self.Tags = etree.SubElement(self.root, "Tags")
self.Tags.append(Tag.getLocalRoot())

def setParent(self, parent):
assert etree.iselement(parent) and parent.tag == "Programs"
parent.append(self.root)
35 changes: 35 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Project(Base_Template):
'''
Project Template:
See L5X Manual for Details,
These members are to be used when defining a project.
----------------------------------------------------------
This class should always serve as the base class.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, SchemaRevision = "1.0", SoftwareRevision = "30.00"):
#Initialize Member Attributes
self.root = etree.Element("RSLogix5000Content")
self.root.set("SchemaRevision", SchemaRevision)
self.root.set("SoftwareRevision", SoftwareRevision)

def getControllerRoot(self):
return self.Controller

def setController(self, Controller):
assert etree.iselement(Controller.getLocalRoot()) and Controller.getLocalRoot().tag == "Controller"
self.root.append(Controller.getLocalRoot())

def setAttribute(self, kwargs):
for key in kwargs:
self.root.set(key, kwargs[key])
37 changes: 37 additions & 0 deletions src/build/lib/AB/Rockwell/XML/Templates/Routine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
try:
import lxml
from lxml import etree
except ImportError as e:
print e.message

from AB.Rockwell.XML.Tools import *
from Base_Template import Base_Template

class Routine(Base_Template):
'''
Routine Template:
See L5X Manual for Details,
These members are to be used when defining a ladder routine.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Name, Description = ""):
#Initialize Member Attributes
assert isValidTag(Name)
self.root = etree.Element("Routine")
self.root.set("Name", Name)
self.root.set("Type", "RLL")
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def addRung(self, Rung):
assert etree.iselement(Rung.getLocalRoot()) and Rung.getLocalRoot().tag == "Rung"
if not self.checkIfChild("RLLContent"):
self.RLLContent = etree.SubElement(self.root, "RLLContent")
self.RLLContent.append(Rung.getLocalRoot())

def setParent(self, parent):
assert etree.iselement(parent) and parent.tag == "Routines"
parent.append(self.root)
Loading

0 comments on commit 2147fd4

Please sign in to comment.