Click here to Skip to main content
15,887,214 members
Articles / Desktop Programming / Windows Forms

Using .NET with Wonderware

Rate me:
Please Sign up or sign in to vote.
3.75/5 (9 votes)
24 Aug 2010GPL33 min read 220.3K   3.1K   22   113
This article will show how to read and write to Wonderware from VB

Introduction

This article is born out of several projects I have had extending Wonderware by calling VB.NET applications. Wonderware is an HMI/SCADA front end made by Wonderware. Wonderware is fairly easy to use, although I am not a huge fan of it, I don't have much against it either. It is just a common program in the SCADA industry. This will show you how to write applications that communicate with Wonderware. I usually have to do this to extend the functionality or to fill in the gaps between what Wonderware can do and what the customer requires.

Background

I write HMI/SCADA software mostly for the oil and gas industry. In this industry, many companies use a product called Wonderware. I have also come across it in waste water plants as well as food processing plants (Cheese Cake to be exact!!!). At most of these facilities, they need a function in the Wonderware application, but Wonderware can't do it. This will give you another option. I have seen other options using DDE. However, DDE is no longer supported so we will be using the Wonderware Toolkit. This code will contact the Wonderware running on the same computer.

Using the Code

Using the code will be pretty easy. We will create 2 VB files that are required to call the Wonderware toolkit (ptacc.dll and wwheap.dll). After that, all that will be left is your application to call the read/write functions of the Wonderare Toolkit. These files were created based on information from Wonderware West and my experience with using the 2 DLLs.

To do this, you need to copy the Intouch.vb and the Ptacc.vb into your project as well as reference the wwheap.dll and the ptacc.dll. Doing this will allow you to communicate with the Wonderware database.

The Ptacc.vb file will contain everything necessary to communicate with Wonderware. However it isn't very pretty, so that is why we use the Intouch.vb file. It is just the basic level.

The Intouch.vb file is going to contain our commands for reading and writing values with the Wonderware database. This will allow you to read/write Strings, Floats, Booleans(Discrete), and Integers.

So if you want to read the first 132 characters from the string variable with the tag SBuffer, then you call IntouchToolkit.ReadString("SBuffer", 132) or you can use ReadInteger, ReadDiscrete and ReadFloat for the respective types. Also, the similar is true but the functions is WriteString, WriteFloat, WriteInteger and WriteDiscrete. The Tag name is always a string.

Now that we got the basics out of the way, you need to call this from your application. This is pretty simple. In your main VB file, whether it is Windows Form or console application doesn't matter. I have not tried this with a web form, but I would like to hear your experience with it if you do try it.

VB.NET
Public Class Form1
    Dim accid As Integer
    Dim hPt As Integer
    Dim SB As String
    Dim IntouchToolkit As Intouch

    '------------------------------------------------
    'Form1_Load
    '------------------------------------------------
    Private Sub Form1_Load(ByVal sender As System.Object, _
		ByVal e As System.EventArgs) Handles MyBase.Load

        IntouchToolkit = New Intouch(0, 0)
        SB = IntouchToolkit.ReadString("SBuffer", 132)	'SBuffer is the Tag 
						'I want to read in Wonderware

    End Sub
    
    Private Sub btnOpen_Click(ByVal sender As System.Object, _
		ByVal e As System.EventArgs) Handles btnOpen.Click
        IntouchToolkit = New Intouch(0, 0)
        IntouchToolkit.WriteDiscrete("SomeTag", 1)
    End Sub
End Class

These are the write functions available to call:

  • VB.NET
    IntouchToolkit.WriteString("SomeTag", "FooBar")

    This is to write a string value.

  • VB.NET
    IntouchToolkit.WriteFloat("SomeTag", 3.1415)

    This is to write a float value.

  • VB.NET
    IntouchToolkit.WriteInteger("SomeTag", 10)

    This is to write an integer value.

  • VB.NET
    IntouchToolkit.WriteDiscrete("SomeTag", 1)

    This is to write a boolean value.

These are the read functions available to call:

  • VB.NET
    IntouchToolkit.ReadString("SomeTag")

    This is to read a string value.

  • VB.NET
    IntouchToolkit.ReadFloat("SomeTag")

    This is to read a float value.

  • VB.NET
    IntouchToolkit.ReadInteger("SomeTag")

    This is to read a integer value.

  • VB.NET
    IntouchToolkit.ReadDiscrete("SomeTag")

    This is to read a boolean value.

*NOTE: Replace "SomeTag" with the tagname you want to read or write from.

Points of Interest

As you can see, this is pretty simple. I have used this code several times on Wonderware 7.1 to 10.0. I usually put in some code that starts my application when an icon in Wonderware is clicked. This is the reason why I get the x and y values from Wonderware. It took me about a week with Wonderware support to find this information, and they do not support the Wonderware toolkit, but it has been reliable for me.

History

Well, this is the initial version.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer Chemex Modular
United States United States
I am a Developer and Electrical Engineer. I work mostly on HMI and SCADA systems in the Houston area. I have worked mostly around oil and gas industry. I have also spent time in Indiana working on automotive assembly plants.

Comments and Discussions

 
GeneralRe: Other side of the fence Pin
earl the dead cat2-Sep-10 6:27
earl the dead cat2-Sep-10 6:27 
GeneralRe: Other side of the fence [modified] Pin
knockNrod5-Sep-10 11:10
knockNrod5-Sep-10 11:10 
GeneralRe: Other side of the fence Pin
earl the dead cat5-Sep-10 15:37
earl the dead cat5-Sep-10 15:37 
GeneralRe: Other side of the fence Pin
knockNrod6-Sep-10 18:55
knockNrod6-Sep-10 18:55 
GeneralRe: Other side of the fence Pin
earl the dead cat7-Sep-10 2:28
earl the dead cat7-Sep-10 2:28 
GeneralRe: Other side of the fence Pin
knockNrod6-Sep-10 19:08
knockNrod6-Sep-10 19:08 
GeneralRe: My vote of 4 Pin
earl the dead cat2-Sep-10 6:37
earl the dead cat2-Sep-10 6:37 
GeneralRe: My vote of 4 [modified] Pin
knockNrod5-Sep-10 11:06
knockNrod5-Sep-10 11:06 
Interop is a pain. There are probably more people who understand quantum mechanics than InterOps. Microsoft's InterOp Forms Toolkit does add a LOT more stuff than you need to make it work in most cases, but the fact that it builds these into the project for you does ease the burden quite a bit. And there are a fair number of folks willing to help you cure or avoid the warts interop causes.

We're not trying to deal with all 150 different versions. Sorry, didn't mean to imply that. Most of our customers that are requesting that our Level 2 HMI be integrated with their Level 1 HMI are running either Wonderware InTouch or WinCC. We did have one using Factory Link, but we already know the problems there preclude a one-size-fits-all, so we made the strategic decision to not even try and address that in our design. Even in that scenario, though, packaging our HMI as a set of stand-alone controls does make it easier to pull out pieces. These pieces, then, can be embedded into a VB6 application, where a true ActiveX control can be created, which does work in Factory Link.

PLC access is a bit different. Not all of them have drivers supported by OPC, but I suspect that all the ones that work with WonderWare and WinCC do. Because WinCC and WonderWare both include an OPC server as an in-built part of the package, you can at least avoid writing in-house drivers for all the PLCs.

In this case, the drivers are provided by Wonderware and WinCC, but you've got to be willing to write controls that make use of OPC calls. If you've got to access a different manufacture of PLC for your controls than what you intended to support by Wonderware, you will have to purchase another driver from Wonderware to use by its OPC server for accessing that additional PLC. I understand WinCC is a little better about licensing in this area, but I haven't had to do this, so I'm unsure. In fact, I haven't tried to even call into the OPC servers of either product, and one thing I've learned in my own project is that you can't take anything for granted -- if you haven't tested it, it probably won't work. (Public methods are and raised events appear to be dead in WinCC. I'm awaiting confirmation on the latter from Seimens. That last one may be impossible to work around since raising an event causes an out of memory error even if you try to handle the event between controls, although our hope was to program WinCC scripts against those events. If you're interested, I encourage you to also keep an eye out for my article.)

In short, you can't avoid eating the bitter pill in all cases, but you can at least design the coating around the pill so that it's easier to swallow. Of course, it's always our preference to do everything as a native Windows Forms application for exactly the reasons you mention. (I don't think we have the expertise or resources to create our own SCADA system, so we won't be leaving OPC anytime soon.) However, our customer's often have a deep commitment to a particular SCADA and insist we embed various amounts of our HMI within their system. I can't avoid it, but I can sure sweeten the pill.

Without darkness, there are no dreams.
-Karla Kuban



-- Modified Monday, September 6, 2010 3:35 AM
GeneralRe: My vote of 4 [modified] Pin
ralimin7-Nov-10 23:19
ralimin7-Nov-10 23:19 
General[My vote of 2] I keep wondering Pin
Luc Pattyn23-Aug-10 10:27
sitebuilderLuc Pattyn23-Aug-10 10:27 
GeneralRe: [My vote of 2] I keep wondering Pin
earl the dead cat23-Aug-10 11:42
earl the dead cat23-Aug-10 11:42 
GeneralRe: [My vote of 2] I keep wondering Pin
Luc Pattyn23-Aug-10 11:45
sitebuilderLuc Pattyn23-Aug-10 11:45 
GeneralRe: [My vote of 2] I keep wondering Pin
knockNrod24-Aug-10 6:58
knockNrod24-Aug-10 6:58 
AnswerRe: [My vote of 2] I keep wondering Pin
Luc Pattyn24-Aug-10 7:12
sitebuilderLuc Pattyn24-Aug-10 7:12 
GeneralRe: [My vote of 2] I keep wondering Pin
knockNrod25-Aug-10 2:39
knockNrod25-Aug-10 2:39 
GeneralRe: [My vote of 2] I keep wondering Pin
earl the dead cat25-Aug-10 2:57
earl the dead cat25-Aug-10 2:57 
GeneralRe: [My vote of 2] I keep wondering Pin
earl the dead cat24-Aug-10 7:30
earl the dead cat24-Aug-10 7:30 
GeneralRe: [My vote of 2] I keep wondering Pin
knockNrod25-Aug-10 3:03
knockNrod25-Aug-10 3:03 
GeneralRe: [My vote of 2] I keep wondering Pin
earl the dead cat25-Aug-10 3:26
earl the dead cat25-Aug-10 3:26 
GeneralRe: [My vote of 2] I keep wondering Pin
earl the dead cat24-Aug-10 7:33
earl the dead cat24-Aug-10 7:33 
GeneralRe: [My vote of 2] I keep wondering Pin
knockNrod25-Aug-10 3:04
knockNrod25-Aug-10 3:04 
GeneralJust a giant code dump... Pin
Dave Kreskowiak18-Aug-10 1:59
mveDave Kreskowiak18-Aug-10 1:59 
GeneralRe: Just a giant code dump... Pin
earl the dead cat18-Aug-10 4:34
earl the dead cat18-Aug-10 4:34 
GeneralRe: Just a giant code dump... Pin
Dave Kreskowiak18-Aug-10 12:28
mveDave Kreskowiak18-Aug-10 12:28 
GeneralRe: Just a giant code dump... Pin
earl the dead cat18-Aug-10 13:09
earl the dead cat18-Aug-10 13:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.