This class allows the creation and modification of l5x Program.
XML data is stored in variablename.l5xdata (XMLDocument format).
Example 1:
Creating an empty l5x Program with default parameters:
const myNewProgram = new kSDKv1.l5xProgram();
New program is a complete (though empty) l5x program that can be modified with methods (see below). It also can be immediately transformed into an l5x file (see "saveToFile()" method below) and imported into Studio5000 software.
Example 2:
Creating a program from custom XML (this will overwrite all default parameters):
const myNewCustomPrg = new kSDKv1.l5xProgram(`
<?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 Use="Context"> <Program Use="Target" Name="Kiptr" TestEdits="false" MainRoutineName="Schedule" Disabled="false" UseAsFolder="false">
<CustomXML/>
</Program>
</Programs>
</Controller>
</RSLogix5000Content>
`);
It is important to inject XML with the attribute “Use”="Target" of node “Program”. 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() | |||
Routine | getRoutine() getMainRtnName() getRoutineNames() | setMainRtnName() | addRoutine() | deleteRoutine() | |
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 program name. | NA | Program name - (string) |
Example
var newProgram = new kSDKv1.l5xProgram(); newProgram.setName("NewProgram"); console.log(newProgram.getName()); // -> "NewProgram"
setName(newName) | Parameters | Returns |
Sets new program name. | newName – (string) New program name. | NA |
Example
var newProgram = new kSDKv1.l5xProgram(); newProgram.setName("NewProgram"); console.log(newProgram.getName()); // -> "NewProgram"
Routine |
getRoutine(routineName) | Parameters | Returns |
Returns the routine with name routineName from the existing program. | routineName - (string) Name of routine to be returned. | Routine (l5xRoutine) |
Example
var newPrg = new kSDKv1.l5xProgram(); var existingRoutineName = newPrg.getRoutineNames()[0]; var existingRoutine = newPrg.getRoutine(existingRoutineName); console.log(existingRoutine.getName()) // -> Schedule
getMainRtnName(newName) | Parameters | Returns |
Sets the name of the main routine. | newName - (string) New main routine name. | NA |
Example
var newProgram = new kSDKv1.l5xProgram(); newProgram.setMainRtnName("NewRoutine"); console.log(newProgram.getMainRtnName()); // -> "NewRoutine"
getRoutineNames() | Parameters | Returns |
Returns names of routines from the existing program. | NA | Routine names ([string]) |
Example
var newPrg = new kSDKv1.l5xProgram(); console.log(newPrg.getRoutineNames().length) // -> 1 console.log(newPrg.getRoutineNames()[0]) // -> Schedule
setMainRtnName(newName) | Parameters | Returns |
Sets the name of the main routine. | newName - (string) New main routine name. | NA |
Example
var newProgram = new kSDKv1.l5xProgram(); newProgram.setMainRtnName("NewRoutine"); console.log(newProgram.getMainRtnName()); // -> "NewRoutine"
addRoutine(routine) | Parameters | Returns |
Adds routine to the existing project. | routine - (l5xRoutine) Routine to be added. | NA |
Example
var newPrg = new kSDKv1.l5xProgram(); console.log(newPrg.getRoutineNames().length) // -> 1 var newRoutine = new kSDKv1.l5xRoutineLD(); newPrg.addRoutine(newRoutine); console.log(newPrg.getRoutineNames().length) // -> 2
deleteRoutine(routineName) | Parameters | Returns |
Deletes the Routine with name routineName from the existing project. | routineName - (string) Name of Routine to be deleted. | NA |
Example
var newPrg = new kSDKv1.l5xProgram(); var RtnNames = newPrg.getRoutineNames(); console.log(RtnNames.length) // -> 1 newPrg.deleteRoutine(RtnNames[0]); console.log(newPrg.getRoutineNames().length) // -> 0
Tag |
getTag(tagName, programName) | Parameters | Returns |
Returns an existing tag from the program | 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 newPrj = new kSDKv1.l5xProgram(); var newTag = new kSDKv1.l5xTag(); newTag.setName("MyNewTag"); newPrj.addTag(newTag); newPrj.addTag(newTag, "MainProgram"); // Controller scope: var existingTag = newPrj.getTag("MyNewTag"); console.log(existingTag.getName()) // -> MyNewTag // Program scope: console.log(newPrj.getTag("MyNewTag", "MainProgram").getName()) // -> MyNewTag
getTags(programName) | Parameters | Returns |
Returns all the tags found in the existing program. | 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 newPrj = new kSDKv1.l5xProgram(); console.log(newPrj.getTags().length) // -> 0 var newTag = new kSDKv1.l5xTag(); newPrj.addTag(newTag); console.log(newPrj.getTags().length) // -> 1
getTagNames(programName) | Parameters | Returns |
Returns names of all the tags found in the existing program. | 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 newPrj = new kSDKv1.l5xProgram(); console.log(newPrj.getTagNames().length) // -> 0 var newTag = new kSDKv1.l5xTag(); newTag.setName("MyNewTag"); newPrj.addTag(newTag); console.log(newPrj.getTagNames()[0]) // -> MyNewTag
addTag(newTag, programName) | Parameters | Returns |
Adds a new tag to an existing program. 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 newPrj = new kSDKv1.l5xProgram(); // Controller scope: console.log(newPrj.getTags().length) // -> 0 var newTag = new kSDKv1.l5xTag(); newPrj.addTag(newTag); console.log(newPrj.getTags().length) // -> 1 // Program scope: console.log(newPrj.getTags("MainProgram").length) // -> 0 newPrj.addTag(newTag, "MainProgram"); console.log(newPrj.getTags("MainProgram").length) // -> 1
deleteTag(tagName, programName) | Parameters | Returns |
Deletes a tag from the program. | 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 newPrj = new kSDKv1.l5xProgram(); var newTag = new kSDKv1.l5xTag(); newTag.setName("MyNewTag"); newPrj.addTag(newTag); newPrj.addTag(newTag, "MainProgram"); // Controller scope: console.log(newPrj.getTags().length) // -> 1 newPrj.deleteTag("MyNewTag"); console.log(newPrj.getTags().length) // -> 0 // Program scope: console.log(newPrj.getTags("MainProgram").length) // -> 1 newPrj.deleteTag("MyNewTag", "MainProgram"); console.log(newPrj.getTags("MainProgram").length) // -> 0
UDT |
getUDT(UDTName) | Parameters | Returns |
Returns the UDT (User-defined Data Type) with name UDTName from the existing program. All the dependencies (AOIs and UDTs) will be automatically taken out of the project 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 newPrj = new kSDKv1.l5xProgram(); var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newPrj.addUDT(newUDT); var exisitngUDT = newPrj.getUDT("MyNewUDT"); console.log(exisitngUDT.getName()) // -> MyNewUDT
getUDTNames() | Parameters | Returns |
Returns names of all the UDTs (User-defined Data Types) found in the existing program. | NA | UDT names ([string]) |
Example
var newPrj = new kSDKv1.l5xProgram(); console.log(newPrj.getUDTNames().length) // -> 0 var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newPrj.addUDT(newUDT); console.log(newPrj.getUDTNames()[0]) // -> MyNewUDT
addUDT(UDT) | Parameters | Returns |
Adds the UDT (User-defined Data Type) to the existing program. This also adds all the dependencies - AOIs and UDTs from the UDT to the existing project. This method works similar to "Import UDT" in Studio 5000. | UDT - (l5xUDT) UDT to be added. | NA |
Example
var newPrj = new kSDKv1.l5xProgram(); var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newPrj.addUDT(newUDT); var exisitngUDT = newPrj.getUDT("MyNewUDT"); console.log(exisitngUDT.getName()) // -> MyNewUDT
deleteUDT() | Parameters | Returns |
Deletes the UDT (User-defined Data Type) with name UDTName from the existing program. | UDTName - (string) Name of UDT to be deleted. | UDT (l5xUDT) |
Example
var newPrj = new kSDKv1.l5xProgram(); var newUDT = new kSDKv1.l5xUDT(); newUDT.setName("MyNewUDT"); newPrj.addUDT(newUDT); console.log(newPrj.getUDTNames().length) // -> 1 newPrj.deleteUDT("MyNewUDT"); console.log(newPrj.getUDTNames().length) // -> 0
AOI |
getAOI(AOIName) | Parameters | Returns |
Returns the AOI (Add On Instruction) with name AOIName from the existing program. All the dependencies (AOIs and UDTs) will be automatically taken out of the project 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 newPrj = new kSDKv1.l5xProgram(); var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newPrj.addAOI(newAOI); var exisitngAOI = newPrj.getAOI("MyNewAOI"); console.log(exisitngAOI.getName()) // -> MyNewAOI
getAOINames() | Parameters | Returns |
Returns names of all the AOIs (Add On Instructions) found in the existing program. Supports encoded AOIs. | NA | AOI names ([string]) |
Example
var newPrj = new kSDKv1.l5xProgram(); console.log(newPrj.getAOINames().length) // -> 0 var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newPrj.addAOI(newAOI); console.log(newPrj.getAOINames()[0]) // -> MyNewAOI
addAOI(AOI) | Parameters | Returns |
Adds the AOI (Add On Instruction) to the existing program. This also adds all the dependencies - AOIs and UDTs from the AOI to the existing project. This method works similar to "Import AOI" in Studio 5000. Supports encoded AOIs. | AOI - (l5xAOI) AOI to be added. | NA |
Example
var newPrj = new kSDKv1.l5xProgram(); var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newPrj.addAOI(newAOI); var exisitngAOI = newPrj.getAOI("MyNewAOI"); console.log(exisitngAOI.getName()) // -> MyNewAOI
deleteAOI(AOIName) | Parameters | Returns |
Deletes the AOI (Add On Instruction) with name AOIName from the existing program. Supports encoded AOIs. | AOIName - (string) Name of AOI to be deleted. | AOI (l5xAOI) |
Example
var newPrj = new kSDKv1.l5xProgram(); var newAOI = new kSDKv1.l5xAOI(); newAOI.setName("MyNewAOI"); newPrj.addAOI(newAOI); console.log(newPrj.getAOINames().length) // -> 1 newPrj.deleteAOI("MyNewAOI"); console.log(newPrj.getAOINames().length) // -> 0
Order |
orderify() | Parameters | Returns |
Puts XML nodes in correct order. Studio5000 software generates an error if main XML nodes are not in the right order. You will not have to use this function if you use methods from Kiptr library. But you will have to make sure that the following order of nodes is kept if you modify XML directly: RedundancyInfo -> Security -> SafetyInfo -> DataTypes -> Modules -> AddOnInstructionDefinitions -> Tags -> Programs -> Tasks -> CommPorts -> CST -> WallClockTime -> Trends -> DataLogs -> TimeSynchronize orderify method is sorting all the nodes in the XMLDocument in the correct order | NA | NA |
Example
var newPrj = new kSDKv1.l5xProgram(); newPrj.orderify();
Files |
toText() | Parameters | Returns |
Returns contents of XMLDocument stored in variable.l5xdata as a text. | NA | XML in a text format. |
Example
var newPrj = new kSDKv1.l5xProgram(); console.log(newPrj.toText());
saveToFile(fileName) | Parameters | Returns |
Saves the project to a L5X file with the name fileName. | fileName - (string) optional. File name will be assigned to “kiptr_gen.l5x”. File name should include extension. | NA |
var newPrj = new kSDKv1.l5xProgram(); newPrj.saveToFile("myNewProject.l5x");