Skip to main content

RSLogix .L5X interface.

Project description

This package aims to implement an interface for manipulating content of RSLogix .L5X export files using a native Pythonic approach as opposed to dealing with raw XML.

Getting Started

All access to .L5X data is through a top-level Project object, instantiated by passing a filename to the constructor. If the project is to be modified the write method writes the updated data back to a file for importing into RSLogix. Typical execution flow is as follows:

import l5x
prj = l5x.Project('project.L5X')

# Read or modify data as needed.

prj.write('modified.L5X')

Controller

The controller attribute of a project has the following attributes:

tags:

A tag scope containing controller tags; see Tags.

comm_path:

Permits reading and modifying the controller’s communication path. Setting to None will delete the communication path.

>>> prj.controller.tags['tag_name'].description = 'A controller tag'
>>> prj.controller.comm_path
'AB_ETHIP-1\\192.168.1.10\\Backplane\\0'

Programs

A project’s programs attribute contains a names attribute that evaluates to a list of program names, members of which can be used as indices to access program-scoped tags.

>>> prj.programs.names
['MainProgram', 'AnotherProgram']
>>> prj.programs['MainProgram'].tags['a_program_tag'].value = 50

Tags

The top-level project contains tag scope objects, such as controller or programs, which provide access to their respective tags. Indexing a scope object with a tag’s name will return a tag object providing access to the various properties of the tag. A list of tag names can also be acquired from a scope’s names attribute.

ctl_tags = prj.controller.tags
tag_names = ctl_tags.names
some_tag = ctl_tags[tag_names[0]]

All tag objects have at least the following attributes:

data_type

A string describing the tag’s data type, such as DINT or TIMER.

value

The tag’s complete value, the type of which varies based on the tag’s type. For base data types this will be a single value, such as an integer, however, container objects are utilized for compound data types such as arrays and UDTs. See documentation below for details. This attribute can be read to acquire the current value or written to set a new value.

description

The tag’s top-level comment. See data type specific documentation for data types which support commenting subelements such as individual array members or integer bits. In addition to normal read/write activities, setting this attribute to None will delete any existing comment.

Integers

DINT, INT, and SINT data types accept integer values.

prj.controller.tags['dint_tag'].value = 42

Accessing individual bits is available via index notation with a zero-based integer index:

prj.controller.tags['dint_tag'][3].value = 1
prj.controller.tags['dint_tag'][2].description = 'this is bit 2'

Booleans

Like integers, BOOL data types accept integer values, albeit only 0 or 1.

Floats

REAL data types use floating point values. If an integer value is desired, it must first be converted to a float before assignment or a TypeError will be raised. Infinite and not-a-number values may not be used.

Structures

Structured data types include UDTs and built-ins such as TIMER. Individual members are accessed using the member’s name as an index as follows:

prj.controller.tags['timer']['PRE'].value = 100
prj.controller.tags['timer']['DN'].description = 'done bit'

Accessing the value of the structure as a whole is also possible using dictionaries keyed by member name.

d = {'PRE':0, 'ACC':0, 'EN':0, 'TT':0, 'DN':0}
prj.controller.tags['timer'].value = d

Arrays

Array elements are accessed with standard index notation using integer indices. Multidimensional arrays use a series of indices, each within their own bracket as opposed to the comma-separated style of RSLogix.

>>> prj.controller.tags['single_dim_array'][3].value = 16
>>> prj.controller.tags['multi_dim_array'][2][5].description
'This is multi_dim_array[2,5]'

The value of entire array is available through the value attribute using lists. Multidimensional arrays use lists of lists and arrays of complex data types are supported, for example an array of UDTs is a list of dicts.

>>> l = [0, 1, 2, 3, 4]
>>> prj.controller.tags['single_dim_array'].value = l
>>> prj.controller.tags['multi_dim_array'].value
[[0, 1], [2, 3], [4, 5]]

An array’s dimensions may be read with the shape attribute, which returns a tuple containing the size of each dimension. The following example shows output for a tag of type DINT[4,3,2]. Note the tuple’s reversed display order as the number of elements in DimX is placed in shape[X].

>>> prj.controller.tags['array'].shape
(2, 3, 4)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

l5x-1.0.win32.exe (214.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page