This class allows creation and modification of l5x Routine (Ladder Diagram).
XML data is stored in variablename.l5xdata (XMLDocument format).
Example 1:
Creating an empty l5x Routine with default parameters:
const myRoutineLD = new kSDKv1.l5xRoutineLD();
New Routine is a complete (though empty) l5x RoutineLD 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.l5xRoutineLD(`<?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.
METHODS | Click on Methods for further information | ||||
Category | get | set | add | delete | Special |
Name | getName() | setName() | |||
Program | getProgramName() | setProgramName() | |||
Rung | getRungs() | addRung() | deleteRungs() | ||
Description | getDescription() | setDescription() | |||
Tag | getTag() getTags() getTagNames() | addTag() | deleteTag() | ||
UDT | getUDT() getUDTNames() | addUDT() | deleteUDT() | ||
AOI | getAOI() getAOINames() | addAOI() | deleteAOI() | ||
Order | orderify() | ||||
Files | toText() saveToFile() |
Name |
getName() | Parameters | Returns |
Returns a routine name. | NA | Routine name - (string) |
Example
var newRoutine = new kSDKv1.l5xRoutineLD(); newRoutine.setName("NewRoutine"); console.log(newRoutine.getName()); // -> "NewRoutine"
setName(newName) | Parameters | Returns |
Sets new routine name. | newName – (string) New routine name. | NA |
Example
var newRoutine = new kSDKv1.l5xRoutineLD(); newRoutine.setName("NewRoutine"); console.log(newRoutine.getName()); // -> "NewRoutine"
Program |
getProgramName() | Parameters | Returns |
Returns a program name. | NA | Program name - (string) |
Example
var newRoutine = new kSDKv1.l5xRoutineLD(); newRoutine.setProgramName("MainProgram"); console.log(newRoutine.getProgramName()); // -> "MainProgram"
setProgramName(newName) | Parameters | Returns |
Sets new program name. | newName – (string) New program name. | NA |
Example
var newRoutine = new kSDKv1.l5xRoutineLD(); newRoutine.setProgramName("MainProgram"); console.log(newRoutine.getProgramName()); // -> "MainProgram"
Rung |
getRungs() | Parameters | Returns |
Returns an array with all the rungs of existing routine. | NA | Rungs ([l5xRung]) |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); console.log(newRtn.getRungs().length); // -> 0 newRung = new kSDKv1.l5xRung(); newRung.setLogic("XIC(tag1)OTE(tag2);"); newRtn.addRung(newRung); console.log(newRtn.getRungs().length); // -> 1 console.log(newRtn.getRungs()[0].getLogic()); // -> XIC(tag1)OTE(tag2); newRung.setLogic("XIC(tag3)OTE(tag4);"); newRtn.addRung(newRung, 0); //Adding new rung to position 0 console.log(newRtn.getRungs()[0].getLogic()); // -> XIC(tag3)OTE(tag4);
addRung(logic, position) | Parameters | Returns |
Adds a new rung to a desired position. | logic - (string or l5xRung) Rung instance or logic to add to routine. If an l5xRung instance is passed and “position” is not passed - position will be taken from the instance. If “position” is passed - it will override the value from the instance of l5xRung. 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 (unless l5xRung instance is passed to “logic”. In this case position will be taken from the instance). | NA |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); console.log(newRtn.getRungs().length); // -> 0 newRung = new kSDKv1.l5xRung(); newRung.setLogic("XIC(tag1)OTE(tag2);"); newRtn.addRung(newRung); console.log(newRtn.getRungs().length); // -> 1 console.log(newRtn.getRungs()[0].getLogic()); // -> XIC(tag1)OTE(tag2); newRung.setLogic("XIC(tag3)OTE(tag4);"); newRtn.addRung(newRung, 0); //Adding new rung to position 0 console.log(newRtn.getRungs()[0].getLogic()); // -> XIC(tag3)OTE(tag4);
deleteRung(rungNumber) | Parameters | Returns |
Deletes a rung from a position in routine. | rungNumber - (number) Position of the rung to be deleted. | NA |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); console.log(newRtn.getRungs().length); // -> 0 newRung = new kSDKv1.l5xRung(); newRung.setLogic("XIC(tag1)OTE(tag2);"); newRtn.addRung(newRung); console.log(newRtn.getRungs().length); // -> 1 newRung.setLogic("XIC(tag3)OTE(tag4);"); newRtn.addRung(newRung, 0); //Adding new rung to position 0 console.log(newRtn.getRungs().length); // -> 2 newRtn.deleteRung(0); console.log(newRtn.getRungs().length); // -> 1
Description |
getDescription() | Parameters | Returns |
Returns a routine description. | NA | Routine description - (string) |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); newRtn.setDescription("New Routine Description"); console.log(newRtn.getDescription()); // -> "New Routine Description"
setDescription(newDescription) | Parameters | Returns |
Sets new routine description. | newDescription - (string) New routine description. | NA |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); newRtn.setDescription("New Routine Description"); console.log(newRtn.getDescription()); // -> "New Routine Description"
Tag |
getTag(tagName, programName) | Parameters | Returns |
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.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); console.log(newRtn.getTags().length) // -> 0 var newTag = new kSDKv1.l5xTag(); newRtn.addTag(newTag); console.log(newRtn.getTags().length) // -> 1
getTagNames(programName) | Parameters | Returns |
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.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); // 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) | Parameters | Returns |
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.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newRtn.addUDT(newUDT); var exisitngUDT = newRtn.getUDT("MyNewUDT"); console.log(exisitngUDT.getName()) // -> MyNewUDT
getUDTNames() | Parameters | Returns |
Returns names of all the UDTs (User-defined Data Types) found in the existing routine. | NA | UDT names ([string]) |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newRtn.addUDT(newUDT); var exisitngUDT = newRtn.getUDT("MyNewUDT"); console.log(exisitngUDT.getName()) // -> MyNewUDT
deleteUDT() | Parameters | Returns |
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.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newRtn.addAOI(newAOI); var exisitngAOI = newRtn.getAOI("MyNewAOI"); console.log(exisitngAOI.getName()) // -> MyNewAOI
getAOINames() | Parameters | Returns |
Returns names of all the AOIs (Add On Instructions) found in the existing routine. Supports encoded AOIs. | NA | AOI names ([string]) |
Example
var newRtn = new kSDKv1.l5xRoutineLD(); 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) | Parameters | Returns |
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.l5xRoutineLD(); var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newRtn.addAOI(newAOI); var exisitngAOI = newRtn.getAOI("MyNewAOI"); console.log(exisitngAOI.getName()) // -> MyNewAOI
deleteAOI(AOIName) | Parameters | Returns |
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.l5xRoutineLD(); 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