ClientAce WPF Project Example



Similar documents
Kepware Technologies ClientAce: Creating a Simple Windows Form Application

Kepware Technologies OPC Quick Client Connectivity Guide

Visual Basic and OPC All versions of Kepware OPC Servers 10/23/03

Kepware Technologies KEPServerEX OPC Tunnel

Hands-On Lab. Client Workflow. Lab version: Last updated: 2/23/2011

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

ODBC Client Driver Help Kepware, Inc.

OPC Quick Client Users Guide. Version (OPC Interfaces)

Getting Started with STATISTICA Enterprise Programming

Alarms & Events Plug-In Help Kepware, Inc.

RedundancyMaster Help Kepware Technologies

CRM Setup Factory Installer V 3.0 Developers Guide

DataLogger Kepware, Inc.

OPC Unified Architecture - Connectivity Guide

Working with SQL Server Integration Services

Kepware Technologies KEPServerEX Client Connectivity Guide for GE's Proficy ifix

Visual Basic Programming. An Introduction

Xythos on Demand Quick Start Guide For Xythos Drive

How do I Configure, Enable, and Schedule Reports?

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual SPCHOL306 Using Silverlight with the Client Object Model VB

OnTime Web Services User Guide

ComponentOne. Windows for WPF

Visual Basic 2010 Essentials

EViews Database Extension Interface

A Step by Step Guide for Building an Ozeki VoIP SIP Softphone

Technical Note. Configuring an Omron PLC with Omron FINS Ethernet Driver. 1. Introduction

MMLIST Listserv User's Guide for ICORS.ORG

MS Enterprise Library 5.0 (Logging Application Block)

Kepware Technologies Optimizing KEPServerEX V5 Projects

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

Creating Database Tables in Microsoft SQL Server

Hands-On Lab. Building Applications in Silverlight 4 Module 8: Advanced OOB and MEF. Event Administrator Dashboard

Kepware Technologies Configuring Secured UA Communications Using ClientAce

Integration with Active Directory

webcrm API Getting Started

Revu Tutorial: Studio Projects

S/MIME on Good for Enterprise MS Online Certificate Status Protocol. Installation and Configuration Notes. Updated: October 08, 2014

CRYSTAL REPORTS IN VISUAL STUDIO.NET 2003

Products that are referred to in this document may be trademarks and/or registered trademarks of the respective owners.

Gravity Forms: Creating a Form

Kepware Technologies Remote OPC DA Quick Start Guide (DCOM)

Sage Abra Timesheet. Quick Start Guide

How to develop your own app

Offline Payment Methods

Recommended KEPServerEX Settings for groov

Lab 8: ASP.NET 2.0 Configuration API and Health Monitoring

BarTender s ActiveX Automation Interface. The World's Leading Software for Label, Barcode, RFID & Card Printing

Fax. Problems with Fax Delivery to Users CHAPTER

Allen Bradley ControlLogix Ethernet Driver for KEPServerEX

User Manual. Office: For fast & friendly community support join us at GetSatisfaction Visit our Support Page

CA Spectrum. Microsoft MOM and SCOM Integration Guide. Release 9.4

OrgPublisher for PeopleSoft HCM. Scheduler

Chapter 11 Managing Core Database Downloads

Use the below instructions to configure your wireless settings to connect to the secure wireless network using Microsoft Windows Vista/7.

Intel Retail Client Manager Audience Analytics

Professional Services. Plant Applications SDK Guidelines GE FANUC AUTOMATION. Prepared by. Donna Lui Professional Services

Recalling A Sent Message in Outlook 2010

Microsoft Virtual Labs. Building Windows Presentation Foundation Applications - C# - Part 1

Installation Guide Installing / Licensing / Unlocking Kepware Products

How To: Create a Crystal Report from ADO.NET Dataset using Visual Basic.NET

IBM BPM V8.5 Standard Consistent Document Managment

KETS Enterprise VPN. Client Installation and Configuration Guide. Version 2.3

ASP.NET Dynamic Data

Managing the OATS Certificate

EventSentry Overview. Part I Introduction 1 Part II Setting up SQL 2008 R2 Express 2. Part III Setting up IIS 9. Part IV Installing EventSentry 11

NETWRIX EVENT LOG MANAGER

Release Notes OPC-Server V3 Alarm Event for High Availability

AUTHENTICATION... 2 Step 1:Set up your LDAP server... 2 Step 2: Set up your username... 4 WRITEBACK REPORT... 8 Step 1: Table structures...

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

SQL Server Automated Administration

Project management integrated into Outlook

Guidelines for Installing SQL Server and Client (SQL Server Management Studio)

Architecture and Data Flow Overview. BlackBerry Enterprise Service Version: Quick Reference

Kepware Technologies KEPServerEX Client Connectivity Guide for Wonderware InTouch

MailEnable Connector for Microsoft Outlook

Title Release Notes PC SDK Date Dealt with by, telephone. Table of Content GENERAL Corrected Issues PDD...

RSA Event Source Configuration Guide. Microsoft Exchange Server

DEPLOYING A VISUAL BASIC.NET APPLICATION

R i o L i n x s u p p o r r i o l i n x. c o m 1 / 3 0 /

Database Automation using VBA

Appendix E. Captioning Manager system requirements. Installing the Captioning Manager

Best Practices for... "Setting up notifications for alerts"

Analytics Configuration Reference

InfoRouter LDAP Authentication Web Service documentation for inforouter Versions 7.5.x & 8.x

1. Create SQL Database in Visual Studio

Automated backup. of the LumaSoft Gas database

Aventail Connect Client with Smart Tunneling

How to create Event Filters directly from the Event Viewer

FioranoMQ 9. High Availability Guide

Installing GFI Network Server Monitor

RSA Security Analytics

How to connect to VUWiFi

Junk Settings. Options

VB.NET - WEB PROGRAMMING

PrivateWire Gateway Load Balancing and High Availability using Microsoft SQL Server Replication

Subscribe to RSS in Outlook Find RSS Feeds. Exchange Outlook 2007 How To s / RSS Feeds 1of 7

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

ICONICS Using the Azure Cloud Connector

Transcription:

Technical Note ClientAce WPF Project Example 1. Introduction Traditional Windows forms are being replaced by Windows Presentation Foundation 1 (WPF) forms. WPF forms are fundamentally different and designed using XAML code. Conventional controls designed for a Windows forms cannot be used in a WPF form without being hosted through an interop. The controls of the ClientAce group in the Visual Studio Toolbox are grayed out, but this document provides the steps to create a project with the ClientAce API to get data to a form. 1.1 Required Software The following are required to duplicate the process outlined in this document. Visual Studio 2008 SP1, 2010, 2012, and 2013 ClientAce V3.5 or 4.0.Net 3.5 SP1 or 4.x 2. Creating the WPF Project This is one simple example of how to create a WPF OPC with ClientAce; it is not intended to teach anyone how to write code. 2.1 Create the WPF Application 1. In VS 2008, create a new project of type: VB Windows WPF application. 2. By default, the project is created with a window and a grid panel. From the Common Controls, select a text box and place it in the grid panel. 2.2 Add the ClientAce References 3. Open the properties for the project by right-clicking on the project in the Solution Explorer. 1 The Windows Foundation Classes were introduced in VS 2008. www.kepware.com 1 2015 Kepware, Inc.

4. Click on the References tab. 5. Click Add to create a new.net reference. 6. In the Add Reference dialog box, scroll through the.net components to find the Kepware.ClientAce 3.5.0.3 component. 7. Select it and click OK. 2.3 Adding Code to the Project 8. To declare global variables at the form level, click on the xaml.vb tab. 9. Enter the declarations from EX1 below. ' Create an OPC DA Server Management object for each server to connect. ' This only connects to one server at a time, so create one and make it global ' Use the "WithEvents" modifier to receive data changed notifications for ' subscribed items. Dim WithEvents daservermgt As New Kepware.ClientAce.OpcDaClient.DaServerMgt ' When creating a subscription, the server provides a handle that ' must be used when referencing that subscription in the server. Dim activeclientsubscriptionhandle As Integer ' Where the server subscription handle refers to a subscription within the ' server, specify a client subscription handle to refer to that subscription. Dim activeserversubscriptionhandle As Integer EX 1: Project Declarations 10. Add code to initialize parameters for connecting to the server as shown in EX2 below. This code is executed when the form s loaded event is called (i.e. Private Sub Window1_Loaded()). ' The URL describes the type of server connection, the server program ID, ' and optional ClsID. Dim url As String = "opcda:///kepware.kepserverex.v5" ' The client handle is a unique identifier for each client connection. Dim clienthandle As Integer = 1 ' The connectinfo structure defines a number of connection parameters. Dim connectinfo As New Kepware.ClientAce.OpcDaClient.ConnectInfo ' The LocalID member specifies supported language options. Use "en" for English. connectinfo.localid = "en" ' The KeepAliveTime member is the time interval or rate, in ms, at which ' the connection to the server is checked by the API. connectinfo.keepalivetime = 1000 www.kepware.com 2 2015 Kepware, Inc.

' The RetryAfterConnectionError instructs the API to automatically ' attempt to reconnect after a connection loss. Set to True: connectinfo.retryafterconnectionerror = True ' The RetryInitialConnection instructs the API to continue to try to ' establish an initial connection. This is best if it is known that ' the server is really present and will likely allow a connection. ' If not, it creates a huge delay. Set to False: connectinfo.retryinitialconnection = False ' The connectfailed is set by the API. Check this value after the Connect ' method. Initialize to False in case Connect throws an exception before ' it can be set. Dim connectfailed As Boolean = False EX 2: Initialization of Connection Parameters 11. Once the connection parameters are initialized, the connection to the server can be attempted. 12. Enter the code in EX3 below into the form s loaded event function. Note: After the connection attempt, call the Subscribe_Data() function to request the item(s) to poll. Name this function as appropriate for the application or item. ' Call the Connect API method: Try daservermgt.connect(url, clienthandle, connectinfo, connectfailed) Call Subscribe_Data() Catch ex As Exception MsgBox("Handled Connect exception. Reason: " & ex.message) ' Verify the following code detects connection failed: connectfailed = True End Try ' Handle result: If connectfailed Then ' Tell user connection attempt failed: MsgBox("Connect failed") End If EX 3: Server Management Object Connection Method 13. Create the Subscribe_Data function by which to subscribe or request the items to be polled. To do this, create an array of object identifiers. This array www.kepware.com 3 2015 Kepware, Inc.

is passed to the server in the subscription method of the Server Management object created for connecting to the server. 14. Enter the code in EX4 to initialize the parameters of the item identifier and the subscription parameters. Dim clientsubscriptionhandle As Integer = 1 ' The active parameter is used to indicate to the server data is required ' for the subscribed items now or not. The active state can be changed ' later with a call to SubscriptionModify. Dim active As Boolean = True ' The updaterate parameter is used to indicate to the server the speed of ' data updates. This is a REQUESTED rate in milliseconds. The server may ' not be able to honor this request. Dim updaterate As Integer = 1000 ' The deadband parameter specifies the minimum deviation to be considered ' a change of value. It is expressed as a percentage (0-100). Dim deadband As Single = 0 ' The itemidentifiers array describes the items to enroll in this subscription. ' Each member of the ItemIdentifier structure is described below. ' Create only 1 for this example. Dim itemidentifiers(0) As Kepware.ClientAce.OpcDaClient.ItemIdentifier itemidentifiers(0) = New Kepware.ClientAce.OpcDaClient.ItemIdentifier ' The itemname parameter is the identity of the data object in the server. itemidentifiers(0).itemname = "Channel_1.Device_1.R0" ' The ClientHandle is used by the server to reference items in data ' changed events. This handle should uniquely identify each item. itemidentifiers(0).clienthandle = 0 ' Request a specific data type if desired. itemidentifiers(0).datatype = Nothing ' The revisedupdaterate parameter is the actual update rate of the server. Dim revisedupdaterate As Integer EX 4: Server Data Subscription Initialization www.kepware.com 4 2015 Kepware, Inc.

15. Add the code for the Subscription as shown in EX5 below. ' Call the Subscribe API method: Try daservermgt.subscribe(clientsubscriptionhandle, active, updaterate, revisedupdaterate, deadband, itemidentifiers, activeserversubscriptionhandle) ' Save the active client subscription handle for use in ' DataChanged events: activeclientsubscriptionhandle = clientsubscriptionhandle ' Check item result ID: If itemidentifiers(0).resultid.succeeded = False Then ' Show a message box if an item could not be added to subscription. MsgBox("Failed to add item" & itemidentifiers(0).itemname & " to subscription") End If Catch ex As Exception MsgBox("Handled Subscribe exception. Reason: " & ex.message) End Try EX 5: Subscription Method 16. To handle the Data Change event sent to this application every time the value of the subscribed item changes in the sever, enter the code in EX6. Private Sub daservermgt_datachanged(byval clientsubscription As Integer, ByVal allqualitiesgood As Boolean, ByVal noerrors As Boolean, ByVal itemvalues() As Kepware.ClientAce.OpcDaClient.ItemValueCallback) Handles daservermgt.datachanged ' Loop over values returned. Do not assume that data for all items enrolled ' in a subscription are included in every data changed event. ' The number of values likely varies each time. Dim itemvalue As Kepware.ClientAce.OpcDaClient.ItemValueCallback For Each itemvalue In itemvalues ' Get the item handle. Use the Items Client handle to update the specific ' control associated. For larger projects, create a control array and ' associate the client handle with the control array index. Select Case itemvalue.clienthandle ' Update value control (could be NULL if quality goes bad): Case 0 If IsNothing(itemValue.Value) Then TextBox1.Text = "Unknown" Else TextBox1.Text = itemvalue.value.tostring() www.kepware.com 5 2015 Kepware, Inc.

End If End Select Next End Sub EX 6: Data Change Event 17. It is necessary to handle closing the form and disconnecting from the server, which are accomplished with two separate functions, as seen in EX 7 below. The first function is a Window or Form Closed event triggered when the form closes normally. This uses a function called DisconnectOPCServer(), which tests the connection to the server and, in connected, executes the Disconnect method of the Server Management Object. Private Sub Window1_Closed(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded 'On unload of the form, call the disconnection process for the server. DisconnectOPCServer() End Sub Private Sub DisconnectOPCServer() ' Call Disconnect API method: Try If daservermgt.isconnected Then daservermgt.disconnect() End If Catch ex As Exception MsgBox("Handled Disconnect exception. Reason: " & ex.message) End Try End Sub EX 7: Form Unload and Server Disconnection 18. Run the project and verify data from the server is displayed in the WPF form. 3. Summary Completing the steps described above should provide a foundation for creating a WPF OPC project of greater complexity. www.kepware.com 6 2015 Kepware, Inc.