This class allows creation and modification of l5x Routine (Structured Text).

XML data is stored in variablename.l5xdata (XMLDocument format).


Example 1:

Creating an empty l5x Routine with default parameters:

const myRoutineST = new kSDKv1.l5xRoutineST();

New Routine is a complete (though empty) l5x RoutineST that can be modified with methods (see below) or it can be immediately transformed into an l5x file (see "saveToFile()" method below) and imported into Studio5000 software.


Example 2:

Creating a Routine from custom XML (this will overwrite all default parameters):

const myNewCustomRtn = new kSDKv1.l5xRoutineST(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?
          <RSLogix5000Content SomeParam="1.0" SomeOtherParam = "2.0">
          <Controller Use="Context" Name="Kiptr" SomeParam="1.0" SomeOtherParam ="2.0">
          <Programs>
          <Program>
               <Routines>
               <Routine Use="Target" Name="Kiptr_LAD" Type="RLL"
          <CustomXML/>
               </Routine>
               </Routines>
          </Program>
          </Programs>
          </Controller>
          </RSLogix5000Content>
`);

It is important to inject XML with the Routine attribute "Use" = "Target". An error is generated if this condition is not satisfied.


METHODSClick on Methods for further information
Category
getsetadddeleteSpecial
NamegetName()setName()



Program

getProgramName() 
setProgramName() 

LinegetLines()

addLine()
deleteLine()

TaggetTag()
getTags()
getTagNames()

addTag()deleteTag()
UDT
getUDT()
getUDTNames()

addUDT()
deleteUDT()
AOIgetAOI()
getAOINames() 

addAOI()deleteAOI()
Order



orderify()
Files



toText()
saveToFile()

Name


getName()

ParametersReturns
Returns a routine name.
NARoutine name - (string)


Example

var newRoutine = new kSDKv1.l5xRoutineST();
newRoutine.setName("NewRoutine");
console.log(newRoutine.getName()); // -> "NewRoutine"



setName(newName)

ParametersReturns

Sets new routine name.

newName – (string) New routine name.
NA


Example

var newRoutine = new kSDKv1.l5xRoutineST();
newRoutine.setName("NewRoutine");
console.log(newRoutine.getName()); // -> "NewRoutine"

Program


getProgramName()

ParametersReturns

Returns a program name.

NA

Program name - (string)


Example

var newRoutine = new kSDKv1.l5xRoutineST();
newRoutine.setProgramName("MainProgram");
console.log(newRoutine.getProgramName()); // -> "MainProgram"


setProgramName(newName)

ParametersReturns

Sets new program name.

newName – (string) New program name.

NA


Example

var newRoutine = new kSDKv1.l5xRoutineST();
newRoutine.setProgramName("MainProgram");
console.log(newRoutine.getProgramName()); // -> "MainProgram"

Line


getLines()

ParametersReturns

Returns an array with all the lines of the existing routine.

NA

Lines ([string])


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getLines().length); // -> 0
newLine = "JSR(Events_general);";
newRtn.addLine(newLine);
console.log(newRtn.getLines().length); // -> 1
console.log(newRtn.getLines()[0]); // -> JSR(Events_general);
newLine = "TONR(TONR_00);";
newRtn.addLine(newLine, 0); //Adding new Line to position 0
console.log(newRtn.getLines()[0]); // -> TONR(TONR_00);


addLine(logic, position)

ParametersReturns

Adds a new line to a desired position.

logic - (string) Logic text to add to routine.

position - optional (number) Position to place the logic to. If “position” is not passed logic will be added to the last position in the routine.

NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getLines().length); // -> 0
newLine = "JSR(Events_general);";
newRtn.addLine(newLine);
console.log(newRtn.getLines().length); // -> 1 console.log(newRtn.getLines()[0]); // -> JSR(Events_general);
newLine = "TONR(TONR_00);";
newRtn.addLine(newLine, 0); //Adding new Line to position 0



deleteLine(LineNumber)

ParametersReturns

Deletes a line from a position in routine.

lineNumber - (number) Position of the line to be deleted.

NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getLines().length); // -> 0
newLine = "JSR(Events_general);";
newRtn.addLine(newLine);
console.log(newRtn.getLines().length); // -> 1
console.log(newRtn.getLines()[0]); // -> JSR(Events_general);
newLine = "TONR(TONR_00);";
newRtn.addLine(newLine, 0); //Adding new Line to position 0
console.log(newRtn.getLines()[0]); // -> TONR(TONR_00);



Tag


getTag(tagName, programName)

ParametersReturns

Returns an existing tag from the routine.

tagName –  (string) Name of tag to be returned.

programName - (string) optional. Name of program to get tag from. Controller scoped tag will be returned if the parameter is missing.

Tag (l5xTag)


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newTag = new kSDKv1.l5xTag();
newTag.setName("MyNewTag");
newRtn.addTag(newTag);
newRtn.addTag(newTag, "MainProgram");
// Controller scope:
var existingTag = newRtn.getTag("MyNewTag");
console.log(existingTag.getName()) // -> MyNewTag
// Program scope:
console.log(newRtn.getTag("MyNewTag",
"MainProgram").getName()) // -> MyNewTag



getTags(programName)

ParametersReturns

Returns all the tags found in the existing routine.

programName – (string) optional. Name of program to get tags from. Controller scoped tags will be returned if the parameter is missing.Tags ([l5xTag])


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getTags().length) // -> 0
var newTag = new kSDKv1.l5xTag();
newRtn.addTag(newTag);
console.log(newRtn.getTags().length) // -> 1



getTagNames(programName)

ParametersReturns

Returns names of all the tags found in the existing routine.

programName – (string) optional. Name of program to get tag names from. Controller scoped tag names will be returned if the parameter is missing.Tag names ([string])


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getTagNames().length) // -> 0
var newTag = new kSDKv1.l5xTag();
newTag.setName("MyNewTag");
newRtn.addTag(newTag);
console.log(newRtn.getTagNames()[0]) // -> MyNewTag



addTag(newTag, programName)

ParametersReturns

Adds a new tag to an existing routine.


Note: If the tag type has to belong to AOI or UDT and you want to update some of its parameters - use fixAOITag(AOI) and fixUDTTag(UDT) methods of l5xTag class. This will create the parameters in a new tag that match AOI and UDT structure.

newTag – (l5xTag) Tag being added.

programName - (string) optional. Name of program to add tag to. Controller scoped tag will be created if the parameter is missing.

NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
// Controller scope:
console.log(newRtn.getTags().length) // -> 0
var newTag = new kSDKv1.l5xTag();
newRtn.addTag(newTag);
console.log(newRtn.getTags().length) // -> 1
// Program scope:
console.log(newRtn.getTags("MainProgram").length) // -> 0
newRtn.addTag(newTag, "MainProgram");
console.log(newRtn.getTags("MainProgram").length) // -> 1



deleteTag(tagName, programName)

ParametersReturns

Deletes a tag from the routine.

tagName – (string) Name of tag to be deleted.

programName - (string) optional. Name of program to delete tag from. Controller scoped tag will be deleted if the parameter is missing.

NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newTag = new kSDKv1.l5xTag();
newTag.setName("MyNewTag");
newRtn.addTag(newTag); newRtn.addTag(newTag, "MainProgram");
// Controller scope:
console.log(newRtn.getTags().length) // -> 1
newRtn.deleteTag("MyNewTag");
console.log(newRtn.getTags().length) // -> 0
// Program scope:
console.log(newRtn.getTags("MainProgram").length) // -> 1
newRtn.deleteTag("MyNewTag", "MainProgram");
console.log(newRtn.getTags("MainProgram").length) // -> 0

UDT


getUDT(UDTName)

ParametersReturns

Returns the UDT (User-defined Data Type) with name UDTName from the existing routine. All the dependencies (AOIs and UDTs) will be automatically taken out of the routine and saved with the UDT. This method works similar to "Export UDT" in Studio 5000.

UDTName - (string) Name of UDT to be returned.UDT (l5xUDT)


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newUDT = new kSDKv1.l5xUDT();
newUDT.setName("MyNewUDT"); newRtn.addUDT(newUDT);
var exisitngUDT = newRtn.getUDT("MyNewUDT");
console.log(exisitngUDT.getName()) // -> MyNewUDT



getUDTNames()

ParametersReturns

Returns names of all the UDTs (User-defined Data Types) found in the existing routine.

NAUDT names ([string])


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getUDTNames().length) // -> 0
var newUDT = new kSDKv1.l5xUDT();
newUDT.setName("MyNewUDT");
newRtn.addUDT(newUDT);
console.log(newRtn.getUDTNames()[0]) // -> MyNewUDT



addUDT(UDT)

ParametersReturns

Adds the UDT (User-defined Data Type) to the existing routine. This also adds all the dependencies - AOIs and UDTs from the UDT to the existing routine. This method works similar to "Import UDT" in Studio 5000.

UDT - (l5xUDT) UDT to be added.NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newUDT = new kSDKv1.l5xUDT();
newUDT.setName("MyNewUDT");
newRtn.addUDT(newUDT);
var exisitngUDT = newRtn.getUDT("MyNewUDT");
console.log(exisitngUDT.getName()) // -> MyNewUDT



deleteUDT()

ParametersReturns

Deletes the UDT (User-defined Data Type) with name UDTName from the existing routine.

UDTName - (string) Name of UDT to be deleted.UDT (l5xUDT)


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newUDT = new kSDKv1.l5xUDT();
newUDT.setName("MyNewUDT");
newRtn.addUDT(newUDT);
console.log(newRtn.getUDTNames().length) // -> 1
newRtn.deleteUDT("MyNewUDT");
console.log(newRtn.getUDTNames().length) // -> 0

AOI


getAOI(AOIName)

ParametersReturns

Returns the AOI (Add On Instruction) with name AOIName from the existing routine. All the dependencies (AOIs and UDTs) will be automatically taken out of the routine and saved with the AOI. This method works similar to "Export UDT" in Studio 5000. Supports encoded AOIs.

AOIName - (string) Name of AOI to be returned.AOI (l5xAOI)


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newAOI = new kSDKv1.l5xAOI();
newAOI.setName("MyNewAOI");
newRtn.addAOI(newAOI);
var exisitngAOI = newRtn.getAOI("MyNewAOI");
console.log(exisitngAOI.getName()) // -> MyNewAOI



getAOINames()

ParametersReturns

Returns names of all the AOIs (Add On Instructions) found in the existing routine. Supports encoded AOIs.

NAAOI names ([string])


Example

var newRtn = new kSDKv1.l5xRoutineST();
console.log(newRtn.getAOINames().length) // -> 0
var newAOI = new kSDKv1.l5xAOI();
newAOI.setName("MyNewAOI");
newRtn.addAOI(newAOI);
console.log(newRtn.getAOINames()[0]) // -> MyNewAOI



addAOI(AOI)

ParametersReturns

Adds the AOI (Add On Instruction) to the existing routine. This also adds all the dependencies - AOIs and UDTs from the AOI to the existing routine. This method works similar to "Import AOI" in Studio 5000. Supports encoded AOIs.

AOI - (l5xAOI) AOI to be added.NA


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newAOI = new kSDKv1.l5xAOI();
newAOI.setName("MyNewAOI");
newRtn.addAOI(newAOI);
var exisitngAOI = newRtn.getAOI("MyNewAOI");
console.log(exisitngAOI.getName()) // -> MyNewAOI



deleteAOI(AOIName)

ParametersReturns

Deletes the AOI (Add On Instruction) with name AOIName from the existing routine. Supports encoded AOIs.

AOIName - (string) Name of AOI to be deleted.AOI (l5xAOI)


Example

var newRtn = new kSDKv1.l5xRoutineST();
var newAOI = new kSDKv1.l5xAOI();
newAOI.setName("MyNewAOI");
newRtn.addAOI(newAOI);
console.log(newRtn.getAOINames().length) // -> 1
newRtn.deleteAOI("MyNewAOI");
console.log(newRtn.getAOINames().length) // -> 0