In this article we are going to look at some of the advantages and disadvantages of developing your own custrom C# HMI versus going with a commercial-off-the-shelf system. One of the biggest advantages of using C# to develop your HMI is the ability to directly access your controller tag data directly. That means no middle-ware or OPC Server software will be needed to bridge the connections from your C# HMI application to your PLC hardware.
Instead, the Ingear driver class libraries make it extremely easy to directly connect your C# HMI application to virtually any PLC hardware on the market by means of Dynamic Linked Library files or DLL’s. Why develop a custom C# HMI instead of using a commercially available off-the-shelf solution you ask?
Keep reading and we’ll discuss some of the pro’s and con’s of opting for one solution over the other, and why sometimes it may make sense to develop your own custom C# HMI for a particular project!
C# HMI vs. Commercial Off-The-Shelf Solution
The question I’m often asked is why opt for a custom C# HMI versus a commercial-off-the-shelf type solution such as those produced by Rockwell or Siemens over some other “canned” type alternative. Well truthfully it almost always boils down to the cost! While these off-the-shelf solutions are robust and well tried systems, they can sometimes lack the flexibility needed for a given project, and they are comparatively expensive.
In some circumstance the cost alone can cripple your ability to be awarded a contract. Now I know I’m going to get some people that are going to say that all of these companies offer scalable solutions and I say to that, yes that’s true, but…
They would be nowhere near as cost effective as a custom C# HMI application that I could develop myself, especially when the system needs to do things like connect to a backend SQL Server database or send automatic notifications via email and SMS.
Curious how you can develop your own custom C# HMI? Get started in this first video in the series.
It’s capabilities such as these that really separate the canned “cookie cutter” type solutions from a custom C# HMI application that is designed from the ground up to provide these types of functions. The ability to take full control over your application through a high-level programming language such as C#, is by far a superior approach in circumstances such as these.
There are simply no constraints! The only constraint is your imagination and your ability to code a solution. I know you’re probably thinking, “but I’m not an expert coder”! Make no mistake, I don’t profess to be one either! That said, I should probably disclose that I do have a degree in Computer Science and Software Engineering.
Truth is, while the formal training I have gives me some additional insight into how to architect a software solution, make no mistake this is where Google can become your best friend. Websites like StackExchange and others are truly amazing and will help you to code just about anything you put your mind to!
C# HMI – Why A Direct Connection Over OPC?
The biggest advantage of a direct connection to a PLC endpoint versus going through an OPC Server is speed. You are effectively cutting out the “middleman” by going with a direct connection from your C# HMI application.
How does it work? Most driver manufacturers on the market, such as CimQuest Ingear that I eluded to earlier, can make short work of the complexities of connecting your C# HMI application to a programmable logic controller. The basic workflow goes like this:
- Add the class libraries to your new or existing C# HMI application.
- Import the necessary references into your class.
- Instantiate the objects and start making use of the pre-built methods included in the libraries.
If you watched the first video in the series, perhaps you’ll be interested in the second one here!
That’s basically all there is to it from a very high-level point of view. The complexities of building your own low-level drivers, or connecting to an OPC Server or an endpoint logic controller, is essentially gone. Provided you are comfortable in a C# object-oriented programming world this is a great alternative to expensive commercial-off-the-shelf solutions.
C# HMI – Adding The Required Ingear Class Library Files (.dll’s)
The process of accessing your PLC’s data directly from your C# application becomes extremely easy using Ingear’s driver packages. To add the required library files to your application follow these steps.
- Open an existing or create a new C# application in Visual Studio.
We are going to create a simple WinForms project titles “TestProject”.
- Navigate to your Solution Explorer and right-click the “References” directory and choose “Add Reference“.
We are interested in three Ingear reference files in particular:
- INGEAR NET.LOGIX X.0
- INGEAR NET.Interfaces X.0
- DeployLX Licensing Runtime vX.0
The “X” in the file names will be dependent on which version of Ingear you have installed.
- Now that the necessary references have been added to your project. You’re ready to start using the libraries to connect to one or more Logix controllers.
All that’s left to make use of these libraries is to it to your Class Namespace.
- Open an existing or create a new C# application in Visual Studio.
Below is a simple demo project using the Ingear drivers and Visual Studio 2017 Community Edition. It is the third video in our C# HMI playlist on our YouTube Channel .
C# HMI – Connecting To The Controller
If you watched the previous video, you’ll see that Ingear makes it extremely easy to get and running quickly with the variety of demo projects they include in there software. We did however glaze over some of the code behind necessary to actually implement it yourself.
In this section let’s carry on with our “TestProject” above to develop our own simple C# HMI and then implement the necessary code needed to connect to a ControlLogix controller. Let’s say the controller is at the following IP address: 172.16.10.10 with the following subnet: 255.255.255.0.
Let’s also create a two buttons, one to “Connect” and one to “Disconnect” from the PLC. Once connected we should get some kind of indication that we are connected to the controller.
Want to see how this works in action??? Check out this fourth video in our C# HMI playlist on our YouTube Channel. This “TestProject” application has two parts. This is first part that gets the main GUI (Graphical User Interface) components roughed in.
It should be clear that we are creating a very simple C# HMI application in this tutorial. We are making some assumptions too – we will assume that once we’re connected to the controller nothing will disconnect us other than by pressing the “Disconnect” button.
In reality and in a production environment, you need to consider every conceivable possibility that can arise and deploy the necessary logic. For checking the connection status, a Timer that periodically checks the connection status to the controller would be useful.
This is sometimes referred to as a “heartbeat” type check. This can be easily implemented by making use of the Timer() class and we are going to be implementing one in the next section when we attempt to read a tag continuously from the controller at some predefined sample rate.
C# HMI – Reading/Writing A Controller Tag
Reading and writing of tag data is snap using the Ingear class libraries. Simply instantiate a Controller object and then instantiate a Tag object. Once instantiated, simply make a call using one of the several overloaded read and write methods that are pre-built in the libraries.
In our “TestProject” example, I show you how to make use of the builtin Timer() class to continuously read the analog value of a tag residing the ControlLogix PLC. By “forking” off a new timer thread we can read the state of this or any tag at some sample rate that we define.
This is perfect for reading tag values that you want to tie to a trend or some other continuous type display that requires a consistent tag update rates.
See how it’s done right now…
C# HMI – Final Words…
I hope you have enjoyed this article, and I do encourage you to become a member of our growing community of professional engineers, technicians and technologists, Register Here!
Also, check out our YouTube Channel to see some great videos…and don’t forget to like and subscribe to our channel!
If you enjoyed this article be sure to check out some of these good reads too:
- How To Become A PLC Programmer
- Best Laptops For PLC Programming
- What Is Industrial Control Systems Security?
- How Much Does A PLC Programmer Make
- PLC Versus Microcontroller – What’s In Your Plant?
- Essential Tools Every PLC Programmer Needs
- Difference Between DCS And PLC
- How To Implement A ControlLogix PID Controller
Lastly, if you run into any problems in your day-to-day engineering activities please be sure to check out our Live and Interactive PLC Forum!
And if you so desire, assist other community members by replying or offering helpful information to the questions or challenges they may be facing right now!
Author: Fred (a.k.a. PLCGuru)
Hi, Fred here, I am the founding member and site moderator here at PLCGurus.NET. I’d like to be the first to welcome you to the site. I have over 20 years in the Industrial Automation and Control Systems field. Be sure to Register Today!