• No results found

QuickOPC Examples. Examples-QuickOPC.docx Page 1 of 19

N/A
N/A
Protected

Academic year: 2021

Share "QuickOPC Examples. Examples-QuickOPC.docx Page 1 of 19"

Copied!
19
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

Contents

QuickOPC Examples ... 1

Introduction ... 3

.NET Examples ... 4

Examples for OPC “Classic” (OPC-DA, OPC XML-DA and OPC-A&E) ... 4

Examples for OPC Unified Architecture (OPC-UA) ... 10

Reactive Programming Examples ... 11

COM Examples ... 13

JScript Examples (IE, WSH) ... 14

JScript Examples in IE ... 14

JScript Examples in WSH ... 14

Object Pascal Examples (Delphi) ... 14

Perl Examples ... 14 PHP Examples ... 15 PHP Console Examples ... 15 PHP Web Examples ... 16 Portable C++ Examples ... 16 Python Examples ... 16

REALbasic (Xojo) Examples ... 16

VBA Examples in Excel ... 17

VBScript Examples (ASP, IE, WSH) ... 17

VBScript Examples in ASP ... 17

VBScript Examples in IE ... 18

VBScript Examples in WSH ... 18

Visual Basic Examples (VB 6.0) ... 18

Visual C++ Examples ... 18

Visual FoxPro Examples... 19

(3)

 .NET Examples, and  COM Examples.

Depending on whether you develop OPC applications for Microsoft .NET, or are using Microsoft COM, please refer to the corresponding part.

Examples are provided for OPC “Classic” (COM-based) specifications, and OPC Unified Architecture (OPC UA).

The QuickOPC installation contains usage examples in various programming languages. The examples are being updated and enhanced more frequently than the base product, so if you like them, please check for newer builds of QuickOPC from time to time.

Note that the examples are different for QuickOPC.NET and QuickOPC-COM. The text is marked with corresponding .NET or COM icon further below.

(4)

.NET Examples

The examples are currently provided for Microsoft Visual Studio 2012. They can all be automatically converted to Microsoft Visual Studio 2013.

The examples are targeting Microsoft .NET Framework 4.5. In Visual Studio, it is possible to re-target the projects to newer framework versions (e.g. 4.5.1) by changing the appropriate setting in the properties of the project.

Visual Studio solutions with examples in Visual Basic, C#, F# and C++ are available from the Start menu.

Examples for OPC “Classic” (OPC-DA, OPC XML-DA and OPC-A&E)

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

ArrayValues: Shows how to write into an OPC item that is of array type, and read

the array value back.  

AutoRefreshWeb: Web application with a screen that refreshes itself periodically.  

BrowseAndReadValues: Console application that recursively browses and displays the nodes in the OPC address space, and attempts to read and display values of all OPC items it finds.

  BrowseBranchesWeb: Browses the branches in the OPC server (ASP.NET Web

application).  

BrowseServersWeb: Browses the available OPC servers (ASP.NET Web

application).  

ConsoleApplication1: The simplest console application. Reads and displays an OPC

item value.  

 *  ConsoleDataTypes: Shows how different data types can be processed, including

rare types and arrays of values.  

(5)

ConsoleEvents: Hooking up events and receiving OPC item changes in a console

application.  

ConsoleLiveMapping: Creates an object structure for a boiler, describes its mapping into OPC Data Access server using attributes, and then performs the live mapping. Boiler data is then read, written and/or subscribed to using plain .NET object access.

 

DataGridWebApplication: Demonstrates how easily can WebControls.GridView be

populated with data read from OPC Data Access server.   DocExamples: A collection of OPC “Classic” console-based examples that illustrate

the use of individual objects in the product, and their members. These are the same examples that appear in reference documentation, with an extra control routine that allows the use to choose an example to be performed.

 

EasyOpcNetDemo: This is a source of the Demo application for OPC “Classic” that ships with the QuickOPC.NET product. The application shows most product functions, including the browsing forms, OPC property access, and event-based subscriptions.

 

EasyOpcNetDemoXml: This is a source of the Demo application for OPC “Classic” (OPC XML-enabled) that ships with the QuickOPC.NET product. The application shows most product functions, including the browsing forms, OPC property access, and event-based subscriptions. The defaults are pre-filled for OPC XML-DA demo server, but the application is written in such a way that it can handle COM servers as well.

HmiScreen: Windows Forms application that shows how to use implement an HMI screen by storing OPC Item IDs in the Tag property of screen controls, and animate the controls by subscribing to all items at once. Also shows a possibility how to write to an OPC item form the screen.

(6)

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

IndustrialGadgetsDemo: Shows live binding of OPC Data Access items (from simulation OPC server) to controls from Industrial Gadgets .NET (a separate product, http://www.industrialgadgets.net/). The application has been developed with no manual coding - all functionality is achieved by configuring the

components in Visual Studio.

(7)

InstrumentationControlsDemo: Shows live binding of OPC Data Access items (from simulation OPC server) to controls from Instrumentation .NET (a separate product, http://www.instrumentationopc.com/). The binding is done with no manual coding - all functionality is achieved by configuring the components in Visual Studio.

 

ListView1: Shows how (Windows Forms) ListView items can be populated with

(8)

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

LiveBindingDemo: Shows live binding of OPC Data Access information (from simulation OPC server) to standard Windows Forms controls (Microsoft). All binding to OPC data is achieved with no manual coding, only by configuring the components in Visual Studio.

 

LiveBindingDemo2: Shows advanced live binding features. Among others, it demonstrates:

 Binding kinds: binding to local vs. UTC timestamp.

 Conversions: Use of LinearConverter, even bi-directionally.

 Animations: Moving a control around the form, depending on an OPC tag value.

 Cumulative: Adding incoming values to ListBox or ListView.

LogAsStringToSql: Logs OPC Data Access item changes into an SQL database, using

a subscription. Values of all data types are stored in a single NVARCHAR column.   LogAsUnionToSql: Logs OPC Data Access item changes into an SQL database, using

a subscription. Values of all data types are stored in separate columns.   LogToSqlEnhanced: Logs OPC Data Access item changes into an SQL database,

using a subscription. Item values and qualities are stored in their respective columns. Notifications with the same timestamp are merged into a single row.

 

MultipleItems: Show how to write into multiple OPC items using a single method

(9)

OvenControl: Monitors sensors in an industrial oven, indicates level alarms by changing colors, allows the user to change a setpoint, and logs the values into a CSV file.

 

QualityStrings: Shows how numerical OPC quality codes are converted to

displayable strings (Windows Forms application).  

SimpleLogToSql: Logs OPC Data Access item changes into an SQL database, using a

subscription. Values of all data types are stored in a single SQL_VARIANT column.   SubscribeFromXml: Loads list of OPC items from an XML file and subscribes to

them.  

SubscribeToMany: Demonstrates and measures performance with large number

of subscribed OPC items.  

SymbolFactoryDemo: Shows live binding of OPC Data Access items (from

simulation OPC server) to controls from Symbol Factory .NET (a separate product, http://www.symbolfactory.net/). All controls are bound to a single source item. The application has been developed with no manual coding - all functionality is achieved by configuring the components in Visual Studio.

 

ValueToMessageBox: Very simple Windows Forms application that reads and

displays an OPC item value in a message box after the user clicks on a button.   WcfClient1: Using a Web service provided by the WcfService1 project (under Web

folder), gets and displays a value of an OPC item.  

WcfService1: WcfService1: A simple Web service using WCF technology. Provides a GetData method to read a value of an OPC item. Use WcfClient1 project (under Console folder) to test this Web service.

(10)

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

WebApplication1: The simplest ASP.NET Web application for OPC “Classic”. Reads

and displays an OPC item value.  

WebService1: A simple Web service using ASMX technology. Provides

"Hello World" method to read a value of an OPC item.   WindowsFormsApplication1: The simplest Windows Forms application. Reads and

displays an OPC item value on a form. This is what you get if you follow the steps described in Quick Start for QuickOPC.NET.

  WpfApplication1: The simplest WPF application for OPC “Classic”. Reads and

displays an OPC item value. 

XmlEventLogger: Logs OPC Alarms and Events notifications into an XML file.  

XmlLogger: Logs OPC Data Access item changes into an XML file.  

WindowsService1: A Windows Service that subscribes to items from the

simulation server, and logs their changes into a file.  

Examples for OPC Unified Architecture (OPC-UA)

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

EasyOpcUADemo: This is a source of the Demo application for OPC-UA that ships with the QuickOPC-UA product. The application shows the most important product functions, including event-based subscriptions.

 

UADocExamples: A collection of OPC-UA console-based examples that illustrate the use of individual objects in the product, and their members. These are the same examples that appear in reference documentation, with an extra control routine that allows the use to choose an example to be performed.

(11)

UAConsoleLiveMapping: Creates an object structure for a boiler, describes its mapping into OPC Unified Architecture server using attributes, and then performs the live mapping. Boiler data is then read, written and/or subscribed to using plain .NET object access.

 

UALiveBindingDemo: Shows live binding of OPC Unified Architecture information (from sample OPC-UA server) to standard Windows Forms controls (Microsoft). All binding to OPC-UA data is achieved with no manual coding, only by configuring the components in Visual Studio.

 

UAWebApplication1: The simplest ASP.NET Web application for OPC-UA. Reads

and displays a value of a node in an OPC-UA server.  

UAWpfScreen: Shows how to update WPF controls with dynamic OPC-UA data.

Reactive Programming Examples

Examples for reactive programming model need an installation of Microsoft Reactive Extensions for proper building. These extensions are now provided by Microsoft in the form of NuGet packages.

The examples only contain references to the additional packages needed, and not the packages themselves. With the help of automatic NuGet Package Restore feature

(12)

(http://docs.nuget.org/docs/reference/package-restore), when enabled, the missing packages will automatically be downloaded and installed when you first build the project that references them. In Visual Studio 2013, this works “out of the box” (with default settings). Visual Studio 2012 ships with an earlier version of NuGet Package Manager which does not have the automatic package restore feature. If building the project in Visual Studio 2012 fails due to missing NuGet packages, follow the steps below:

1. In Visual Studio 2012, select command Tools -> Extensions and Updates.

2. On the left side of the "Extension and Updates" dialog, select Updates -> Visual Studio Gallery. A "NuGet Package Manager" entry will appear in the list of updates, with an "Update" button (on the right side of the dialog, the "New Version" will be indicated as 2.8 or later).

3. Press the Update button and go through the process. You will probably have to restart the Visual Studio in the end.

4. Rebuild the solution then, packages will be restored.

Vi sua l C# Vi sua l Basic Vi sua l F# Vi sua l C++

ReactiveDocExamples: A collection of console-based examples for reactive programming model that illustrate the use of individual objects in the product, and their members. These are the same examples that appear in reference documentation, with an extra control routine that allows the use to choose an example to be performed.

(13)

For OPC Data Access, the examples show:  reading and writing OPC items,  working with multiple items at once,  error handling,

 subscribing for item changes, and managing subscriptions,  getting property values,

 browsing for OPC servers, branches and leaves, and properties,  obtaining information about OPC servers,

 processing events,

 user interface for browsing,  and more.

For OPC Alarms and Events, the examples show:  subscribing to events,

 event filtering,  error handling,

 subscribing for item changes, and managing subscriptions,  browsing for OPC servers, areas and sources,

 querying for event categories, conditions and attributes,  obtaining information about OPC servers,

 processing events,

 acknowledging conditions,  refreshing event subscriptions,  and more.

For OPC Unified Architecture, the examples show:  reading and writing attributes of OPC nodes,  working with multiple nodes/attributes at once,  error handling,

 subscribing for monitored item changes, and managing subscriptions,  discovering OPC servers,

(14)

 browsing for OPC nodes,  processing events,

 user interface for browsing,  and more.

Following shortcuts are available from the Start menu:

JScript Examples (IE, WSH)

JScript Examples in IE

The examples here run inside Internet Explorer, i.e. directly on client. No Web server is required. The EasyOPC-DA component must be installed on the client side, and the OPC server(s) must be accessible locally or via DCOM from the computer where EasyOPC-DA component resides.

ReadAndDisplayValue_JScript.htm: Reads and displays an OPC item value.

JScript Examples in WSH

The examples here run in Windows Script Host (WSH), e.g. from Windows Command Prompt.

DocExamples folder: Contains all JScript examples for OPC Classic that are given in the

Reference documentation.

ReadAndDisplayValue.js: Reads and displays an OPC item value.

UADocExamples folder: Contains all JScript examples for OPC-UA that are given in the

Reference documentation.

Object Pascal Examples (Delphi)

The examples are currently provided for Delphi XE7. Although you may not be able to directly load the projects into earlier versions of Delphi, the actual source code is likely to work just well with no or minor modifications.

We have also tested the examples with Delphi XE8.

DocExamples: Contains all Delphi examples for OPC Classic that are given in the

Reference documentation.

Imports: Contains Delphi components created by importing QuickOPC type libraries.

ReadAndDisplayValue: The simplest form. Reads and displays an OPC item value.

UADocExamples: Contains all Delphi examples for OPC-UA that are given in the Reference

documentation.

Perl Examples

The examples were tested in ActivePerl v5.14.2.

ReadAndDisplayValue.pl: The simplest console application for OPC “Classic”. Reads and

(15)

displays the values.

PHP Examples

The examples were tested in PHP v5.6, under command-line interpreter and Internet Information Server (IIS). The examples use the COM extension for PHP. This extension can be enabled e.g. in following ways:

a) Add following to the php.ini file: extension=ext/php_com_dotnet.dll b) Use following in the php.ini file:

extension_dir = "ext"

extension=php_com_dotnet.dll

c) From IIS, under Internet Information Services (IIS) Manager, by PHP Manager: Use [PHP_COM_DOTNET]

extension=php_com_dotnet.dll

PHP Console Examples

In order to run the command-line examples, use PHP.EXE –f “filename

For easier troubleshooting of the command-line scripts, it is recommended that you enable the display_error option, e.g. in one of the following ways:

a) Use the following on the command line: -d display_errors

b) Add following to the php.ini file: display_errors = On

c) Copy the file php.ini-development over your php.ini file.

Console\DocExamples folder: Contains all command-line PHP examples for OPC Classic

that are given in the Reference documentation.

Console\UADocExamples folder: Contains all command-line PHP examples for OPC-UA

(16)

PHP Web Examples

In order to run the Web-based examples, you need to configure an IIS virtual directory that points to the physical directory where the examples are installed.

Examples in this folder are Web server scripts: the page, including OPC data, is generated on the server. The EasyOPC component must be installed on the server side, and the OPC server(s) must be accessible locally or remotely from the computer where EasyOPC component resides.

Web\ReadAndDisplayValue.php: The simplest Web application. Reads and displays an

OPC item value.

Web\ReadAndDisplayMultipleItems.php. Reads four values at once and displays their

contents. Aimed at showing how PHP can pass input and output arguments that are VARIANT arrays.

Web\UADocExamples folder: Contains all Web server PHP examples for OPC-UA that are

given in the Reference documentation.

Portable C++ Examples

Note: No longer shipped with the product. Contact us if you are interested in these examples.

These examples are designed to only use C++ language features and libraries that are portable across compilers.

VoleReadItemValue: Shows how to read value of a single OPC item, and display it, using

STLSoft and VOLE libraries.

VoleReadMultipleItems: Shows how to read 4 items at once, and display their values,

timestamps and qualities, using STLSoft and VOLE libraries.

Python Examples

The examples were tested in Python 3.4.2, with pywin32-219 extension (Build 219).

DocExamples folder: Contains all Python examples for OPC Classic that are given in the

Reference documentation.

UADocExamples folder: Contains all Python examples for OPC-UA that are given in the

Reference documentation.

REALbasic (Xojo) Examples

Note: We do not regularly update these examples with new versions. You may have to modify the code to use newer versions.

The example was originally created in REAL Studio 2010r5, and converted to REAL Studio 2011r1.1, and later versions.

(17)

VBA Examples in Excel

VBA stands for Visual Basic for Applications. The examples were developed and tested in Excel 2007 or 2010, but are saved in Excel 2003 format for compatibility.

ReadAndDisplayMultipleValues.xls: Reads multiple OPC Classic item values, and stores

them in cells of a worksheet.

ReadAndDisplayValue.xls: The simplest Excel VBA example for OPC “Classic”. Reads an

OPC item value and stores it in a cell of a worksheet.

ReadAndWriteValue.xls: Shows how to read or write an OPC Classic item value upon

press of a button.

SubscribeToMultipleItems.xls: Show how to subscribe to and unsubscribe from multiple

OPC Classic items, and how to continuously update the worksheet cells with their values.

UAReadAndDisplayValue.xls: The simplest Excel VBA example for OPC UA. Reads an OPC

UA value and stores it in a cell of a worksheet.

UAReadAndWriteValue.xls: Shows how to read or write an OPC UA value upon press of

a button.

UASubscribeToMultiple.xls: Shows how to subscribe to and unsubscribe from multiple

OPC UA monitored items, and how to continuously update the worksheet cells with their values.

UASubscribeToMultiple2.xls and UASubscribeToMultiple2.xls: As

UASubscribeToMultiple.xls, but allows sheet editing while being subscribed, using different approaches.

VBScript Examples (ASP, IE, WSH)

VBScript Examples in ASP

The examples run in Internet Information Server (IIS). In order to run the examples, you need to configure an IIS virtual directory that points to the physical directory where the examples are installed.

Examples in this folder are Web server scripts: the page, including OPC data, is generated on the server. The EasyOPC component must be installed on the server side, and the OPC server(s) must be accessible locally or remotely from the computer where EasyOPC component resides.

ReadAndDisplayValue_VBScript.asp: The simplest Web application. Reads and displays

(18)

VBScript Examples in IE

The examples here run inside Internet Explorer, i.e. directly on client. No Web server is required. The EasyOPC component must be installed on the client side, and the OPC server(s) must be accessible locally or remotely from the computer where EasyOPC component resides.

ReadAndDisplayValue_VBScript.htm: Reads and displays an OPC item value.

VBScript Examples in WSH

The examples here run in Windows Script Host (WSH), e.g. from Windows Command Prompt. It is possible to use CScript (console output) or WScript (window output) to run the examples. Some examples give longer output, and CScript is better for them as you do not have to confirm each “line” of output by pressing a button as in WScript.

DocExamples folder: Contains all VBScript examples for OPC Classic that are given in the

Reference documentation.

ReadAndDisplayValue.vbs: Reads and displays an OPC item value.

UADocExamples folder: Contains all VBScript examples for OPC-UA that are given in the

Reference documentation.

Visual Basic Examples (VB 6.0)

The examples are for Visual Basic 6.0.

ReadAndDisplayValue: The simplest form. Reads and displays an OPC item value. This is

what you get if you follow the steps described in Quick Start for QuickOPC-COM.

SubscribeMultipleItems: Subscribes to multiple OPC-DA items, and displays the incoming

changes in the list box.

UADocExamples: Contains all VB 6.0 examples for OPC-UA that are given in the Reference

documentation.

WriteMultipleItemValues: Writes different values to multiple OPC Data Access items at

once.

Visual C++ Examples

Examples are currently provided for Microsoft Visual Studio 2012, with a possible conversion to Microsoft Visual Studio 2013.

MFC\EasyOPCDADemo: This is a clone of the Demo application that ships with the

QuickOPC-COM product.

Win32\DumpAddressSpace: Dumps OPC server's address space recursively to the

console.

Win32\RandomReads: Reads random number of random items in a random fashion. This

(19)

Win32\WriteMultipleItemValues: Writes values into multiple items at once. Note that you can also use the “Portable C++ Examples” (see elsewhere in this document) in Visual C++.

Visual FoxPro Examples

Note: We do not regularly update these examples with new versions. You may have to modify the code to use newer version numbers.

The examples were tested in Visual FoxPro 9.0 with Service Pack 2.

ReadItemValue: Reads a value of an OPC Classic item and displays it in a message box.

UAReadItem: Reads a value of an OPC UA node and displays it in a message box.

Xbase++ Examples

Note: We do not regularly update these examples with new versions. You may have to modify the code to use newer version numbers.

The examples were tested with Xbase++ 1.90 SL1.

UAReadValue.prg: Reads a values of an OPC UA node displays it.

WriteAndReadValue.prg: Writes a value into an OPC Classic item, reads it back and

References

Related documents

나이, 수상 후 기간, 치료방법, 고정 기간 및 May Elbow Performance Index간의 상관관계 분석(Pearson corr- elation analysis)을 시행하였고, 위 여러 분석에서 의미

The auditory-oral modality does have a visual component: there were examples of both deaf and hearing people lipreading key terms within particular contexts; and deaf

As Grant Dalton, manager of the 2021 America’s Cup, announced, the AC75 rule allows a great deal of freedom in hull design, and the Italian Luna Rossa Design Team, Luna Rossa, has

This technique is called cross-sectional analysis. Cross-sectional analysis compares financial ratios of several companies from the same industry. Ratio

Схема функціонування обліково-аналітичного забезпечення управління основними засобами підприємства Джерело: розроблено автором

The main activity distinction used in the project was to defi ne activities as those that assigned costs directly to bank products and services or those that assigned costs to

the high efficiency of the cobalt plating process. The obtained Co thin films were visually uniform, shiny, and well attached. Pro- cess after 30 min - a) current density and

Conditions of marine protected areas (MPAs) in the Philippines observed through the MEAT database and a reality of evaluation system and the community based management in two