dir()
y inspectapi
)
EcoStruxure Machine Expert incluye una API de Python que podrá utilizar para los scripts de EcoStruxure Machine Expert. Cuando escribe Python, la mayoría de las veces solo necesita nombres de funciones o la lista de parámetros requeridos y sus nombres. Con frecuencia, también necesitará las funciones disponibles de un objeto devuelto por una función de la API que haya llamado. Las siguientes funciones le permiten explorar la API de Python de EcoStruxure Machine Expert para ayudarle en el desarrollo de scripts Python.
dir(…)
integrada de Python
Sin argumentos, esta función devuelve la lista de nombres en el ámbito local actual. Con un argumento, esta función intenta devolver una lista de atributos válidos para el objeto en cuestión.
El mecanismo predeterminado de dir()
de Python se comporta de manera diferente con diferentes tipos de objetos, ya que intenta producir la información más relevante, en lugar de la información completa:
Si el objeto es un objeto de módulo, la lista contendrá los nombres de los atributos del módulo.
Si el objeto es un objeto de tipo o clase, la lista contendrá los nombres de sus atributos y, de manera recursiva, los nombres de los atributos de sus bases.
De lo contrario, la lista contendrá los nombres de los atributos del objeto, los nombres de los atributos de su clase y, de manera recursiva, los nombres de los atributos de las clases básicas.
Ejemplo (en LogicBuilderShell.exe):
>>> import struct
>>> dir() # show the names in the module namespace
['__builtins__', '__doc__', '__name__', 'struct']
>>> dir(struct) # show the names in the struct module
['Struct', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
'unpack', 'unpack_from']
>>> class Shape(object):
def __dir__(self):
return ['area', 'perimeter', 'location']
>>> s = Shape()
>>> dir(s)
['area', 'perimeter', 'location']
inspectapi
Ya que la función dir()
no enumera todos los elementos de la API de Python de EcoStruxure Machine Expert, se muestran funciones adicionales disponibles para los desarrolladores de scripts de Python.
inspectapi
es un módulo Python que se carga automáticamente mientras se inicia LogicBuilderShell.exe o la vista . Como resultado, hay disponible una variable/módulo inspectapi
en el ámbito actual. Esta variable también se enumera al ejecutar la función dir()
.
La variable/módulo inspectapi
proporciona las siguientes funciones:
Nombre de la función |
Parámetros |
Descripción |
---|---|---|
|
(opcional) |
Esta función proporciona una lista de los miembros de la API de Python de EcoStruxure Machine Expert disponibles que puede llamar. Se enumeran los campos, las propiedades, los eventos y los métodos. |
|
Esta función proporciona una lista de los eventos de la API de Python de EcoStruxure Machine Expert disponibles que puede llamar. |
|
|
||
|
||
|
||
|
|
Esta función abre la ayuda online de la Guía del Usuario de CODESYS Script Engine Guía . Para obtener más información, consulte también la Guía del usuario de Schneider Electric Script Engine Guía del usuario de Schneider Electric Script Engine online. |
|
Esta función abre la ayuda online del objeto.
|
# To see the API of the inspect api itself
inspectapi.dir(inspectapi)
Members of type 'InspectAPI'
Methods:
dir (obj, verbose = False)
dir_events (obj, verbose = False)
dir_fields (obj, verbose = False)
dir_methods (obj, verbose = False)
dir_properties (obj, verbose = False)
help (obj = null)
# To see the API of projects variable
inspectapi.dir(projects)
Members of type 'ScriptProjects'
Properties:
[get] all
[get] primary
Methods:
convert (stPath, stOutputPath, converter, bPrimary)
convert (stPath, stOutputPath, converterGuid, bPrimary)
create (stPath, bPrimary)
get_all ()
get_by_path (stPath)
get_primary ()
open (stPath, stPassword, bPrimary)
open (stPath, encryption_password, session_user, session_password, bPrimary)
open_archive (stArchiveFile, stProjectPath, bOverwrite, stPassword)
open_archive (stArchiveFile, stProjectPath, bOverwrite, encryption_password, session_user, session_password)
# open a project
proj = projects.open("c:\\temp\\MyScript.py ")
# To see API of primary project
inspectapi.dir(projects.primary)
Members of type 'ScriptProject'
Properties:
[set] active_application
[get] dirty
[get] handle
[get] has_library_manager
[get] has_project_info
[get] is_root
[get] library
[get] path
[get] primary
[get] project
[get] svn
[get] user_management
Methods:
add (stName, id, stModuleId)
add (stName, iType, stId, stVersion, stModuleId)
check_all_pool_objects ()
clean_all ()
close ()
compare_to (projectFile)
compare_to (projectFile, ignoreWhiteSpace, ignoreComments, ignoreProperties)
...
logout ()
save ()
save_archive (stArchiveFile)
save_archive (stPath, additional_categories)
save_archive (stPath, comment, additional_categories)
save_archive (stPath, additional_files, additional_categories)
....
save_as (stPath, stPassword)
save_as_compiled_library (destination_name)
set_active_application (value)
update ()
# search objects by name (e.g. a device with name SERCOSIII)
objs = projects.primary.find("SERCOSIII", True)
# extract object at index 0 from returned list (if found).
theObj = obj[0]
# see the available API of the found object SERCOSIII
inspectapi.dir(theObj)
Members of type 'ScriptObject'
Properties:
[get] connectors
[get] device_parameters
[get] embedded_object_types
[get] guid
[get] handle
[get] has_textual_declaration
[get] has_textual_implementation
[get] index
[get] is_application
[get] is_device
[get] is_explicit_connector
[get] is_folder
[get] is_libman
[get] is_project_info
[get] is_root
[get] is_task
[get] parent
[get] project
[get] svn
[get] type
Methods:
add (stName, id, stModuleId)
add (stName, iType, stId, stVersion, stModuleId)
allowed_interfaces_at (index)
can_convert (targetDeviceId, targetModuleId = null)
can_convert (targetType, targetId, targetVersion, targetModuleId = null)
convert (targetDeviceId, targetModuleId = null)
convert (targetType, targetId, targetVersion, targetModuleId = null)
create_folder (stFolderName)
disable ()
enable ()
export_native (destination, includeChildren, profileName, reporter)
export_xml (reporter, stPath, bRecursive)
export_xml (reporter, stPath, bRecursive, bExportFolderStructure)
export_xml (reporter, stPath, bRecursive, bExportFolderStructure, bPlainText)
export_xml (stPath, bRecursive, bExportFolderStructure, bPlainText)
find (namePath)
find (stName, recursive)
get_address ()
get_all_parameters ()
...
move (newParent, nNewIndex)
plug (stName, id, stModuleId)
plug (stName, iType, stId, stVersion, stModuleId)
reboot_plc ()
remove ()
rename (stNewName)
reset_diagnosis_messages ()
set_communication_address (address)
set_gateway_and_address (stGateway, stAddress)
set_gateway_and_address (gateway, stAddress)
set_parameter (parameter, value)
set_parameter_iec_address (identifier, connectorId, iecAddress)
set_parameter_io_variable_mapping (identifier, connectorId, variable, createVariable = False)
set_parameter_io_variable_mapping (identifier, connectorId, subElementIndex, variable, createVariable = False)
set_simulation_mode (bSimulation)
unplug ()
update (id, stModuleId)
update (iType, stId, stVersion, stModuleId)