High-Performance Industrial IoT (IIoT) Monitoring System in C#

In the era of Industry 4.0, Industrial Internet of Things (IIoT) technology has gradually become the core of the manufacturing industry. By connecting devices to the network, interconnectivity between devices can be achieved, which improves production efficiency, optimizes production processes, and reduces production costs. To efficiently monitor and manage IIoT devices, developing a high-performance monitoring system has become crucial.

The core of the IIoT system is data collection, processing, and visualization. Traditional monitoring systems often suffer from low data collection efficiency, poor real-time performance, and insufficient scalability. To address these challenges, we designed and implemented a high-performance IIoT monitoring system. This system combines the efficient development capabilities of C# with the powerful features of the .NET framework, enabling real-time monitoring and data collection from various industrial devices.Multi-protocol support: Supports various industrial communication protocols such as Modbus-TCP, OPC-UA, MQTT, etc., allowing seamless integration with various industrial devices.High-performance data collection: Utilizes multithreading and asynchronous programming techniques to achieve efficient data collection and processing, ensuring real-time and accurate data.Data visualization: Provides rich data visualization features, including real-time curves, historical curves, and alarm information display, helping users quickly understand device status.Data storage and analysis: Uses high-performance databases (such as MySQL, SQL Server) to store collected data and provides data analysis functions, supporting the generation of production reports and trend analysis.User permission management: Supports user permission management, allowing different users to view and operate devices based on their permissions, ensuring system security.Alarm function: Supports real-time alarm functions, automatically sending alarm notifications when device parameters exceed set limits, reminding users to take timely action.Multi-client support: Supports simultaneous access from multiple clients, allowing management to monitor device status in real-time through computers, mobile phones, and other devices.The data collection module is the core of the system, responsible for collecting data from industrial devices. The system supports multiple communication protocols and can communicate with various devices. The main functions of the data collection module are as follows:Multi-protocol support: Supports Modbus-TCP, OPC-UA, MQTT, and other protocols.Multi-device connection: Supports simultaneous connections to multiple devices for efficient data collection.Real-time data updates: Utilizes multithreading and asynchronous programming techniques to ensure real-time data updates.The data processing module is responsible for processing and analyzing the collected data. The main functions of the data processing module are as follows:Data cleaning: Removes invalid and anomalous data to ensure data accuracy.Data storage: Stores collected data in databases, supporting MySQL, SQL Server, and other databases.Data query: Provides data query functions, supporting queries based on time, device, parameters, and other conditions.The data visualization module presents the collected data in an intuitive manner to users. The main functions of the data visualization module are as follows:Real-time curves: Displays the changing trends of device parameters in real-time.Historical curves: Shows the historical trends of device parameters.Alarm information: Displays alarm information in real-time, supporting alarm threshold settings.The user management module is responsible for managing user permissions to ensure system security. The main functions of the user management module are as follows:User permission settings: Supports setting user permissions, allowing different users to view and operate devices based on their permissions.User login: Supports user login functionality to ensure system security.User operation records: Records user operations for subsequent auditing and analysis.Below is a simple example of an IIoT monitoring system, demonstrating how to implement data collection and visualization.The following code shows how to collect data from a device using the Modbus-TCP protocol:

using System;using System.Net.Sockets;using System.Threading.Tasks;using Modbus.Device;public class ModbusDataCollector{    private TcpClient _tcpClient;    private IModbusMaster _modbusMaster;    public async Task InitializeModbusClient(string ipAddress, int port)    {        _tcpClient = new TcpClient(ipAddress, port);        _modbusMaster = ModbusIpMaster.CreateIp(_tcpClient);    }    public async Task<float> ReadFloatFromDevice(byte slaveId, ushort startAddress)    {        float value = _modbusMaster.ReadSingleRegister(slaveId, startAddress);        return value;    }}

The following code demonstrates how to store the collected data in a database:

using System;using System.Data.SqlClient;public class DataProcessor{    private string _connectionString;    public DataProcessor(string connectionString)    {        _connectionString = connectionString;    }    public void SaveDataToDatabase(string tableName, string columnName, float value)    {        using (SqlConnection connection = new SqlConnection(_connectionString))        {            string query = $"INSERT INTO {tableName} ({columnName}) VALUES ({value})";            SqlCommand command = new SqlCommand(query, connection);            connection.Open();            command.ExecuteNonQuery();        }    }}

The following code demonstrates how to display real-time data using WinForms:

using System;using System.Windows.Forms;using System.Threading.Tasks;public class DataVisualizer : Form{    private Label _label;    private Timer _timer;    private ModbusDataCollector _dataCollector;    private DataProcessor _dataProcessor;    public DataVisualizer()    {        _label = new Label        {            Text = "Waiting for data...",            Font = new Font("Arial", 16),            Location = new System.Drawing.Point(10, 10)        };        Controls.Add(_label);        _timer = new Timer { Interval = 1000 };        _timer.Tick += Timer_Tick;        _timer.Start();        _dataCollector = new ModbusDataCollector();        _dataProcessor = new DataProcessor("your_connection_string");    }    private async void Timer_Tick(object sender, EventArgs e)    {        await _dataCollector.InitializeModbusClient("192.168.1.100", 502);        float value = await _dataCollector.ReadFloatFromDevice(1, 0);        _dataProcessor.SaveDataToDatabase("DeviceData", "Temperature", value);        _label.Text = $"Current Temperature: {value}°C";    }    [STAThread]    public static void Main()    {        Application.EnableVisualStyles();        Application.SetCompatibleTextRenderingDefault(false);        Application.Run(new DataVisualizer());    }}

Through this article, you can quickly understand how to develop a high-performance IIoT monitoring system using C#. This system supports multiple communication protocols, efficient data collection and processing, and rich data visualization features, significantly improving production efficiency and device management levels.We hope this article is helpful to you! If there are any adjustments needed, please feel free to let me know.

Leave a Comment