# Web-Modbus-Simulator **Repository Path**: air-el/Web-Modbus-Simulator ## Basic Information - **Project Name**: Web-Modbus-Simulator - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-09 - **Last Updated**: 2026-05-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ModBus Communication Simulator ## Introduction The ModBus Communication Simulator is a web-based application designed to simulate industrial automation networks using the ModBus protocol. It serves as both an educational tool for understanding industrial communication standards and a functional testbed for Human-Machine Interface (HMI) concepts. The application runs entirely in the browser, simulating a Master PLC and multiple Slave devices without the need for external hardware or backend servers. ## Project Overview This project addresses the need for accessible, safe, and interactive environments to learn and test ModBus concepts. Real industrial hardware is often expensive and dangerous to experiment with. This simulator provides a risk-free environment where users can verify register mappings, understand frame structures, and visualize how data changes in memory affect physical systems. Key capabilities include: - **Protocol Simulation**: Accurate generation and parsing of ModBus RTU frames, including CRC-16 error checking. - **Physics Simulation**: Dynamic behavior of industrial systems (HVAC, Conveyor, Tank) based on control inputs. - **Network Visualization**: Real-time monitoring of the Master-Slave architecture. - **Traffic Analysis**: Deep inspection of communication traffic, breaking down raw hex data into readable commands and responses. ## Simulated Environments The application simulates three distinct industrial systems, each representing a common use case for ModBus control. ### 1. HVAC System (Air Handling Unit) **Slave ID: 1** This module simulates a standard Air Handling Unit (AHU) used in building automation. It demonstrates the use of analog inputs for temperature sensors and PID-like control loops. - **Supply Air Temperature**: Read-only input register. Reacts to fan operation. - **Return Air Temperature**: Read-only input register. Represents the ambient load. - **Fan Speed Setpoint**: Holding register (0-100%). Controls the target speed of the supply fan. - **Fan Start/Stop**: Coil. Master switch for the system. - **Filter Clog Status**: Discrete input. Simulates a maintenance alarm. ### 2. Manufacturing Line (Conveyor System) **Slave ID: 2** This module simulates a discrete manufacturing process. It focuses on high-speed counting and binary sensor states, typical of packaging or assembly lines. - **Belt Speed**: Holding register. Controls the velocity of the conveyor. - **Item Counter**: Input register. Increments automatically based on belt speed and simulated sensor triggers. - **Motor Run Command**: Coil. Starts and stops the main drive motor. - **Photo Eye Sensor**: Discrete input. Momentarily activates when an item passes. - **Emergency Stop**: Discrete input. Indicates safety system status. ### 3. Process Control (Liquid Tank) **Slave ID: 3** This module simulates a continuous process control scenario involving fluid dynamics. It demonstrates the relationship between valve positioning, flow rates, and level monitoring. - **Tank Level**: Input register (0-100%). Represents the current fluid level. - **Inlet Valve Position**: Holding register (0-100%). Controls the rate of inflow. - **Outlet Pump Command**: Coil. Activates the discharge pump to drain the tank. - **High/Low Level Alarms**: Discrete inputs. Triggered when the level exceeds defined safety thresholds. ## Technical Architecture The application is built as a Single Page Application (SPA) using React. It leverages a centralized state management approach to decouple the simulation logic from the user interface. ### Core Components - **Simulation Engine**: A dedicated hook (`useSimulation`) runs a precise timing loop that updates the physics state of every slave device independently of the UI rendering cycle. - **ModBus Protocol Layer**: A library of pure functions handles the construction of ModBus Application Data Units (ADU). This includes Function Code handling (FC01, FC02, FC03, FC04, FC05, FC06) and Cyclical Redundancy Check (CRC) calculation. - **State Store**: `Zustand` is used to maintain the "Truth" of the network. This includes the memory maps (TypedArrays) for all devices and the log of all network traffic. ### Data Visualization - **Traffic Monitor**: A scrolling log that captures every request and response. It provides a dual view: the raw hexadecimal byte stream for low-level debugging and a parsed description for high-level understanding. - **Register Inspector**: A tabular view allowing users to inspect the values of specific memory addresses. It supports switching between different memory banks (Coils, Discrete Inputs, Input Registers, Holding Registers) and displays values in both decimal and hexadecimal formats. ## Installation and Usage ### Prerequisites Ensure you have Node.js installed on your system. This project requires Node.js version 20.19+ or 22.12+. ### Setup 1. Clone the repository to your local machine. 2. Navigate to the project directory. 3. Install the necessary dependencies: ```bash npm install ``` ### Development To start the local development server: ```bash npm run dev ``` The application will be accessible at `http://localhost:5173`. ### Production Build To create a production-ready build: ```bash npm run build ``` The output will be generated in the `dist` directory. ### Deployment This project is configured for deployment to GitHub Pages. To deploy the latest version: ```bash npm run deploy ``` ## License This project is open-source and available under the MIT License.