Netflux is a high-performance Soft-Realtime UDP communication protocol for bridging PLCs, PCs, and other automation devices. It is designed to work where standard proprietary protocols (like Profinet, EtherCAT, or S7-Communication) are too expensive or inflexible, but raw UDP is too unreliable.
It is proven to achieve 1ms cycle times between CODESYS PLCs and robustly handles cross-platform communication between:
- CODESYS V3
- Siemens S7-1500
- Python (PC/Linux/Mac)
- High Speed: Optimized for ≤ 2ms data exchange cycles.
- Reliable: Implementing a custom "Sequence Number + Feedback" handshake to guarantee packet delivery and order.
- Cross-Platform: Seamlessly talk between different brands of PLCs and PC software.
- Zero Cost: No licenses, no royalties. Open Source (MIT License).
- Simple: Designed to be easier to implement than a standard TCP socket connection.
| Platform | Directory | Description |
|---|---|---|
| CODESYS V3 | 📂 /Codesys_V3 |
Original implementation. Includes Function Blocks, statistics tuning, and examples. |
| Siemens S7 | 📂 /Siemens_S7_1500 |
SCL implementation for S7-1500 (TIA Portal). |
| Python | 📂 /Python |
Complete Python 3 implementation for testing, logging, or PC-based control. |
| Documents | 📂 /Diagrams |
Protocol design diagrams and documentation assets. |
The protocol allows two devices to "handshake" over UDP without the overhead of TCP.
- Send: Device A sends a packet with a
Sequence Number(0-255). - Acknowledge: Device B receives it and echoes that number back as a
Feedback Sequence Numberin its own next packet. - Verify: Device A sees the feedback and knows the link is healthy.
If a packet is lost, the sequence numbers won't match, and the built-in Watchdog or Statistics Block will flag an error immediately.
The CODESYS V3 implementation uses cds-tex-sync to export source code from .project files into plain text .st files for version control.
Key Benefits:
- Git-Friendly: Track changes in human-readable Structured Text files instead of binary XML.
- Code Review: Enable proper diff/merge workflows for PLC code.
- CI/CD Ready: Integrate with automated testing and deployment pipelines.
Export Structure:
Codesys_V3/
├── _config.json # cds-tex-sync configuration
├── _metadata.csv # Object metadata (GUIDs, types)
├── src/ # Exported .st source files
│ ├── MAIN_NETFLUX.st
│ └── NETFLUX/ # Library modules
└── xml/ # Original CODESYS XML exports
Workflow:
- Make changes in CODESYS IDE
- Run
cds-tex-syncexport script - Review changes in
src/directory - Commit to Git with meaningful messages
Note: The export files in
Codesys_V3/src/are automatically synchronized with the CODESYS project. Always export before committing changes.
We welcome contributions! Please see CONTRIBUTING.md for details on how to submit pull requests or report issues.
This project is licensed under the MIT License - see the LICENSE file for details.
The Codesys V3 implementation has been significantly refactored to a Unified Socket Architecture (fbNetflux_Socket) to improve reliability and maintainability.
- Unified Function Block: Handles both sending and receiving in a single non-blocking state machine.
- Robust Connection Handling:
- Cold Start Detection: Automatically resets socket handles on program download/restart.
- Fast Port Release: Uses
SO_REUSEADDRoption to allow immediate reconnection, eliminating the need for controller restarts stuck inTIME_WAIT. - Auto-Recovery: Built-in error recovery mechanism retries connections automatically.
- Performance Tuning:
- Optimized
SysSocketcalls (tuned signatures for speed). - Buffer management optimization.
- Optimized
- Detailed Statistics:
tPartnerTxPeriod: Measures the actual reception interval from the partner.tOwnRealTxPeriod: Measures the PLC's actual transmission interval.tInstantRTT: Estimated Round Trip Time.uiInstantRxSkipped: Counters for lost/skipped packets.
The Main program (MAIN_NETFLUX) uses an explicit execution order for better control:
// 1. Process Receive Logic (inside FB body)
_fbNetflux_Socket(...);
// 2. Execute Application Logic using received data
// ...
// 3. Explicitly Send Data (at end of cycle)
_fbNetflux_Socket.send();
// 4. Update Statistics (optional)
_fbNetflux_Socket.Statistics();