Beispiel #1
0
def create_project(*populate):
    """
    Generates a mock L5X project. The created document contains only an
    empty set of elements required by the L5X Project class; the populate
    callbacks are used to add whatever additional content needed by particular
    test cases.
    """
    imp = xml.dom.minidom.getDOMImplementation()
    doc = imp.createDocument(None, 'RSLogix5000Content', None)
    root = doc.documentElement

    controller = doc.createElement('Controller')
    root.appendChild(controller)

    # Create the top-level elements under the Controller.
    for tag in ['Tags', 'Programs', 'Modules']:
        element = doc.createElement(tag)
        controller.appendChild(element)

    # Dispatch the document to the populate callbacks to allow additional
    # content to be added before serialization.
    [f(doc) for f in populate]

    # Serialize the document so it can be parsed as a simulated XML file.
    xml_str = root.toxml('UTF-8').decode('UTF-8')
    buf = io.StringIO(xml_str)
    return l5x.Project(buf)
Beispiel #2
0
def string_to_project(s):
    """Parses an XML string into a L5X project."""
    # Convert to unicode as needed for Python 2.7.
    try:
        s = unicode(s)
    except NameError:
        pass

    buf = io.StringIO(s)
    return l5x.Project(buf)
Beispiel #3
0
    def common_setup(cls):
        prj = l5x.Project()
        prj.controller.target_name = 'CreateTestName'
        prj.controller.slot = '2'
        prj.controller.processor_type = '1756-L75'
        prj.controller.major_revision = '20'
        prj.controller.minor_revision = '11'
        prj.controller.description = 'Base test project to be used with l5x python package'
        prj.modules['Local'].ports[1].address = '4'
        program = prj.programs['MainProgram']
        RLLRoutine.create(program, 'TestLadderRoutine')
        FBDRoutine.create(program, 'TestFunctionBlockRoutine')
        SFCRoutine.create(program, 'TestSeqFunctionChartRoutine')
        STRoutine.create(program, 'TestStructuredTextRoutine')
        program.description = 'Test Program Description'

        routine = program.routines['TestLadderRoutine']
        Rung.create(routine, 'XIC(boolean1)OTE(boolean2);')
        Rung.create(routine, 'XIC(boolean1)OTE(boolean2);')
        Rung.create(routine, 'XIC(boolean1)OTE(boolean2);')

        routine = program.routines['MainRoutine']
        Rung.create(routine, 'JSR(TestFunctionBlockRoutine,0);')
        Rung.create(routine, 'JSR(TestSeqFunctionChartRoutine,0);')
        Rung.create(routine, 'JSR(TestLadderRoutine,0);')
        Rung.create(routine, 'JSR(TestStructuredTextRoutine,0);')

        routine = program.routines['TestFunctionBlockRoutine']
        routine.description = 'Test Function Block Routine'
        sheet = Sheet.create(routine)
        iref = FBD_IRef.create(sheet, 'boolean1', 160, 120)
        oref = FBD_ORef.create(sheet, 'boolean2', 500, 120)
        Wire.create(sheet, iref, oref)
        FBD_TextBox.create(sheet, 'Test Function Block Description On Sheet')

        #Create tags
        Tag.create(prj.controller, prj, 'Base', 'boolean1', 'BOOL', 1,
                   'Test Boolean 1')
        Tag.create(prj.controller, prj, 'Base', 'real1', 'REAL', 0.4,
                   'Test Real 1')
        Tag.create(prj.controller, prj, 'Base', 'dint1', 'DINT', 1,
                   'Test DINT 1')
        Tag.create(program, prj, 'Base', 'boolean2', 'BOOL', 1,
                   'Test Boolean 2')

        #Create alias tag
        Tag.create(prj.controller, prj, 'Alias', 'alias1', alias_for="dint1")
        return prj
Beispiel #4
0
 def setUp(self):
     self.prj = l5x.Project('./tests/basetest.L5X')
Beispiel #5
0
 def write_read_project(self):
     self.prj.write('./tests/__results__/basetest_output.L5X')
     return l5x.Project('./tests/__results__/basetest_output.L5X')