transsecs_host:startup_trigger_host_recipesend_ui
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| transsecs_host:startup_trigger_host_recipesend_ui [2025/08/19 12:57] – amyw | transsecs_host:startup_trigger_host_recipesend_ui [2025/08/21 11:49] (current) – amyw | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| It performs two key tasks: | It performs two key tasks: | ||
| - | * Waits for the TransSECS Host controller to become available. | + | * Waits for the **TransSECS Host controller** to become available. |
| - | * Sets up a **Connection Status Listener** that, once communications are established, | + | * Sets up a **Connection Status Listener** that, once communications are established, |
| - | The script includes a **Swing-based popup window** for PPID and file selection. | + | The script includes a **Swing-based popup window** for entering a PPID and choosing a file. |
| ===== Key Features ===== | ===== Key Features ===== | ||
| - | * **Swing UI**: Lets the user enter a PPID and select a file to send as a recipe. | + | * **Swing UI**: Lets the user enter a **PPID** and select a **file** to send as a recipe. |
| * **Background host discovery**: | * **Background host discovery**: | ||
| - | - In deployment: host is usually ready immediately. | + | - In **SIM mode**: waits until the user toggles |
| - | - In SIM mode: the thread | + | - In **deployment mode**: usually connects quickly, but can be delayed if: |
| - | * **Safe listener setup**: Adds a short delay before registering the listener, preventing | + | * The tool is still initializing. |
| - | * **Null-safe message bean lookup**: Ensures `RecipeSend` bean is available before sending. | + | |
| - | * **Robust error handling**: | + | |
| + | | ||
| + | * **Connection-safe | ||
| + | * **Robust logging**: Provides clear feedback during wait, connection, timeout, and UI launch. | ||
| + | * **Thread-safe UI handling**: | ||
| ===== How It Works ===== | ===== How It Works ===== | ||
| + | At startup, a **background thread** is launched: | ||
| + | * Repeatedly checks `TransSecsController.getSingleController()` until it returns a valid controller, or until a **5-second timeout** is reached. | ||
| + | * Logs progress every **10 polling cycles (~500 ms)** while waiting. | ||
| + | * Stops waiting and logs an error message after the timeout if no host is detected. | ||
| - | At startup: a background thread begins waiting | + | Once the host is found: |
| + | * Waits **1 second** | ||
| + | * Registers a **Connection Status Listener**. | ||
| - | If in SIM mode: the loop continues until the user toggles to LIVE. | + | When the host reports **status = 0 (Connected)**: |
| + | * Launches | ||
| + | * Collects | ||
| + | * Sends an **S7F3 RecipeSend** message with the selected PPID and file contents. | ||
| - | If in deployment: | + | If the host never becomes available: |
| + | * Logs a timeout message. | ||
| + | * Skips UI initialization to avoid errors. | ||
| - | After discovery: waits 1 second for project initialization, | + | {{:transsecs_host:screenshot_2025-08-18_103804.png?400|}} |
| - | + | ||
| - | On connection: when the host reports connection status 0 (operational), | + | |
| - | + | ||
| - | Pops up the Swing UI. | + | |
| - | + | ||
| - | Collects PPID and file bytes. | + | |
| - | + | ||
| - | Sends an S7F3 RecipeSend message with the user’s inputs. | + | |
| ===== Benefits ===== | ===== Benefits ===== | ||
| + | * **Resilient in all environments**: | ||
| + | * **Lightweight and efficient**: | ||
| + | * **Safe initialization**: | ||
| + | * **User-friendly**: | ||
| + | - Clear log messages for troubleshooting. | ||
| + | - Safe and simple UI for recipe selection and transmission. | ||
| - | Works seamlessly in both SIM and deployment modes. | ||
| - | |||
| - | No CPU churn (500 ms polling). | ||
| - | |||
| - | No premature null errors on deployment. | ||
| - | User-friendly: | ||
| ===== Full Code ===== | ===== Full Code ===== | ||
| Line 192: | Line 199: | ||
| } | } | ||
| - | // --- Background host discovery | + | // --- Startup Trigger Main Loop --- |
| - | var r = new java.lang.Runnable() { | + | var r = new java.lang.Runnable() { // |
| run: function() { | run: function() { | ||
| var host = null; | var host = null; | ||
| var count = 0; | var count = 0; | ||
| - | + | | |
| - | // Wait until host is ready (deployment: | + | Thread.sleep(50); |
| - | | + | count++; |
| - | Thread.sleep(500); | + | |
| - | count++; | + | |
| host = TransSecsController.getSingleController(); | host = TransSecsController.getSingleController(); | ||
| - | + | | |
| - | | + | DataSource.logMessage(" |
| - | DataSource.logMessage(" | + | } |
| + | | ||
| + | DataSource.logMessage(" | ||
| + | break; | ||
| } | } | ||
| } | } | ||
| - | DataSource.logMessage(" | + | |
| - | + | | |
| - | // Delay: give project time to finish initialization | + | Thread.sleep(1000); |
| - | | + | host.addConnectionStatusListener(new ConnectionStatusListener() { // |
| - | + | connectionStatusChanged: | |
| - | // Connection listener | + | if (connectionStatus == 0) { // Connected |
| - | | + | |
| - | connectionStatusChanged: | + | |
| - | | + | }); |
| - | | + | |
| - | try { | + | |
| - | | + | |
| - | var msg = h.getMessageBean(" | + | |
| - | + | ||
| - | if (msg == null) { | + | |
| - | DataSource.logMessage(" | + | |
| - | | + | |
| - | } | + | |
| - | + | ||
| - | var selection = requestParams().get(); | + | |
| - | | + | |
| - | msg.setPPBodyFormat(new SecsFormat10(selection.get(" | + | |
| - | msg.sendMessage(); | + | |
| - | + | ||
| - | | + | |
| - | print(" | + | |
| } | } | ||
| } | } | ||
| - | | + | }); |
| - | | + | DataSource.logMessage(" |
| - | + | } else { | |
| - | | + | DataSource.logMessage(" |
| + | } | ||
| } | } | ||
| }; | }; | ||
| - | // Start in a background thread (avoids blocking project load) | + | new Thread(r).start(); |
| - | new Thread(r).start(); | + | |
| </ | </ | ||
transsecs_host/startup_trigger_host_recipesend_ui.1755622628.txt.gz · Last modified: by amyw
