構成API ¶
モジュール: typhoon.api.configuration
構成 API は、Typhoon HIL コントロール センターの定義済み構成を読み取り、更新するために使用される一連のメソッドです。
APIリファレンス¶
- クラス 構成API ( * args , ** kwargs ) ¶
- 取得(キー: str = '' ) str | フロート | 整数 | ブール | 辞書 | リスト | なし ¶
キーで指定された構成項目の現在の値を取得します。
- パラメータ:
key ( str ) – 取得する設定項目の識別子。設定の一部を取得する場合は部分的な値(例:“general” または “general.autosave”)を指定し、設定全体を取得する場合は空の値を指定します。
- 戻り値:
設定項目の現在の値。型はstr、float、int、bool、dict、list、またはNoneです。
- 戻り値の型:
JSONスキーマ値
- 昇給:
KeyError – キーが構成スキーマの一部ではない場合。
注記
使用できるのは定義済みのキーのみです。設定キーの完全なリストとその説明については、以下の「get_schema」メソッドの例をご覧ください。
例:
# # Get a typed value from the configuration by key # from typhoon.api.configuration import configuration autosave_interval: int = configuration.get("general.autosave.interval") print(f"The autosave interval is {autosave_interval} seconds.") # Get values prefixed with partial key general_configuration = configuration.get("general") print(general_configuration)
出力
The autosave interval is 180 seconds. {'general.autosave.interval': 180, 'general.autosave.file_extension': '.bak'}
- get_schema (キー: str = '' ) JSONSchema ¶
キーによって識別される構成項目のスキーマを取得します。
- パラメータ:
key ( str ,オプション) – 取得する設定項目の識別子。スキーマの一部を取得する場合は部分的な値(例:“general” または “general.autosave”)を指定し、スキーマ全体を取得する場合は空の値を指定します。
- 戻り値:
JSONSchema 形式の構成項目のスキーマ。
- 戻り値の型:
JSONスキーマ
- 昇給:
KeyError – キーが構成スキーマの一部ではない場合。
注記
「internal」とマークされたスキーマ キーは、Typhoon HIL コントロール センターにある設定 UI には表示されませんが、API では引き続き使用できます。
例:
# # すべての設定キーのスキーマを取得する#インポート JSONから typhoon.api.configuration 設定をインポートします。 schema = configuration.get_schema ( ) print ( json.dumps ( schema , indent = 4 ) )
出力
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "/typhoon/thcc/configuration/schema.json", "title": "Typhoon HIL Control Center Configuration Schema", "description": "JSON Schema describing the configuration of various parts of the Typhoon HIL Control Center", "type": "object", "properties": { "general.autosave.interval": { "type": "number", "markdownDescription": "\n Interval (in seconds) between auto-saves in the HIL SCADA and Schematic Editor.\n ", "default": 180, "minimum": 3, "maximum": 36000 }, "general.autosave.file_extension": { "type": "string", "markdownDescription": "\n File extension for autosave files. The default extension is '.bak'.\n ", "default": ".bak", "pattern": "^\\.[a-zA-Z0-9]{1,10}$", "patternErrorMessage": "Extension must start with a period and contain 1-10 alphanumeric characters. E.g., '.bak'" }, "debug.logging_on": { "type": "boolean", "markdownDescription": "\n Enables or disables logging.\n The file <code>server.log</code> is created in the source directory.\n This settings is disabled by default.\n ", "default": false, "internal": true }, "paths.user_lib_dir": { "title": "User Library Directories", "type": "object", "description": "User library directories to include. Each item represents a directory, and if its checkbox is checked the subdirectories will be included in the path as well.", "additionalProperties": { "type": "boolean", "description": "Indicates whether the library path should be imported recursively." }, "default": {}, "examples": [ { "C:\\Users\\DefaultUser\\AppData\\Roaming\\typhoon\\user-libs": true } ], "internal": true }, "paths.user_lib_dir.disabled": { "title": "Disabled User Library Directories", "type": "array", "description": "User library directories that should not be loaded.", "items": { "type": "string" }, "default": [], "internal": true }, "external_tools.psim_path": { "title": "PSIM Installation Directory", "type": "string", "markdownDescription": "\n Specifies the installation directory of the PSIM tool, if used. Empty if not set.\n <br><br>\n <b>Note:</b>\n <br>\n In order to import PSIM schematic files, the PSIM software v12.0.3 or later has to\n be installed and activated with a valid license on your PC. <br>\n If you still do not have the PSIM software,\n please contact: <a href='https://powersimtech.com/products/psim/'>https://powersimtech.com/products/psim/</a>\n ", "default": "" }, "control_center.hil_setup.default_path": { "type": [ "string", "null" ], "description": "Default path for HIL setup files. Typhoon HIL Control Center needs to be restarted for changes to take effect.", "default": null, "internal": true }, "control_center.hil_setup.custom_ip_addresses": { "type": "array", "description": "Specify a list of IP addresses where HIL devices are located if auto discovery fails to find them. Typhoon HIL Control Center needs to be restarted for changes to take effect.", "items": { "type": "string", "format": "ipv4" }, "default": [], "internal": true }, "hil_activation.proxy.address": { "type": "string", "description": "HIL Activation Proxy Address. ", "default": "", "internal": true }, "hil_activation.proxy.port": { "type": "integer", "description": "HIL Activation Proxy Port. ", "default": 80, "minimum": 1, "maximum": 65535, "internal": true }, "hil_activation.proxy.username": { "type": "string", "description": "HIL Activation Proxy Username. ", "default": "", "internal": true }, "hil_activation.proxy.password": { "type": "string", "description": "HIL Activation Proxy Password. ", "default": "", "internal": true }, "hil_activation.proxy.authentication_method": { "type": "string", "markdownDescription": "\n HIL Activation Proxy Authentication Method.\n HIL Activation Proxy Authentication Method.\n The default authentication method is <code>BASIC_AUTHENTICATION</code>.\n ", "default": "BASIC_AUTHENTICATION", "enum": [ "BASIC_AUTHENTICATION", "DIGEST_AUTHENTICATION" ], "enumDescriptions": [ "The username and password are sent in clear text.", "The username and password are hashed before sending." ], "internal": true }, "hil.server_rep_port": { "title": "HIL Server Response Port", "type": [ "integer", "null" ], "description": "HIL Server's response port. This parameter is assigned a random port between 49152 and 65535 at startup.", "default": null, "minimum": 1, "maximum": 65535, "internal": true }, "signal_analyzer.recent_files.recent_data_files": { "type": "array", "description": "List of recently opened signal analyzer data files.", "items": { "type": "string" }, "default": [], "internal": true }, "schematic_editor.perspective": { "type": "string", "enum": [ "REAL_TIME", "TYPHOONSIM", "BOTH" ], "enumDescriptions": [ "Real-time perspective", "TyphoonSim perspective", "Integrated perspective" ], "default": "BOTH", "description": "Schematic editor perspective.", "internal": true }, "schematic_editor.recent_files.recent_schematic_files": { "type": "array", "description": "List of recently opened schematic (.tse) files.", "items": { "type": "string" }, "default": [], "internal": true }, "schematic_editor.server_rep_port": { "title": "Schematic Editor Server Response Port", "type": [ "integer", "null" ], "description": "Schematic Editor Server's response port. This parameter is assigned a random port between 49152 and 65535 at startup.", "default": null, "minimum": 1, "maximum": 65535, "internal": true }, "scada.recent_files.recent_model_files": { "type": "array", "description": "List of recently opened model files.", "items": { "type": "string" }, "default": [], "internal": true }, "scada.recent_files.recent_model_settings_files": { "type": "array", "description": "List of recently opened model settings files.", "items": { "type": "string" }, "default": [], "internal": true }, "scada.recent_files.recent_hil_scada_files": { "type": "array", "description": "List of recently opened HIL SCADA files.", "items": { "type": "string" }, "default": [], "internal": true }, "scada.recent_directories.last_cpd_files_dir": { "title": "Last CPD Files Directory", "type": [ "string", "null" ], "description": "Last used directory for CPD files.", "default": null, "internal": true }, "typhoon_test_ide.recent_files.recent_scripts": { "type": "array", "description": "List of recently opened scripts.", "items": { "type": "string" }, "default": [], "internal": true }, "typhoon_test_ide.interpreters.custom_interpreter_cmd": { "type": [ "string", "null" ], "title": "Custom Interpreter Command", "description": "Custom interpreter command.", "default": null, "internal": true }, "typhoon_test_ide.pdf.trace": { "type": "boolean", "description": "Enable or disable trace in the PDF report.", "default": false, "internal": true }, "typhoon_test_ide.pdf.plots": { "type": "boolean", "description": "Enable or disable plots in the PDF report.", "default": true, "internal": true }, "typhoon_test_ide.pdf.steps": { "type": "boolean", "description": "Enable or disable steps in the PDF report.", "default": true, "internal": true }, "typhoon_test_ide.pdf.slogan": { "type": "string", "description": "Slogan to be displayed in the PDF report.", "default": "**Test**\n**_Design_**\n_Deploy_", "internal": true }, "typhoon_test_ide.pdf.color": { "type": "string", "description": "Color for the PDF report heading text in HEX format (eg. #333333).", "default": "#333333", "pattern": "^#[0-9a-fA-F]{6}$", "internal": true }, "typhoon_test_ide.pdf.title": { "type": "string", "description": "Title for the PDF report.", "default": "Typhoon HIL Test session report", "internal": true }, "typhoon_test_ide.pdf.work_dir": { "type": "boolean", "markdownDescription": "\n Use the working directory for the PDF report.\n If disabled, the file path configured in <a href=\"typhoon_test_ide.pdf.file_path\">PDF: File Path</a> will be used.\n ", "default": true, "internal": true }, "typhoon_test_ide.pdf.file_path": { "type": "string", "markdownDescription": "\n File path for the PDF report.\n This path is ignored if <a href=\"typhoon_test_ide.pdf.work_dir\">PDF: Work Dir</a> is enabled.\n ", "default": "", "internal": true }, "typhoon_test_ide.pdf.typhoon_logo": { "type": "boolean", "description": "Include the Typhoon HIL logo in the PDF report.", "default": true, "internal": true }, "typhoon_test_ide.pdf.logo": { "type": "string", "markdownDescription": "\n Path to a custom logo to include in the PDF report.\n This path is ignored if <a href='typhoon_test_ide.pdf.typhoon_logo'>PDF: Typhoon Logo</a> is enabled.\n ", "default": "", "internal": true }, "scada.server_rep_port": { "title": "SCADA Server Response Port", "type": [ "integer", "null" ], "description": "SCADA Server's response port. This parameter is assigned a random port between 49152 and 65535 at startup.", "default": null, "minimum": 1, "maximum": 65535, "internal": true }, "pv_generator.server_rep_port": { "title": "PV Generator Server Response Port", "type": [ "integer", "null" ], "description": "PV Generator Server's response port. This parameter is assigned a random port between 49152 and 65535 at startup.", "default": null, "minimum": 1, "maximum": 65535, "internal": true }, "firmware_manager.server_rep_port": { "title": "Firmware Manager Server Response Port", "type": [ "integer", "null" ], "description": "Firmware Manager Server's response port. This parameter is assigned a random port between 49152 and 65535 at startup.", "default": null, "minimum": 1, "maximum": 65535, "internal": true }, "vhil.announcement_port_range": { "type": "string", "description": "Range of ports for announcements. The format is a dash-delimited range, e.g., '40000-40050'.", "pattern": "^[0-9]{1,5}-[0-9]{1,5}$", "default": "40000-40050", "internal": true }, "communication.announcement_port_req_range": { "title": "Announcement Port Request Range", "type": "string", "description": "Range for announcement port requests. The format is a dash-delimited range, e.g., '30000-30100'.", "default": "30000-30100", "pattern": "^[0-9]{1,5}-[0-9]{1,5}$", "examples": [ "30000-30100" ], "internal": true }, "communication.announcement_port_pub_range": { "title": "Announcement Port Publication Range", "type": "string", "description": "Range for announcement port publications. The format is a dash-delimited range, e.g., '50000-50100'.", "default": "50000-50100", "pattern": "^(\\d{1,5})-(\\d{1,5})$", "examples": [ "50000-50100" ], "errorMessage": "Port range must be in the format 'lower-upper', where both sides are valid port numbers (1-65535) and the upper must be greater than the lower.", "internal": true }, "communication.control_center_port": { "type": "integer", "description": "Port used by the control center.", "default": 54972, "minimum": 1, "maximum": 65535, "internal": true }, "communication.user_defined_ip_timeout": { "type": "integer", "description": "Timeout (in milliseconds) for user-defined IP connections.", "default": 500, "minimum": 1, "internal": true }, "communication.socket_read_timeout": { "type": "integer", "description": "Timeout (in milliseconds) for socket reads.", "default": 20000, "minimum": 1, "internal": true }, "communication.heartbeat_timeout": { "type": "integer", "description": "Timeout (in milliseconds) for heartbeat signals.", "default": 5000, "minimum": 1, "internal": true } } }
- リセット(キー: str ) ¶
指定されたキーの構成値をデフォルト値または初期値にリセットします。
- パラメータ:
key ( str ) – リセットする構成項目の識別子。
- 昇給:
KeyError – キーが構成スキーマの一部ではない場合。
json.JSONDecodeError – 構成ファイルが不正な形式であるため、手動で修正する必要がある場合。
例:
# # 設定値をキー#でデフォルトにリセットします typhoon.api.configuration 設定をインポートします。configuration.reset ( " control_center.hil_setup.custom_ip_addresses" ) ip_addresses = configuration.get ( "control_center.hil_setup.custom_ip_addresses" ) print ( ip_addresses )
出力
[]
- セット(キー: 文字列、値: str | フロート | 整数 | ブール | 辞書 | リスト | なし) ¶
キーによって識別される構成項目の値を設定します。
- パラメータ:
key ( str ) – 更新する構成項目の識別子。
value ( JSONSchemaType ) – 設定項目に設定する新しい値。項目のスキーマと一致する必要があります。
- 昇給:
KeyError – キーが構成スキーマの一部ではない場合。
jsonschema.exceptions.ValidationError – 値がスキーマに準拠していない場合。
json.JSONDecodeError – 構成ファイルが不正な形式であるため、手動で修正する必要がある場合。
- 購読(キー: str 、ハンドラー: 呼び出し可能[ [ dict [ str , str | フロート | 整数 | ブール | 辞書 | リスト | なし] ] 、 なし] 、即時: ブール = 間違い) ¶
特定のキーの構成変更をサブスクライブします。
- パラメータ:
key ( str ) – 登録する設定項目の識別子。部分的な指定も可能です(例:「general」または「general.autosave」)。
handler ( Handler ) – 設定項目が変更された際に呼び出される関数。この関数は、設定キーと更新後の値を含む辞書を1つの引数として受け取ります。キーが部分的な場合(例:“general”)、辞書には“general”で始まるすべてのキーが含まれます。
immediate ( bool ,オプション) – True の場合、ハンドラは設定項目の現在の値で直ちに呼び出され、最初の呼び出し時のみ同期的にブロックされます。False の場合、ハンドラは次回の設定変更時に呼び出されます。
- 昇給:
KeyError – キーが構成スキーマの一部ではない場合。
例:
# # Subscription example # from typhoon.api.configuration import configuration def handler(c): print("Configuration changed: ", c) configuration.subscribe("paths.user_lib_dir", handler) # Include /home/user/typhoon/libs and all subdirectories in the search path for user libraries directories = { "/home/user/typhoon/libs": True } configuration.set("paths.user_lib_dir", directories) # Clear the search path for user libraries directories = {} configuration.set("paths.user_lib_dir", directories) # Unsubscribe from changes configuration.unsubscribe("paths.user_lib_dir", handler)
出力
Configuration changed: {'paths.user_lib_dir': {'/home/user/typhoon/libs': True}} Configuration changed: {'paths.user_lib_dir': {}}
- 財産 subscriber_thread ¶
構成の変更をリッスンするサブスクライバー スレッドを取得します。
設定APIが最初にインポートされたときに、スレッドはデーモンとして起動されます。「join()」メソッドを使用してスレッドに参加し、終了を待つことができます。
- 戻り値:
購読者スレッド。
- 戻り値の型:
スレッド。スレッド
- 登録解除(キー: str 、ハンドラー: 呼び出し可能[ [ dict [ str , str | フロート | 整数 | ブール | 辞書 | リスト | なし] ] 、 なし] ) ¶
特定のキーの構成変更のサブスクライブを解除します。
注記
サブスクライブを解除するには、subscribe メソッドに渡されたものと同じキーとハンドラーを使用する必要があります。
- パラメータ:
key ( str ) – 登録解除する構成項目の識別子。
ハンドラー( Handler ) – 以前に構成項目にサブスクライブされた関数。