This document outlines the implementation plan for snap7-gui, broken into incremental phases.
Goal: Establish project structure and define core data models.
- Create project structure with
src/directory layout - Set up
requirements.txtwith dependencies:python-snap7>=1.3PySide6>=6.6
- Create
main.pyentry point - Implement
src/models/variable.py:DataTypeenum with BOOL, BYTE, INT, DINT, REALVariabledataclass with name, data_type, db_number, offset, bit_offset, value
- Implement
src/plc/data_types.py:- Type size constants
- Reader/writer function mappings for snap7.util functions
Runnable project skeleton with data models that can be imported and tested.
Goal: Implement reliable PLC communication with connection management.
- Implement
src/plc/client.py:PLCClientclass wrapping snap7.client.Clientconnect(ip, rack, slot)method with error handlingdisconnect()methodis_connectedpropertyread_variables(variables: list[Variable])method- Group variables by DB number
- Calculate byte ranges for optimized reads
- Parse values using data_types mappings
write_variable(variable: Variable, value)method
- Add reconnection logic with configurable retry attempts
- Implement error translation (snap7 error codes to user-friendly messages)
PLC client that can connect to a real or simulated PLC and read/write variables.
Goal: Implement background polling with thread-safe GUI updates.
- Implement
src/plc/poller.py:PLCPoller(QThread)class- Constructor accepts PLCClient, variable list, poll interval
data_updated = Signal(dict)emitting {var_name: value}connection_lost = Signal(str)emitting error messageerror_occurred = Signal(str)for non-fatal errorsrun()method with polling loopstop()method for graceful shutdownrequest_write(variable, value)method using thread-safe queue
- Handle write requests within polling loop
- Implement connection state tracking
Background thread that polls PLC and emits signals for GUI consumption.
Goal: Persist variable configurations to JSON files.
- Implement
src/storage/config_store.py:save_config(variables: list[Variable], filepath: str)load_config(filepath: str) -> list[Variable]- JSON schema for variable serialization
- Add default config file location (user's app data directory)
- Handle file errors gracefully (missing file, invalid JSON, schema errors)
Configuration persistence that survives application restarts.
Goal: Create the main application window with navigation.
- Implement
src/app.py:create_app()function setting up QApplication- Application-wide styling
- Implement
src/ui/main_window.py:MainWindow(QMainWindow)classQStackedWidgetfor screen switching- Navigation between config and monitor screens
- Status bar for connection state
- Update
main.pyto launch the GUI
Running application window that can switch between placeholder screens.
Goal: Implement the variable configuration interface.
- Implement
src/ui/config_screen.py:ConfigScreen(QWidget)classQTableWidgetwith columns: Name, Type, DB, Offset, Bit, Actions- "Add Variable" button opening inline row or dialog
- Edit button per row
- Delete button per row with confirmation
- Type dropdown (BOOL, BYTE, INT, DINT, REAL)
- Bit offset column enabled only when Type is BOOL
- Input validation (numeric fields, required fields)
- Add "Save" and "Load" buttons connected to config_store
- Add "Go to Monitor" navigation button
- Emit signal when configuration changes
Fully functional configuration screen where users can define PLC variables.
Goal: Implement the live monitoring interface.
- Implement
src/ui/monitor_screen.py:MonitorScreen(QWidget)class- Connection panel: IP input, Rack spinbox, Slot spinbox, Connect button
- Connection status indicator (colored dot + text)
QTableWidgetwith columns: Name, Type, DB, Offset, Value, Action- Value column updates from
data_updatedsignal - Format values appropriately (BOOL as ON/OFF, REAL with decimals)
- Connect/disconnect button logic
- Add "Configuration" navigation button
- Poll interval setting (optional)
Monitor screen that displays live PLC values (read-only).
Goal: Enable writing values to PLC variables.
- Implement
src/ui/dialogs/write_value.py:WriteValueDialog(QDialog)for all data types- BOOL: ON/OFF buttons for clear intent (no ambiguity with live value)
- Numeric types: Input field with validation based on data type
- OK/Cancel buttons for numeric types
- Returns entered value or None if cancelled
- Add action column widgets to monitor screen:
- All types: Write button opening WriteValueDialog
- Consistent UI across all data types
- Connect write actions to poller's write queue
- Show write success/failure feedback in diagnostics console
Complete read/write functionality for all supported data types.
Goal: Improve user experience and handle edge cases.
- Add comprehensive error messages for common issues:
- PLC unreachable
- PUT/GET not enabled
- Invalid DB or offset
- Connection timeout
- Add loading indicators during connection
- Disable write controls when disconnected
- Add keyboard shortcuts (Ctrl+S to save config, etc.)
- Remember last used IP address
- Add window title with connection status
- Handle application close (stop poller, disconnect cleanly)
Production-ready application with good UX.
Goal: Ensure reliability and provide user documentation.
- Add unit tests for:
- Variable model serialization
- Data type conversions
- Config store save/load
- Add integration tests with snap7 server simulator
- Update README with:
- Installation instructions
- Usage guide with screenshots
- PLC configuration requirements
- Add inline code documentation where non-obvious
Tested, documented application ready for distribution.
Goal: Add a standard menu bar with file operations and CSV import/export.
- Add menu bar to
MainWindow:- File menu:
- New (Ctrl+N) - Clear current configuration
- Open... (Ctrl+O) - Load configuration from JSON
- Save (Ctrl+S) - Save current configuration
- Save As... (Ctrl+Shift+S) - Save to new file
- Import CSV... - Import variables from CSV
- Export CSV... - Export variables to CSV
- Quit (Ctrl+Q) - Exit application
- View menu:
- Configuration (Ctrl+1) - Show config screen
- Monitor (Ctrl+2) - Show monitor screen
- Diagnostics Panel (Ctrl+D) - Toggle diagnostics
- Help menu:
- About - Show application info
- File menu:
- Implement CSV import functionality:
- Parse CSV with columns: Name, Type, DB, Offset, Bit
- Validate data types and values
- Handle duplicate variable names
- Show import summary/errors
- Implement CSV export functionality:
- Export current variables to CSV format
- Include all variable properties
- Allow user to choose file location
Application with standard menu bar and CSV import/export capability for easier variable configuration.
Goal: Enhance diagnostics console to show detailed PLC communication messages.
Status: Complete
- ✅ Add verbose logging option to diagnostics panel:
- Toggle button or checkbox for verbose mode
- When enabled, show raw S7 protocol details
- ✅ Log detailed read operations:
- DB number, start offset, byte count
- Raw bytes received (hex format)
- Parsed values for each variable
- Timing information (request/response duration)
- ✅ Log detailed write operations:
- Variable name, address, value being written
- Raw bytes sent (hex format)
- Write confirmation/error response
- Log connection details (partial - basic connection logging):
- TSAP parameters
- PDU size negotiation
- Connection timing
- ✅ Add log filtering options:
- Filter by log level (DEBUG, INFO, WARNING, ERROR)
- Filter by operation type (via log level)
- ✅ Add log export:
- Export diagnostics log to text file
- Include timestamps and all details
DiagnosticsPanel: Enhanced with verbose mode toggle, log level filter dropdown, and export buttonPLCClient: AddedReadResultandWriteResultdataclasses with debug infoPLCClient._read_db_variables_verbose(): Captures timing and raw bytes for read operationsPLCClient._write_bool_verbose()and_write_value_verbose(): Capture timing and raw bytes for writesPLCPoller: Addeddebug_logsignal andset_verbose()method to enable verbose logging
Comprehensive diagnostics console for debugging PLC communication issues.
Goal: Add advanced features to enhance the application's capabilities.
-
Multiple connections: Connect to multiple PLCs simultaneously
- Add connection manager to handle multiple PLC clients
- Tab-based UI for switching between connections
- Independent polling for each connection
-
Variable groups: Organize variables into named groups/tabs
- Add group/folder support in configuration
- Collapsible groups in monitor view
- Group-based filtering and operations
-
Data logging: Record values over time to CSV
- Configurable logging interval
- Select which variables to log
- Start/stop logging controls
- Automatic file rotation
-
Alarm configuration: Set thresholds and alert on value changes
- Define high/low limits per variable
- Visual indicators for alarm states
- Alarm history log
- Optional sound notifications
-
Import from TIA Portal: Parse exported symbol tables
- Support TIA Portal CSV/XML exports
- Map DB symbols to variables automatically
- Handle nested data structures
-
Trend charts: Visualize value changes over time
- Real-time line charts for numeric variables
- Configurable time window
- Multiple variables on same chart
- Export chart as image
Feature-rich PLC monitoring application with advanced capabilities for industrial use.