xml_obj.py

xml_obj.py

This file contains the objects for representing the essential TwinCAT variables and data structures found in the xml (tmc) formatted file.

Symbol

class pytmc.Symbol(element, base=None, suffixes=None)

Inherits from BaseElement

Symbol instances represent instantiated variables and DataTypes.

Parameters
  • element (xml.etree.ElementTree.Element) – A python xml element object connected to the intended .tmc datagroup

  • base (str) – The prefix that will mark pragmas intended for pytmc’s consumption.

property tc_type

Return the type of the data this symbol represents.

Returns

Name of data type (e.g. DINT in the case of a basic type or ‘iterator’ if it is an instance of a user defined struct/fb named ‘iterator’

Return type

str

DataType

class pytmc.DataType(element, base=None, suffixes=None)

Inherits from BaseElement

DataType instances represents the templates for uninstantiated FunctionBlocks, Enums, Structs, Unions, and Aliases.

children

This list contains the SubItem instances that this DataType contains. It is not recommended to set this attribute directly. Instead, set parent, which automates the setup of children for bi-directional look-up.

Type

list

Parameters
  • element (xml.etree.ElementTree.Element) – A python xml element object connected to the intended .tmc datagroup

  • base (str) – The prefix that will mark pragmas intended for pytmc’s consumption.

property datatype

Return the type of the data this symbol represents.

Returns

Name of data type

Return type

str

property is_enum

This property is true if this twincat element is an enum. It works for Datatypes, symbols and subItems.

Returns

is true if this twincat element is an enum.

Return type

Bool

property tc_extends

Return the DataType that this DataType is built upon

Returns

DataType name or None if there is no parent

Return type

str or None

SubItem

class pytmc.SubItem(element, base=None, suffixes=None, parent=None)

Inherits from baseElement

SubItem instances represent variables and DataTypes instantiated within DataTypes.

parent

This is a reference to the DataType that contains this SubItem. We reccommend setting this attribute directly instead of setting children. This property automates settting children for bi-directional look-up. The relationship can be deleted using del SubItem_instance.parent or by setting parent equal to None. To create a relationship, simply set parent equal to the intended parent.

Type

str or None

Parameters
  • element (xml.etree.ElementTree.Element) – A python xml element object connected to the intended .tmc datagroup

  • base (str) – The prefix that will mark pragmas intended for pytmc’s consumption.

  • parent (baseElement) – The DataStructure in which this SubItem appears

property tc_type

Return the type of the data this symbol represents.

Returns

Name of data type (e.g. DINT in the case of a basic type or ‘iterator’ if it is an instance of a user defined struct/fb named ‘iterator’

Return type

str

BaseElement

class pytmc.xml_obj.BaseElement(element, base=None, suffixes=None)

Base class for representing variables as they appear in the .tmc (xml) format.

Parameters
  • element (xml.etree.ElementTree.Element) – A python xml element object connected to the intended .tmc datagroup

  • base (str) – The prefix that will mark pragmas intended for pytmc’s consumption.

property has_config

Shortcut for determining if this element has pragmas.

Returns

True if there is a config pragma attached to this xml element

Return type

bool

property is_array

This property is true if this twincat element is an array.

Returns

is true if this twincat element is an array

Return type

Bool

property is_str

This property is true if this twincat element is a string.

Returns

is true if this twincat element is an string

Return type

Bool

property iterable_length

Obtain the length of an iterable type.

Returns

Return the length of the string/array if the element is a string or an array. Otherwise return None

Return type

int or None

property name

Return the user assigned TwinCAT variable name for this Symbol/DataType/SubItem. This info is taken from the text of the name field sub-element.

Returns

The name of the variable

Return type

str

property properties

Produce a dictionary of lists for the properties associated with this element. The value of the dictionary is a list allowing for multiple properties w/ the same name.

Returns

Dictionary. The key is the property name and the value is a list of values found in the xml

Return type

dict

property raw_config

Produce a stripped-down set of properties including only those that are recognized as pragmas intended for pytmc’s consumption.

Returns

produce the string from the pragma marked for pytmc or a None if no such pragma can be found

Return type

str or None