Modbus-Based-Alert System Desktop Application Using .Net-C#-WPF and Material Design
--
Hello All,
This blog is related to display real-time alert messages from instruments using Modbus protocol based system desktop application.
Use Case
So, one of our friend is working with the IOT and many robotics instruments which have in house systems. Now we need to develop the real-time alerts for different-different instruments and their respective channels.
Instruments => Win Service(Which has Modbus propriety DDL’s for communication) => Updates SQL Status table every 200 ms => WPF Deskptop Application will display Real-Time Status Data.
Win-Service is communicating with instruments using Modbus protocol, and updates near real time channel data into SQL tables.
Note:- Due to propriety DDL’s (Instrument Communication Service is not uploaded on Github)
I know its bit confusing for now, just to make things simpler, We have to develop an intuitive,responsive,real-time desktop application for better visual understandings of our instrument statuses.
To develop this kind of application, we decided to go with .Net framework as .Net is their preferred framework for an application development.
Requirements
- .Net Framework ≥ 4.6
- SQL Server 2014 Edition
- Visual Studio Community Edition
- Material Design
Steps
As I have mentioned above, we are using .Net framework and C# with the help of WPF technology to develop robust desktop application. Firstly we have our UI design ready just to make sure what we need to represent.
So, for the starters, we need to have start-end date and start-end time for filtering the range of data between it.
Once we are done with the design, we required an Timely based polling and alerts and that should be configurable.
For this we have used DispatcherTimer for timely based polling from SQL tables, and its frequency is derived from App.Config file as mentioned below.
<?xml version=”1.0" encoding=”utf-8" ?>
<configuration>
<startup>
<supportedRuntime version=”v4.0" sku=”.NETFramework,Version=v4.6" />
</startup>
<appSettings>
<add key=”connection_string” value=”server=(local);database={DB_Name};User ID={User_Name};Password={Password};”/>
<add key=”time_interval_in_days” value=”0"/>
<add key=”time_interval_in_hours” value=”0"/>
<add key=”time_interval_in_minutes” value=”0"/>
<add key=”time_interval_in_seconds” value=”0"/>
<add key=”time_interval_in_milliseconds” value=”500"/>
<add key=”Number_Of_Channels” value=”4"/>
</appSettings>
</configuration>
Once we are done with this, then we have very specific alert mechanism for better back tracking and visualization purpose. That we have covered with our in-memory operations and SQL tables polling data.
So, lets say whenever the [dbo].[Status] update its channel data value from an instrument we will decide what alert should be inserted into [dbo].[alarm] table.
After all the required business cases and conditional operations are performed and tested, We pushed the Button Click events to render our SQL data into DataGrid as follows,
After completing the required application development will push the build to their respective systems for their alerts and statuses. We have additionally used material design for developing the styling and looks for the application.
I hope this will guide you for developing and setting up your desktop application using .Net — C# and WPF technology.
Thank You!!!