# serial-port-agent-java **Repository Path**: juxj/serial-port-agent-java ## Basic Information - **Project Name**: serial-port-agent-java - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-14 - **Last Updated**: 2026-01-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SerialPortAgent Usage Guide * Please ensure you have copied the example database to the specified directory, which must match the SQLite access path defined in the application.xml file. ### WebSocket Interface The application communicates via WebSocket at the endpoint: `/ws` ### 1. Input (Client -> Server) Send a JSON object to initiate tasks. **Example:** ```json { "taskId": "20260105003", "slotId": "10", "mock": true, "taskTypes": [ "OBTAIN_SENSOR_WEIGHTS", "OPEN_CABINET_DOORS", "MONITOR_TARGET_LOCKER", "MONITOR_ALL_LOCKERS", "MONITOR_WEIGHT_CHANGES" ] } ``` **Fields:** * `taskId`: Unique identifier for the task. * `slotId`: Identifier for the cabinet slot/node. * `taskTypes`: List of actions to perform. Available types: * `OBTAIN_SENSOR_WEIGHTS`: Get current weight readings immediately. * `OPEN_CABINET_DOORS`: Send command to open the door. * `MONITOR_DOOR_CLOSED`: Monitor and wait for the door to close. * `MONITOR_WEIGHT_CHANGES`: Monitor real-time weight changes. ### 2. Output (Server -> Client) The server sends JSON responses indicating events and data. **Structure:** ```json { "taskId": "20260105003", "sessionId": "h7s8-...", "status": 0, "event": "ON_WEIGHTS_CHANGED", "data": [ { "sensorId": 1, "val": 150.5 } ] } ``` **Fields:** * `taskId`: The task ID associated with the event. * `sessionId`: WebSocket session ID. * `status`: Status code (0 usually indicates success/info). * `event`: The type of event occurring. * `data`: Array of sensor results (optional, depends on event). Each item contains: * `sensorId`: ID of the sensor. * `val`: Sensor value (e.g., weight). **Event Types:** | Event Name | Description | Data Content | |-----------------------------|----------------------------------------|------------------------| | `ON_CONNECTED` | Connection established | `null` | | `ON_OBTAIN_WEIGHTS_SUCCESS` | Successfully retrieved initial weights | List of `SensorResult` | | `ON_OPEN_DOOR_SUCCESS` | Door opened successfully | `null` | | `ON_WEIGHTS_CHANGED` | Real-time weight update detected | List of `SensorResult` | | `ON_CLOSE_DOOR_SUCCESS` | Door closed detected | List of `SensorResult` | | `ON_OBTAIN_WEIGHTS_FAILED` | Failed to get weights | `null` | | `ON_OPEN_DOOR_FAILED` | Failed to open door | `null` | | `ON_CLOSE_DOOR_FAILED` | Door did not close within timeout | `null` | | `PORT_NOT_EXISTS` | Serial port configuration error | `null` | | `CABINET_NOT_EXISTS` | Slot ID not found in DB | `null` |