IDevicePropertiesExtension

class

IDevicePropertiesExtension.

IDevicePropertiesExtension

Bases: object

This class is an extension object of CODESYS IScriptDeviceObject .

driver_info_ext

This property provides access to the information needed in order to configure the driver and supporting objects of the connector.

get_all_parameters

Retrieves the parameters from a device.

Returns

Method returns an IEnumerable that contains the parameters of the device.

Return type

IEnumerable

Note

Each entry in the list represents an IParameter object. The members of this object can be found in CODESYS API description.

This example shows how to get a list with the parameters from a device.

# Script searches for a specific device and prints all parameters
# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\GetAllParameters.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# Define the printing function
def printtree(treeobj, depth=0):

    # Verify if the treeobj is a device
    if treeobj.is_device:
        # Get the not localized name of the device
        device_name = treeobj.get_name(False)

        # If name matches the device name that we want...
        if device_name == "DRV_Lexium62":

            # Call the get_all_parameters() function, to get a complete list of all parameters of that device object.
            # A parameter can contain subparameter, which can be verified with .HasSubElements property
            parameter_list = treeobj.get_all_parameters()
        
            # prints all parameters
            for parameter in parameter_list:
                print("ID: " + parameter.Identifier + " Name: " + parameter.VisibleName + " Value: " + parameter.Value + " ParameterSet: " + str((parameter.GetAssociatedConnector).ConnectorId))
            
    # Get all child object, if get_children(True) and call the printtree function recursivley
    for child in treeobj.get_children(False):
        printtree(child, depth+1)

# Get all objects in the device tree
objects = proj.get_children()

# Call the printtree function for each object in the device tree
for singleobject in objects:
    printtree(singleobject)

get_parameter

identifier

connectorID

Retrieves a specific parameter by identifier and connector id.

Parameters
  • identifier (long) -- Unique identifier of this data element within its parent element.

  • connectorID (int) -- The connector id for a specific parameter.

Returns

An element that specifies a value. Base type for Parameter objects and interface of the subcomponents of a parameter. May be a structured type itself and in turn contain other data elements.

Return type

IDataElement

Note

If you do not know the identifier and the connector id, you can call the get_all_parameters() method to identify them. The members of this object can be found in CODESYS API description.

This example shows how to get a specific parameter from a device.

# Script searches for a specific device and prints all parameters
# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\GetParameter.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# Search a specific device in the project by name
device = proj.find('DRV_Lexium62', True)[0]

# If device is found, get a specific parameter
if device != None:
    # We are interestet in the WorkingMode parameter
    # As we have seen in get_all_parameters() the working mode has the following id and parameter set:
    # ID: 191 Name: WorkingMode Value: 1 ParameterSet: 1
    parameter = device.get_parameter(191, 1)

    # Print the value of the offline parameter
    print("ID: " + parameter.Identifier + " Name: " + parameter.VisibleName + " Value: " + parameter.Value + " ParameterSet: " + str((parameter.GetAssociatedConnector).ConnectorId))

set_parameter

parameter

value

This function is used to set a specific offline parameter value.

Parameters
  • parameter (IParameter) -- The parameter whose offline value is to be changed.

  • value (string) -- The new offline value of the parameter.

Note

If the parameter is null an ArgumentNullException is reported. If present, the device editor is also updated (only GUI mode).

This example shows how to set a specific parameter value from a device.

# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\SetParameter.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# To set a parameter you need a device, a parameter and a new value that should be assigned to the parameter
# At first we search for the SERCOSIII node...
sercosNode = proj.find('SERCOSIII', True)[0]

# Add a new device named Robot_XK29 to the SERCOSIII node, we assume that no other device is below the SERCOSIII node, otherwise the index must be changed
sercosNode.insert("Robot_XK29", 0, DeviceID(4096, "1003 0082", "1.36.2.2"), 'LXM62DxS')

# Now we get the children of the SERCOS node, we assume that Robot_XK29 is the only one, otherwise the index must be changed
Robot_XK29 = sercosNode.get_children(True)[0]

# Call the get_all_parameters() function, to get a complete list of all parameters of that device object.
# A parameter can contain subparameter, which can be verified with .HasSubElements property
parameter_list = treeobj.get_all_parameters()
        
# prints all parameters
for parameter in parameter_list:
    print("ID: " + parameter.Identifier + " Name: " + parameter.VisibleName + " Value: " + parameter.Value + " ParameterSet: " + str((parameter.GetAssociatedConnector).ConnectorId))

# We get the WorkingMode parameter:
# ID: 191 Name: WorkingMode Value: 1 ParameterSet: 1
working_mode = Robot_XK29.get_parameter(191, 1)

# Finally we set the WorkingMode parameter to 2 = Deactivated
Robot_XK29.set_parameter(working_mode, "2")

get_parameter_iec_address

identifier

connectorId

Retrieves the address where to map this item in the process image.

Parameters
  • identifier (long) -- Unique identifier of this data element within its parent element.

  • connectorId (int) -- The connector id for a specific parameter.

Returns

The address of the specified parameter.

Return type

string

Reports

ArgumentOutOfRangeException -- A parameter with the specified identifier and connectorId does not exist.

This example shows how to modify the address of a specific device parameter.

# Script searches for a specific device and prints all parameters
# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\ModifyParameterIecAddress.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# Search a specific device in the project by name
device = proj.find('_1_byte_input_0x10_', True)[0]

# If device is found, read the address and modify it
if device != None:        
    # Read the address of the 'Input0' parameter / channel; ID: 1, ConnectorId: 1
    iec_address = device.get_parameter_iec_address(1, 1)
	print(iec_address)
	
    # Set the address of the 'Input0' parameter / channel to '%IB3' and print out the new value to validate the operation
	device.set_parameter_iec_address(1, 1, '%IB3')
	iec_address = device.get_parameter_iec_address(1, 1)
	print(iec_address)

set_parameter_iec_address

identifier

connectorId

iecAddress

Sets the address where to map this item in the process image.

Parameters
  • identifier (long) -- Unique identifier of this data element within its parent element.

  • connectorId (int) -- The connector id for a specific parameter.

  • iecAddress (string) -- The new address for the specified parameter. If null is passed, the address is assigned automatically.

Reports

ArgumentOutOfRangeException -- A parameter with the specified identifier and connectorId does not exist.

This example shows how to modify the address of a specific device parameter.

# Script searches for a specific device and prints all parameters
# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\ModifyParameterIecAddress.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# Search a specific device in the project by name
device = proj.find('_1_byte_input_0x10_', True)[0]

# If device is found, read the address and modify it
if device != None:        
    # Read the address of the 'Input0' parameter / channel; ID: 1, ConnectorId: 1
    iec_address = device.get_parameter_iec_address(1, 1)
	print(iec_address)
	
    # Set the address of the 'Input0' parameter / channel to '%IB3' and print out the new value to validate the operation
	device.set_parameter_iec_address(1, 1, '%IB3')
	iec_address = device.get_parameter_iec_address(1, 1)
	print(iec_address)

get_parameter_io_variable_mapping

identifier

connectorId

subElementIndex

Retrieves the mapping of a data element (subelement) on a specific variable. If a variable mapping is defined an instance of IScriptVariableMapping will be returned. If no variable mapping is defined null will be returned.

Parameters
  • identifier (long) -- Unique identifier of this data element within its parent element.

  • connectorId (int) -- The connector id for a specific parameter.

  • subElementIndex (int) -- Zero-based index of the subelement to get or set.

Returns

The variable mapping of the specified parameter or null if no mapping is defined.

Reports
  • ArgumentOutOfRangeException -- A parameter with the specified identifier and connectorId does not exist.

  • IndexOutOfRangeException -- SubElementIndex is smaller then zero or greater then the number of subelements in the specified parameter.

This example shows how to modify the IO mapping of a specific device parameter.

# Script searches for a specific device and prints all parameters
# We enable the new python 3 print syntax
from __future__ import print_function

# The path to our project
project_path = r"D:\PythonProjects\ModifyIoMapping.project"

# Clean up any open project:
if projects.primary:
    projects.primary.close()

# Load the project
proj = projects.open(project_path);

# Set the project as primary project
proj = projects.primary

# define a print function to write the mapping of a device parameter to the console
def print_variable_mapping(device, parameter_id, connector_id):

	parameter = device.get_parameter(parameter_id, connector_id)
	variable_mapping = device.get_parameter_io_variable_mapping(parameter_id, connector_id)

	if variable_mapping != None:
		print("Parameter: " + parameter.VisibleName + " of device " + device.get_name() + " is mapped to " + variable_mapping.variable)
	else:
		print("No mapping defined for parameter: " + parameter.VisibleName + " of device " + device.get_name())

# Search a specific device in the project by name
device = proj.find('_1_byte_input_0x10_', True)[0]

# If device is found, read the address and modify it
if device != None:

	# Print the mapping
	print_variable_mapping(device, 1, 1)
 
	# Map the 'Input0' parameter / channel to 'Application.bTest'
	device.set_parameter_io_variable_mapping(1, 1, 'Application.bTest')
	
	# Map the first two bits of 'Input0' to an existing variable
	device.set_parameter_io_variable_mapping(1, 1, 0, 'Application.xTest1')
	device.set_parameter_io_variable_mapping(1, 1, 1, 'Application.xTest2', False)
 
 	# Map the third bit of 'Input0' to a newly created variable
	device.set_parameter_io_variable_mapping(1, 1, 2, 'Application.xTest3', True)
 
	# Print the mapping again
	print_variable_mapping(device, 1, 1)

set_parameter_io_variable_mapping

identifier

connectorId

subElementIndex

variable

createVariable=False

Defines the mapping of a data element (subelement) on a specific variable.

Parameters
  • identifier (long) -- Unique identifier of this data element within its parent element.

  • connectorId (int) -- The connector id for a specific parameter.

  • subElementIndex (int) -- Zero-based index of the subelement to get or set.

  • variable (string) -- The name of the variable on which the value is to be mapped. If null is passed, the mapping is removed.

  • createVariable (bool) -- Describes whether a new variable is to be created or the channel is mapped on an existing variable. (This parameter is optional, default = false)

get_effective_connectors

Retrieves the effective connectors of the device. Some devices specify multiple connectors that are effective dependent of the parent device. In contrast the property 'connectors' returns all connectors.

Returns

A list of the effective IScriptDeviceConnector s.

Return type

IList

get_effective_parameters

Retrieves the effective parameters of the device. This means the device parameters and the parameters of the effective connectors.

Returns

A list of the effective IScriptDeviceParameter s.

Return type

IList