Dieses Kapitel beschreibt Methoden zum Bearbeiten von Geräteobjekten.
Diese Methode fügt das spezifizierte Gerät hinzu.
Sie besteht aus drei Parametern:
oEine Zeichenfolge, die den Namen des Geräts angibt.
oDeviceID, die die ID des Geräts angibt. Für den DeviceID-Wert, siehe die Gerätebeschreibung des hinzuzufügenden Geräts.
oEine Zeichenfolge, die die Modul-ID angibt.
# We want to add a TM5C12D6T6L Module to the TM5_Manager
# Search for the TM5_Manager. The new Module will be inserted below this object.
parent_device = projects.primary.find('TM5_Manager', True)[0]
if not(parent_device == None):
parent_device.add("Module_TM5C12D6T6L", DeviceID(51063, "101a 0363", "3.1.2.2"))
Diese Methode markiert dieses Gerät während des Downloads als deaktiviert.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
device.disable()
Diese Methode markiert dieses Gerät während des Downloads als aktiviert.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
device.enable()
Diese Methode ruft die Adresse des Geräts ab. Es wird eine Zeichenfolge zurückgegeben.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
print("Address: " + device.get_address())
Diese Methode ruft die Geräte-Identifikation ab.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
print(str(device.get_device_identification()))
Diese Methode gibt die GUID des Gateways zurück.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
print("Gateway: " + str(device.get_gateway()))
Diese Methode fügt das spezifizierte Gerät dem spezifizierten Index hinzu.
Sie besteht aus vier Parametern:
oEine Zeichenfolge, die den Namen des Geräts angibt.
oInt32 verweist auf den Index, dem das Gerät hinzugefügt werden soll.
oDeviceID gibt die ID des Geräts an. Für den DeviceID-Wert, siehe die Gerätebeschreibung des hinzuzufügenden Geräts.
oEine Zeichenfolge, die die Modul-ID angibt.
# Finds the MyController object in the project
parent_device = projects.primary.find("TM5_Manager", True)[0]
if not(parent_device == None):
# We need the amount of children to add the new device at the end
child_count = len(parent_device.get_children())
# Use a unique name for the inserted device
parent_device.insert("Module_TM5C12D6T6L_" + str(child_count), child_count, DeviceID(51063, "101a 0363", "3.1.2.2"))
Diese Methode setzt das Gateway und die Adresse. Wenn Sie die leere GUID und eine leere Adresse übergeben, wird die Gateway-Adresse gelöscht.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
device.set_gateway_and_address(gateway, address)
Diese Methode setzt den Simulationsmodus. Auf True gesetzt, ist die Simulation aktiviert.
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
device.set_simulation_mode (True)
Diese Methode aktualisiert das spezifizierte Gerät.
# This is a more generic approach to find and update a device by its device description
import os
def find_device_repository(head_dir, sub_dir):
for root, dirs, files in os.walk(head_dir):
for d in dirs:
current_dir = os.path.join(root, d)
if current_dir.endswith(sub_dir):
return current_dir
# This function is used to find the newest version
def version_tuple(v):
return tuple(map(int, (v.split("."))))
def get_newest_version(directory, current_version):
newest_version = None
available_versions = os.listdir(directory)
for version in available_versions:
if version_tuple(version ) > version_tuple(current_version):
newest_version = version
return newest_version
# Finds the MyController object in the project
device = projects.primary.find("MyController", True)[0]
if not(device == None):
device_identification = device.get_device_identification()
# Device Repository subdirectory
sub_dir = os.path.join(str(device_identification.type), device_identification.id)
# Find the path where the device description is stored
result_directory= find_device_repository(r"c:/", sub_dir)
if not result_directory == None:
newest_version = get_newest_version(result_directory, device_identification.version)
if not newest_version == None:
device.update(device_identification.type, device_identification.id, newest_version)