3.8 KiB
3.8 KiB
| title | description | keywords | ||||||
|---|---|---|---|---|---|---|---|---|
| RS485 Component | Documentation for the RS485 component that provides Modbus RTU communication over RS-485 serial protocol |
|
RS485
Path: src/RS485.cpp
Revision History: Initial documentation
The RS485 component provides Modbus RTU master functionality for industrial communications over the RS-485 serial protocol. It enables communication with various industrial devices that support the Modbus RTU protocol and acts as an interface between these devices and the internal system components.
REQUIREMENTS
Hardware
- RS-485 transceiver (typically integrated on ESP32 industrial boards)
- Properly wired RS-485 network (A/B/GND connections)
Software
- ModbusClientRTU library for Modbus RTU communication
- ModbusRTU and ModbusTypes dependencies
- Configuration settings in config-modbus.h
FEATURES
- Modbus RTU master implementation
- Integration with Modbus TCP for remote access to RTU devices
- Device management for multiple slave devices
- Register read/write operations
- Register change notifications
- Periodic device polling
DEPENDENCIES
- Component - Base class for all components
- ModbusTCP - For Modbus TCP to RTU bridging
- ModbusBlockView - For register organization and access
- ArduinoLog - For logging capabilities
- ModbusClientRTU - For Modbus RTU communication
graph TD
RS485 --> Component
RS485 --> ModbusRTU
RS485 --> ModbusTCP
RS485 --> ModbusBlockView
RS485 --> Manager
BEHAVIOUR
The RS485 component initializes during setup and then periodically polls connected devices in its loop function. It also handles Modbus TCP requests by translating them to RTU operations and manages the communication with the RTU slave devices.
stateDiagram-v2
[*] --> Initialization
Initialization --> Ready
Ready --> ProcessingTcpRequests: TCP Request Received
Ready --> PollingDevices: Timer Triggered
ProcessingTcpRequests --> Ready: Response Sent
PollingDevices --> Ready: Polling Complete
Ready --> HandleRegisterChange: Register Changed
HandleRegisterChange --> Ready
TODOS
PERFORMANCE
- Optimize polling frequency based on device response times
- Implement more efficient register caching to reduce network traffic
- Consider batch operations for multiple registers to improve throughput
SECURITY
- Implement proper error handling for malformed Modbus packets
- Consider adding CRC validation for extra reliability
- Implement timeout handling for unresponsive devices
COMPLIANCE
- Ensure compliance with Modbus RTU specification
- Validate against industrial standards for RS-485 communication
- Test with different vendor implementations for compatibility
RECOMMENDATIONS
- Use proper RS-485 termination resistors on the physical network
- Configure appropriate timeouts based on network complexity and device count
- Implement error recovery mechanisms for robust operation
- Use shielded twisted pair cables for RS-485 connections in noisy environments
EXAMPLE
Below is an example of how the RS485 component might be constructed and mounted in an application:
#ifdef ENABLE_RS485
rs485 = new RS485(
this // owner
);
if (rs485)
{
components.push_back(rs485);
Log.infoln(F("RS485 initialized."));
}
else
{
Log.errorln(F("RS485 initialization failed."));
}
#endif