60
OPC CLIENT FOR ODBC USER’S MANUAL DOCUMENT VERSION 2.1 FEBRUARY, 2002

OPC Client for ODBC User Manual

Embed Size (px)

Citation preview

Page 1: OPC Client for ODBC User Manual

OPC CLIENT FOR ODBC

USER’S MANUAL

DOCUMENT VERSION 2.1

FEBRUARY, 2002

Page 2: OPC Client for ODBC User Manual

Matrikon OPC Client for ODBC - User's Manual

For additional information on this manual, this OPC server, or Matrikon, please contact:

Address: Matrikon 1800, 10405 Jasper Avenue Edmonton, Alberta, Canada T5J 3N4

Phone: 780-448-1010 Fax: 780-448-9191

Web: http://www.matrikon.com

Sales: [email protected]

Support: [email protected]

CONFIDENTIAL

The information contained here in is confidential and proprietary to Matrikon. It may not be disclosed or transferred, directly or indirectly, to any third party without the explicit written permission of Matrikon.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, translated, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of Matrikon.

© Copyright 2002 Matrikon Inc.

ii

Page 3: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

TABLE OF CONTENTS

1. INTRODUCTION .........................................................................................................................1 1.1 SYSTEM REQUIREMENTS.....................................................................................................1 1.2 SYSTEM ARCHITECTURE.....................................................................................................2 1.3 OPC OVERVIEW.................................................................................................................3 1.4 DOCUMENT CONVENTIONS ............................................................................................3 1.5 ERROR HANDLING.............................................................................................................4

2. USER INTERFACE ........................................................................................................................5 2.1 MAIN WINDOW..................................................................................................................5

2.1.1 SAVING THE CONFIGURATION.................................................................................6 2.1.2 LOADING THE CONFIGURATION .............................................................................7 2.1.3 CREATING A NEW CONFIGURATION ......................................................................7

2.2 CONNECTING TO AN OPC SERVER ................................................................................8 2.2.1 ADDING AN OPC SERVER CONNECTION ..............................................................9 2.2.2 VIEWING AN OPC SERVER’S PROPERTIES .............................................................10 2.2.3 DELETING AN OPC SERVER CONNECTION ..........................................................10 2.2.4 ADDING A GROUP ..................................................................................................11 2.2.5 VIEWING AND EDITING GROUP PROPERTIES .......................................................13 2.2.6 ACTIVATING AND DISABLING GROUPS ................................................................13 2.2.7 DELETING A GROUP.................................................................................................14 2.2.8 ADDING AN ITEM .....................................................................................................14 2.2.9 DELETING AN ITEM ...................................................................................................16

2.3 ODBC DATABASE CONNECTIONS ................................................................................17 2.3.1 ADDING A DATABASE CONNECTION...................................................................19 2.3.2 DELETING A DATABASE CONNECTION .................................................................20 2.3.3 ADDING A QUERY....................................................................................................20 2.3.4 DELETING A QUERY..................................................................................................22 2.3.5 ADDING A TRIGGERED WRITE ................................................................................22 2.3.6 DELETING A TRIGGERED WRITE ..............................................................................25

2.4 SESSION SETTINGS ............................................................................................................26 2.4.1 GENERAL ...................................................................................................................26 2.4.2 LOGGING..................................................................................................................26

2.5 USING CUSTOM QUERIES................................................................................................28 2.5.1 THE CUSTOM QUERY FORM ....................................................................................28

2.5.1.1 EXECUTING SIMPLE QUERIES ...........................................................................28 2.5.1.2 USING AN OPC ITEM IN A QUERY...................................................................30 2.5.1.3 CREATING AN INSERT QUERY USING AN OPC ITEM ....................................32 2.5.1.4 WRITE TO OPC ITEMS USING A SELECT STATEMENT......................................33 2.5.1.5 ADDING THE QUERY.........................................................................................34 2.5.1.6 EDITING/DELETING AN EXISTING QUERY .......................................................34

iii

Page 4: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5.2 QUERY OPTIONS PANEL ..........................................................................................35 2.5.2.1 QUERY EXECUTION OPTIONS ..........................................................................35 2.5.2.2 OPC ITEM DELIMITERS.......................................................................................35 2.5.2.3 QUERY TEXT OPTIONS.......................................................................................35 2.5.2.4 OPC RETURN ITEMS...........................................................................................35 2.5.2.5 QUOTATION MARKS .........................................................................................35

2.6 USING STORED PROCEDURES ........................................................................................36 2.6.1 ADDING A STORED PROCEDURE...........................................................................36 2.6.2 VIEWING/EDITING STORED PROCEDURES ............................................................37

3. WALKTHROUGH OF STORING PROCESS VALUES IN AN ODBC DATABASE ....................39 3.1 CONNECT TO THE MATRIKON OPC SERVER FOR SIMULATION .................................39

3.1.1 MATRIKON OPC SERVER FOR SIMULATION ..........................................................39 3.2 BROWSE FOR SOME POINTS...........................................................................................40

3.2.1 MATRIKON OPC SERVER FOR SIMULATION ..........................................................40 3.3 CONFIGURE THE ODBC DATABASE...............................................................................42

3.3.1 MICROSOFT ACCESS CONFIGURATION...............................................................42 3.3.2 MICROSOFT SQL CONFIGURATION.......................................................................45

3.4 ADD THE DATABASE ........................................................................................................47 3.5 STORE PROCESS DATA IN DATABASE............................................................................49

3.5.1 STORING DATA IN MICROSOFT ACCESS ..............................................................49 3.5.1.1 UPDATE QUERY .................................................................................................50 3.5.1.2 INSERT QUERY....................................................................................................52

3.5.2 STORING DATA IN MICROSOFT SQL ......................................................................53 3.5.2.1 UPDATE QUERY .................................................................................................54 3.5.2.2 INSERT QUERY....................................................................................................55

3.5.3 STORING DATA IN MICROSOFT EXCEL ..................................................................56

iv

Page 5: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

1. INTRODUCTION The Matrikon OPC Client for ODBC enables any ODBC-compliant database to exchange process data with an OPC Server. This application uses standard SQL queries. There are two main uses for the OPC Client for ODBC:

• Archive process values from an OPC server to an ODBC database. An ODBC database can become a miniature process historian, and this application can place the data in permanent storage. Any trending or analysis tool can then be used to retrieve the data from the ODBC database.

• Populate an OPC Server with data from an ODBC database. For example, gas chromatograph data, stored in a database, can be written into an OPC server by way of this application.

Other features include:

• Support for ODBC compliant databases such as Microsoft Access, Microsoft SQL, Oracle, Sybase, etc.

• Communication between multiple ODBC databases with multiple OPC servers, including concurrent sessions with the same server

• SQL-based query engine that allows both reading and writing

• Real-time editor that allows query changes even while the application is running

• Point-and-click interface supporting drag and drop operation

• Support for transaction-based updates

• Runs as a Windows NT Service

• Supports stored procedures

• XML configuration file

1.1 SYSTEM REQUIREMENTS

The OPC Client for ODBC has the following minimum runtime system requirements:

• Pentium 100MHz processor

• 32MB of RAM

Microsoft Windows NT Workstation or Server 4.0 (Service Pack 3) or Windows 2000

1

Page 6: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

1.2 SYSTEM ARCHITECTURE

The OPC Client for ODBC has the system architecture as shown below in <figure 1> below. The diagram illustrates how the Matrikon OPC Client for ODBC can connect to any OPC server and archive the values. Users can also use the database to write values (such as setpoints, batch recipes, etc).

Figure 1: System Architecture diagram

2

Page 7: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

1.3 OPC OVERVIEW

OLE for Process Control (OPC) was designed to bridge Windows based applications and process control hardware and software applications. It is an open standard that permits a consistent method of accessing field data from plant floor devices. This method remains the same regardless of the type and source of data.

OPC servers provide a method for many different software packages to access data from a process control device, such as a PLC or DCS. Traditionally, any time a package needed to access data from a device, a custom interface or driver had to be written. The purpose of OPC is to define a common interface that is written once and then reused by any business, SCADA, HMI, or custom software package.

Device A Device CDevice B

OPCServer

OPCServer

OPCServer

ClientApplication

ClientApplication

ClientApplication

OPC Interface

Once an OPC server is written for a particular device, it can be reused by any application that is able to act as an OPC client. OPC servers use Microsoft’s OLE technology (also known as the Component Object Model, or COM) to communicate with clients. COM technology permits a standard for real-time information exchange between software applications and process hardware to be defined.

1.4 DOCUMENT CONVENTIONS

This document uses the following conventions:

Convention Example

File Names in Italics. ODBCOPCCLIENT.exe

Main Menu Commands in bold italics. Select Exit from the File menu.

Context Menu Commands in bold Select Properties.

Sub-Menu Commands in bold italics, following an arrow from another Menu command.

Select Determine New → Database.

Button Description between angled brackets. Click the <<New Database>> button.

3

Page 8: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

1.5 ERROR HANDLING

The OPC Client for ODBC incorporates extensive error checking using the Matrikon standard log library. This library provides varying levels of error and information logging. Log files created by the library are self-maintaining and require no user interaction.

Instant and informative feedback is also available when initially constructing the SQL queries between an ODBC-compliant database and an OPC-compliant server. This feature identifies spelling and/or syntactical errors in the SQL queries.

4

Page 9: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2. USER INTERFACE The OPC Client for ODBC can be started through the Windows Start menu (Start → Programs → Matrikon OPC → OPC ODBC Client → ODBC OPC Client), or by double-clicking the executable file, ODBCOPCCLIENT.exe. This will run the COM component in a command-line window on your desktop. In addition, an icon for the COM component will appear in the system tray. When the system tray icon is right-clicked, a menu will appear with the options Configure and Shutdown. Selecting Shutdown will close the ODBC OPC Client, and selecting Configure will load the GUI for configuring the client.

2.1 MAIN WINDOW When the OPC Client for ODBC is started, it restores the option dialog settings of the last session from the Windows Registry. For the first time that the client is run, the default option dialog settings are used and there are no connections made. There is an option setting that allows the client to load the configuration of connections from an XML file on start-up. The main window title contains the name of the program and the name of the configuration file (XML file) that the current connections have been loaded from, or to which they have been saved.

Figure 2 - OPC Client Main Window

5

Page 10: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Once started, the OPC Client for ODBC displays the main window, through which all settings and configurations are accessed. The main window is shown in Figure 2 above.

The main window consists of three panes of information. The top-left pane contains information related to OPC server connections. This includes a list of the available OPC servers, a list of the OPC servers to which the client is connected, and properties for a specific OPC server, OPC group, or OPC item.

The top-right pane contains information related to ODBC database connections. This includes an interface for adding a database connection, a list of the ODBC databases that the client is connected to, and an interface for adding a triggered write.

The bottom pane contains information related to SQL queries. This includes the current query for a specified OPC item tag, or an interface for defining the query of an OPC item tag.

There is also a menu bar at the top of the main window, which includes the File, View, Session, and Help menus. Below the menu is a toolbar, as shown in Figure 3 - The Toolbar below. Its buttons, from left to right, are “New Configuration”, “Open Configuration”, “Save Configuration”, “Add OPC server”, “Delete OPC server”, “Add Group”, “Delete Group”, “Add Item”, “Delete Item”, and “Delete Database”.

Figure 3 - The Toolbar

To close the ODBC OPC client configuration window, select Exit from the File menu or close the main window. To shut down the OPC Client for ODBC from the configuration window, select ShutDown from the File menu. All the settings in the Options dialog will be saved. If the ‘Save current configuration on shutdown’ option were selected, then all connection information will be saved. The Client will then perform an orderly shutdown, releasing any allocated resources before terminating.

2.1.1 SAVING THE CONFIGURATION The OPC Client for ODBC enables the user to save the current configuration of connections in an XML file. This can be done one of two ways:

1. Select the File menu and select Save As (or Save (Ctrl-S) if the current configuration file is the one desired). Enter the name and path of the XML file.

2. Press the “Save Configuration” button, highlighted in Figure 4 below.

Figure 4 - The "Save Configuration" Button

If there already is a current configuration file, then this button will save the configuration to that file, otherwise a dialog will appear asking the user to specify a name and path.

6

Page 11: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.1.2 LOADING THE CONFIGURATION The OPC Client for ODBC allows the user to load a configuration of connections from an XML file. This can be done one of two ways:

1. Select the File menu and select Open (Ctrl-O).

2. Press the “Load Configuration” button, highlighted in Figure 5 below.

Figure 5 - The "Load Configuration" Button

Enter the name and path of the XML file that you want to load the configuration from.

2.1.3 CREATING A NEW CONFIGURATION A new configuration can be created one of two ways:

1. Select the File menu and select New Session (Ctrl-N).

2. Press the “New Configuration” button, highlighted in Figure 6 below.

Figure 6 - The "New Configuration" Button

A dialog will appear asking if you want to save your current configuration. Press <<Yes>> to save your current configuration and create a new one, press <<No>> to overwrite your current configuration with a new one, or press <<Cancel>> to return to your current configuration.

7

Page 12: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2 CONNECTING TO AN OPC SERVER The left pane of the main window contains the OPC server connection information. There are two tabs that can be selected to view in this pane: “Available OPC Servers” and “Connected Servers”. When the client is run, the top-left pane shows the “Available OPC Servers” tab display by default. The “Available OPC Servers” tab displays the OPC Servers to which the client can connect, either on the local computer or through the network. This is shown in tree format. Figure 7 shows an example of this.

Figure 7 - Connected Servers

The “Connected Servers” tab displays the OPC servers that the client is currently connected, in tree format. Each OPC server can have any number of groups defined, and each group can have any combination of available OPC items in it. An example of this is shown in Figure 8 below.

Figure 8 - Available OPC Servers

8

Page 13: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.1 ADDING AN OPC SERVER CONNECTION There are two ways that you can connect to an OPC server:

1. Select the “Available OPC Servers” tab display. Navigate through the tree structure of connected computers and double-click the OPC server you wish to add.

2. Press the “Add OPC server” button in the toolbar, highlighted in Figure 9 below.

Figure 9 – The “Add OPC server” Button

3. After pressing the OPC button, a dialog will appear like in Figure 10 below.

Figure 10 - The Add OPC Server Dialog

4. At the bottom of the dialog, select the computer that contains the OPC server to which a connection is required. By default, the “Local Host” option is selected (the Local Host is the computer you are currently using). To connect to a computer over the network, select the second option and choose a Machine Name from the drop-down menu or select the third option and type it manually into the corresponding text field.

5. At the top of the dialog, select an OPC server name to connect to. This can be done from the drop-down menu or by typing it manually into the text field. The available servers is dependent upon the Machine Name selected.

6. Press the <<Commit>> button after all the information is entered.

If the OPC Server was not already running, then the OPC Client for ODBC will start the OPC server automatically. The new OPC server will be added to the tree view under the “Connected Servers” tab display.

If you try to add an OPC server to which the OPC Client for ODBC is already connected, a dialog box will inform you that a connection is already established. A new redundant connection will not be made.

Note

9

Page 14: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.2 VIEWING AN OPC SERVER’S PROPERTIES To view an OPC server’s properties, select the “Connected Servers” tab display and right-click the OPC server you wish to view. Select the Properties menu item. A list will appear in the left pane showing all relevant OPC server information. See Figure 11 below.

Figure 11 - OPC server properties

2.2.3 DELETING AN OPC SERVER CONNECTION There are two ways that you can delete an OPC server:

1. Select the “Connected Servers” display tab and right-click the OPC server you wish to delete. Select the Delete menu item.

2. Press the “Delete OPC server” button in the toolbar, highlighted in Figure 12 below.

Figure 12 - The "Delete OPC Server" Button

A dialog will pop up asking if you are sure that you want to delete the selected OPC server and associated items. Press <<OK>> to delete the server, or <<Cancel>> if you change your mind. After pressing <<OK>>, the client will disconnect from the OPC server and it’s name will be removed from the display.

10

Page 15: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.4 ADDING A GROUP OPC groups provide a way of specifying how often to get data, and what method (synchronous or asynchronous) to use to get it. The OPC Client for ODBC takes this one step further. Group creation and configuration allow the user to get data at a specified rate. If queries are associated with the OPC items, the data can be updated or inserted into a database at the group’s update rate.

There are two ways to add a group:

1. Select the “Connected Servers” display tab and right-click the OPC server you wish to add the group to. Select the Add Group menu item.

2. Select the “Connected Servers” display tab and left-click the OPC server you wish to add the group to. Press the “Add Group” button in the toolbar, highlighted in Figure 13 below.

Figure 13 - The "Add Group" Button

A dialog will appear for configuring the group that you wish to add. See Figure 14 below for an example.

Figure 14 - Add OPC Group Dialog

11

Page 16: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Option Value

Group Name The group name can be any name desired, so long as it is not the same as an existing group’s name. The group name, then, serves as an identifier for the user. Choose a name that makes sense to the users.

Update Rate The update rate specifies how often the OPC Server should try to retrieve data for the items within this group. Note that the update rate is not a guarantee. That is, an OPC server will try to retrieve data for this group’s items at the specified rate, but the actual rate may be slower if the server is busy or if communications from server to data source are hampered.

Deadband The deadband field allows the user to tell the OPC server what constitutes a change in asynchronous communications. That is, if the deadband is 10%, the value of items in this group must change by at least 10% of their current value before the server will notify the client of any changes.

IO Type The I/O type refers to how data for items in this group will be retrieved from the OPC Server. Selecting “synchronous” tells the client to make a request for data and wait until the server retrieves it. Selecting “asynchronous” means that the client makes a request for data, but does not wait for the server to retrieve the data. Rather, the server responds with an update only after retrieval, and only if item values in the group have changed.

Create Active The create active box allows the user to decide if the group should be active immediately following creation. Unchecking this box means the group will be created in an inactive state. Any items added to an inactive group will not be polled by an OPC server.

Press <<Commit>> to add the group once the information has been entered, or <<Close>> to cancel the “add group” function. If you do not specify a group name, then the client will not allow you to add the group.

12

Page 17: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.5 VIEWING AND EDITING GROUP PROPERTIES To view and/or edit a group’s properties, select the “Connected Servers” display tab and right-click the group you wish to view. Select the Properties menu item. A display will appear in the top-left pane of the main window showing all relevant OPC group information. See Figure 15 below.

Figure 15 - OPC group properties

To edit these properties, press the <<Update>> button and a form similar to the one in Figure 14 will appear. You can change the group information in the text field boxes (except for the Group name and I/O Type) and then press <<Commit>> to apply the changes. From the display of group properties, press <<Close>> to return to the display of connected servers.

2.2.6 ACTIVATING AND DISABLING GROUPS Once a Group has been defined for a connection and then populated with SQL queries, it must be activated before any data will be exchanged between the OPC server and a database. Conversely, when a Group is disabled, there is no exchange of information between the ODBC database and the OPC server. Groups are active by default when you add them, unless you specify otherwise.

To toggle a group between enabled or disabled, select the “Connected Servers” display tab and right-click the group to be changed. Select Activate or Disable depending on the current status of the group. The group’s active status will change to disabled if it was enabled previously, or enabled if it was disabled previously.

13

Page 18: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.7 DELETING A GROUP There are two ways to delete a group:

1. Select the “Connected Servers” display tab and right-click the OPC group to delete. Select the Delete menu item.

2. Select the “Connected Servers” display tab and left-click the OPC server you wish to add the group to. Press the “Delete Group” button in the toolbar, highlighted in Figure 16 below.

Figure 16 - The "Delete Group" Button

A dialog box will pop up asking if want to delete the selected OPC group and associated queries. Press <<OK>> to delete the group, or <<Cancel>> to cancel the delete. After pressing <<OK>>, the group will be deleted as well as any queries made under its items.

2.2.8 ADDING AN ITEM There are two ways to add an item:

1. Select the “Connected Servers” display tab. Right-click the OPC group to which an item must be added. Select the Add Item menu item.

2. Select the “Connected Servers” display tab. Left-click the OPC group to which an item must be added. Press the “Add Item” button in the toolbar, highlighted in Figure 17 below.

Figure 17 - The "Add Item" Button

A dialog box now will appear for configuring the item that you wish to add. Enter the Item ID, or press <<Browse>> to search for the ID of the item you wish to add. You can also select whether the item is an array, the data type of the item, and the access path of the item.

You can press <<Commit>> to add the item once the information has been entered, or <<Close>> to cancel the add item function. See Figure 18 and Figure 19 below.

Figure 18 - Add OPC Item Dialog

14

Page 19: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 19 - Browse for an OPC item

Option Value

Item ID The item ID is server specific. Refer to the server documentation on item IDs it supports. Item IDs are names that correspond to a discrete piece or item of data the server can retrieve.

Data Type Typically, the data type should be left at “Empty/Default,” which causes the client to use the server’s data type for the item. Otherwise, the client will attempt to convert the data type of the incoming data to the selected type.

Access Path The access path is server specific. Refer to the server documentation on whether the access path is used. Leave it blank if it is not used. Access paths normally are used to allow the user more control in specifying how or where data can be obtained for an item.

15

Page 20: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.2.9 DELETING AN ITEM There are two ways to delete an item:

1. Select the “Connected Servers” display tab. Right-click the OPC item to delete. Select the Delete menu item.

2. Select the “Connected Servers” display tab. Left-click the OPC item to delete. Press the “Delete Item” button in the toolbar, highlighted in Figure 20 below.

Figure 20 - The "Delete Item" Button

A dialog box will appear asking for confirmation. Press <<OK>> to delete the item, or <<Cancel>> otherwise. After pressing <<OK>>, the item and its query will be deleted.

16

Page 21: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.3 ODBC DATABASE CONNECTIONS

The top-right pane of the main window contains the ODBC database connection information as shown in Figure 21 below. There are three tabs that can be selected to view in this pane: “Add Database”, “Connected Databases”, and “Triggered Writes”. When the client is run, the right pane shows the “Add Database” tab display by default. The “Add Database” tab displays a scroll menu showing all the database types that you are able to add and the <<Add Database>> button for adding the selected database.

Figure 21 - The Add Database Tab Display

The “Connected Databases” tab displays all the databases that the client is connected to through ODBC, in a tree-view structure. Expanding each database will show the properties and tables associated with it. Expanding each property or table will show the fields within it. See Figure 22 below.

Figure 22 - The Connected Databases Tab Display

17

Page 22: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

The “Triggered Writes” tab displays two things: an interface for setting the triggered write properties, and a list of all the triggered writes. The triggered write properties are shown by default and pressing the <<Close>> button will switch views to the list of all triggered writes. Figure 23 and Figure 24 show both views. See section 2.3.5 for more information on configuring triggered writes.

Figure 23 - Triggered Write Properties

Figure 24 - List of Triggered Writes

18

Page 23: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.3.1 ADDING A DATABASE CONNECTION To connect to an ODBC database, select the “Add Database” tab display and select the database type you wish to add from the drop-down scroll menu. Once you have selected the database type, press the <<Add Database>> button below your choice. A form for entering ODBC connection information will appear in the right pane. See Figure 25 below.

Figure 25 - ODBC Connection Information

Option Value Name Name of the ODBC connection. This name can be selected arbitrarily. Data Source Name The name of the data source, which can be obtained from the ODBC “Data

Sources” in the Windows Control Panel.

User Name The name of the user that the OPC Client for ODBC must use to connect to the database.

Password The password for the above user name.

Timeout The amount of time (in seconds) that the OPC Client for ODBC must wait for the ODBC data source before declaring a timeout.

Read Only Specifies if the OPC Client for ODBC will only be permitted to read from the database, or if it can write as well.

The data sources can be configured by pressing the <<Configure>> button. Press <<Apply>> and the OPC Client for ODBC will attempt to connect to the database. A dialog box will appear telling you if the ODBC connection was successful or not. If the connection was successful, the database will be added to the “Connected Databases” tab in the right pane.

If you try to add a database connection with the same name as one that the OPC Client for ODBC already has, the dialog box will inform you that the ODBC connection was not successful.

Note 19

Page 24: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.3.2 DELETING A DATABASE CONNECTION There are two ways to delete a database connection:

1. Select the “Connected Databases” display tab and right-click the database you wish to delete. Select the Delete menu item.

2. Select the “Connected Databases” display tab. Left-click the database connection to delete. Press the “Delete Database” button in the toolbar, highlighted in Figure 26 below.

Figure 26 - The "Delete Database" Button

A dialog box will appear asking for confirmation. Press <<OK>> to delete the database connection, or <<Cancel>> otherwise. After pressing <<OK>>, the database connection will be deleted and removed from the list of databases in the “Connected Databases” tab.

2.3.3 ADDING A QUERY SQL Queries are used to construct an information exchange between the ODBC database and the OPC server. To create a new SQL query:

1. Select the “Connected Databases” tab in the right pane and select the database and table you wish to apply the query to so that it is in view.

2. Select the “Connected Servers” tab in the left pane and select the item you wish to add to the query to so that it is in view.

3. Click and drag the item over to the right pane and drop it on the desired table.

See Figure 27 below for an example of this.

Figure 27 - Drag and Drop Item to Database Table

20

Page 25: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

After you drag and drop the item, a form will appear in the bottom pane for configuring the item query. See Figure 28 below.

Figure 28 - Add Item Query Form

On the “Add Item Query” form, general information about the OPC server and ODBC database is shown on the left. To the right of the general information, you can select between an update and insert query type. An update query will update one record in your database with the OPC item at the group’s update rate, whereas an insert query will insert new records in your database at the group’s update rate. Below the query type selection, enter the desired number of queries per transaction. The rest of the form is used for selecting the table columns you wish to match the OPC item properties. There are four item properties (name, value, quality, and timestamp), so a maximum of four values will be written to the database at the update rate. If you are adding an update query, you can specify which property/column you wish the query to check for when determining which record to update, by putting a check under the Key column in the form. Once you have entered all the query information, press <<Add Query>>. A dialog will appear indicating whether adding the query was successful or not. If it was successful, the ODBC client will start exchanging information from the server to the database. You can view the query in the bottom pane if you click the item you added it to. See Figure 29 below for an example of this.

Figure 29 - Viewing the Item Query

21

Page 26: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

If you wish to define your own query, you can do so by pressing the <<Custom>> button in the Add Item Query form. Figure 30 below shows the form that appears when you do this.

Figure 30 - Adding a Custom Query

When adding a custom query, the SQL command is entered into the left text box of the form. Once you enter the command, press <<Add Query>> and a dialog will appear indicating whether adding the query was successful or not.

2.3.4 DELETING A QUERY To delete a query, select the “Connected Servers” tab in the left pane and click the item that contains the query. The query should appear in the bottom pane. Right-click the query and select the Delete Query menu item. A dialog will pop up asking if you are sure that you want to delete the selected query. Press <<OK>> to delete the query, or <<Cancel>> if you change your mind. After pressing <<OK>>, the query will be deleted and the ODBC client will stop exchanging information from the server to the database.

2.3.5 ADDING A TRIGGERED WRITE To perform triggered writes, the OPC Client for ODBC must first be connected to an SQL database. If the client is not connected to an SQL database, go through the steps in section 2.3.1 and connect to one.

Select the “Triggered Writes” tab display in the top-right pane of the main window and ensure you are looking at the triggered write properties form shown in Figure 23 - Triggered Write Properties.

Option Value

Database Select the SQL database from the drop-down scroll menu Table Select the table containing the triggering field

Key Column Select the database column that contains the name of the value used for triggering

Value Column Select the database column that contains the value used for triggering

Poll Rate Enter the time interval (in seconds) between client polls to the database

22

Page 27: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Press <<Apply>> and a dialog box will pop up indicating whether setting the properties was successful or not. Figure 31 shows the properties interface in the client and the corresponding view of the SQL database. The Table name, Key Column name, and Value Column name in the properties match the layout of the database.

Figure 31 - Triggered Write Properties and Corresponding Database

If setting the triggered write properties was successful, then press <<Close>> to view the list of triggered writes. If a failure occurred, check that the database is SQL and set up properly.

Determine which record, in the SQL database and table you selected, that you wish the ODBC client to poll. If the table you selected is empty, then add a record with a name (in the key column) and value (in the value column).

23

Page 28: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Select the “Connected Servers” tab display in the left pane and add an item that you wish the ODBC client to write to when triggered. Once the item is added, click and drag the item to the right pane and drop it on the list of triggered writes. See Figure 32 below for an example.

Figure 32 – Drag and Drop Item to Triggered Writes List

An interface will appear in the right pane as shown below. The name of the value in the database must be entered into the “Mapped Name” field. Once this is done, press <<Apply>> and a dialog will appear telling you if your mapping was successful or not. If it was successful, the triggered write mapping will appear in the list.

Figure 33 - Entering the Mapped Name

Whenever the value in the specified record is updated, the ODBC client will write that value to the corresponding item on the OPC Server the next time it polls the database. Matrikon’s OPC Explorer can be used to monitor the triggered write on the server.

24

Page 29: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.3.6 DELETING A TRIGGERED WRITE To delete a triggered write, select the “Triggered Writes” tab in the right pane and view the list of triggered writes. Right-click the OPC server for the triggered write you wish to delete, and select the Delete Mapping menu item. A dialog will pop up asking if you are sure that you want to delete the selected mapping. Press <<OK>> to delete the triggered write, or <<Cancel>> if you change your mind. After pressing <<OK>>, the triggered write will be deleted and the OPC Client for ODBC will stop polling the database and writing data to the OPC server.

25

Page 30: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.4 SESSION SETTINGS

Every session has settings that are saved to the registry when the OPC Client for ODBC is closed. These settings are accessed through the View->Options… drop-down menu.

The Program Settings dialog contains three tabs: General, Logging, and Data Format. Whenever you change a setting in the options dialog, press <<Apply>> to apply the changes. A dialog will appear telling you that the settings have been updated.

2.4.1 GENERAL The general tab contains options for saving and loading connection configurations through an XML file, as well as how data is transmitted from the OPC server.

Figure 34 - General Options Tab

2.4.2 LOGGING The ‘Logging’ tab contains options for configuring the logging settings. The log level sets the severity of messages that is logged, with ‘Low’ being the least number of log messages (where only the most severe are logged), and ‘High’ being a large number of messages.

The ‘Debug’ setting is used for a complete dump of this application while it is running. Therefore, it is not recommended that the ‘Debug’ setting be used except in situations where Matrikon’s technical support is involved. This is because a tremendous amount of information will be written to the hard drive, and will significantly decrease this application’s performance. This is highly undesirable during normal operation.

Note

26

Page 31: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

There are also options for displaying log activity to the command screen, committing all log file writes, and overwriting old log information from previous sessions. The log file must be specified in this tab and is named OdbcOpc Client.log by default.

Figure 35 - Logging Options Tab

27

Page 32: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5 USING CUSTOM QUERIES

The OPC Client for ODBC can perform complex SQL queries using OPC item characteristics (name, value, timestamp or quality) as parameters in the query string. In order to create a custom query, ensure that you have first created a database connection using the ‘Add Database’ panel on the main form. When a database connection has been established, the ‘SQL’ button on the toolbar should become active. Press this button to launch the ‘Add Query’ form.

2.5.1 THE CUSTOM QUERY FORM The Add Query Form has two sides. On the left is a text window which allows a user to enter SQL queries. On the right is a series of tab sheets which allows a user to configure options on a query, select OPC Item values to be used in a query, view query results as well as edit and delete existing queries.

2.5.1.1 EXECUTING SIMPLE QUERIES

SELECT * FROM...

In the ‘Query Text’ edit box enter a simple ‘select * from table_name’. Ensure that the table table_name exists in the database selected in the combo box supplied on the top of the ‘Data Values’ tab sheet. Now press either the ‘Execute’ button or F5 to execute the query. The following figure shows an example from a sample database containing a table named ‘OPC’. This table has two columns called ‘name’ and ‘value’, the values of which are shown on the ‘Query Results’ tab (Figure 36).

UPDATE...

In the ‘Query Text’ edit box enter the following ‘update OPC set value = ‘55’ where name = ‘Random.Int1’. Executing the query gives the results shown in Figure 37. As you will note, the success of the query is reported in the status bar on the bottom of the ‘Query Results’ tab. In this case the query succeeded, but there were no rows returned as a result of the query, so there will be no column headers shown on the ‘Query Results’ tab. Entering the original ‘select *’ statement yields the results in Figure 38. Note that all the values for ‘Random.Int1’ are now ‘55’.

As you can see, the OPC Client for ODBC can act as a query analyser for a user's databases. The range of queries that can be executed by the client is limited only by the database that you are connected to and the ODBC driver that you are using to connect to the database.

28

Page 33: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 36. Executing a Select statement.

Figure 37. Executing an Update statement.

29

Page 34: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 38. Results of the Update statement.

2.5.1.2 USING AN OPC ITEM IN A QUERY In order to use the ODBC Client to its full potential you will want to use OPC item values (OPC item values refers to either an item's ‘name’, ‘value’, ‘quality’ or ‘timestamp’) in the queries you construct. In order to do this:

1) Click on the ‘Query Options’ tab.

2) Note what characters are being used to enclose an OPC item in the ‘OPC Item Delimiters’. By default the Start Delimiter is ‘<<’ and the End Delimiter is ‘>>’.

3) In the ‘Query Text’ edit enter the following:

<<i:item1>>

followed by a space.

4) You will notice that the ‘Data Values’ tab sheet will show one row with ‘item1’ as an Argument Name and a button with an edit box as the Argument Value (Figure 39).

5) Click on the yellow ‘tag’ button.

6) A ‘Select OPC Item’ form will appear which shows you all the connected OPC Servers/Groups/Items that were previously configured.

7) Double Click on an Opc Item to set the Argument Value.

Note In the example above “item1” is a symbolic name and is NOT substituted into the final query.

30

Page 35: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 39. Creating an OPC Item for use in a Query.

In order to access a value from a newly configured OPC Item you must append immediately after the End Delimiter one of the following: .n, .v, .t, or .q. These will access the OPC Item’s Name, Value, Timestamp and Quality respectively. From the example above:

<<i:item1>>.n accesses item1’s NAME.

<<i:item1>>.v accesses item1’s VALUE.

<<i:item1>>.t accesses item1’s TIMESTAMP.

<<i:item1>>.q accesses item1’s QUALITY.

Note From the example, you may use ‘item1’ as many times as you wish in the query itself and each instance of ‘item1’ may reference ANY ONE of the OPC Item’s values.

31

Page 36: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5.1.3 CREATING AN INSERT QUERY USING AN OPC ITEM In your database, create a table with four columns: 1) opcname (varchar) , 2) opcvalue (depends) 3) opcquality (varchar or number) and 4) opctimestamp (datetime or varchar). In this example, the table I will be inserting to is called my_opc_table.

Note(s) • These are only example column and table names.

• Some databases, such as Access, have reserved words such as VALUE. When trying to validate a query on an Access database with the reserved word ‘value’ in the string will fail. In other words: don’t name a column ‘value’ if you are using Microsoft Access!

Enter the following string into the ‘Query Text’ box, substituting your specific table and column name where appropriate:

Insert into my_opc_table (opcname, opcvalue, opcquality, opctimestamp)

values (<<i:item1>>.n, <<i:item1>>.v, <<i:item1>>.q, <<i:item1>>.t)

The following should appear (Figure 40):

Figure 40. Insert query with and OPC item

The next step is to select an OPC Item that will provide the values for the query (see above: Using an OPC Item in a Query).

32

Page 37: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5.1.4 WRITE TO OPC ITEMS USING A SELECT STATEMENT In order to write values acquired from a database query to an OPC item, a different syntax must be used to specify the column of interest. Continuing with the example table above, enter the following into the ‘Query Text’ panel on the form.

select <<c:opcvalue>> from my_opc_table

The following should appear (Figure 41).

Figure 41. Using a Select Statement to Write to an OPC Item.

When a user wishes to write a result set associated with a column to an OPC Item, you must specify the column in the following fashion:

<<c:column_name_as_appears_in_table>>

By using a ‘c’ instead of an ‘i’ (as used to access OPC Items) the ‘Data Values’ tab sheet will now allow the user to select an OPC Item to write the column result to. The number of <<c:***>> expressions that can be put in a query is not limited.

Note(s) • There is no .n, .v, .q, or .t required in this syntax as there is for OPC Items.

• The query may return multiple rows. The ‘Query Options’ panel has an option which allows a user to deal with this possibility (see below Query Options Panel:Opc Return Items).

• In the above example query, there are no OPC Items used in the query that will trigger its execution upon their arrival. In this case, ensure that the query is scheduled to occur by selecting the 'Execute Query At Time Interval' in the ‘Query Options Panel’.

33

Page 38: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5.1.5 ADDING THE QUERY While it is possible to execute a custom query manually, it is more common to add the custom query to the client application. In this case, the user must provide a unique name for the query in the ‘Query Name’ edit box, and then press the 'Add' button. The client will attempt to validate the query, and if successful will add it to the client's list of queries. If unsuccessful an error will be reported to the user.

2.5.1.6 EDITING/DELETING AN EXISTING QUERY Clicking on the ‘Current Queries’ tab shows queries that have been added to the client. The following figure shows the query on the left hand side of the screen after it has been added to the client's query list:

Figure 42. Viewing an existing query

As you will note: the query name, query string and arguments for the query are all displayed in the tree view.

In order to edit or delete an existing query, right-click on the query name in the ‘Current Queries’ tree view and select edit or delete. If you select:

• delete - you will be prompted to confirm the query deletion.

• edit - the original query will be displayed on the form. The ‘Add’ query button will change to ‘Update’, and the ‘Execute’ query button will change to ‘Cancel’. If you select:

o ‘Update’ - the changes made to the query are applied.

o ‘Cancel’ - any changes made to the query are discarded.

Note To use an existing query as a template for a new query, follow the procedure for editing it above, then hit the ‘Cancel’ button and give the query a new name and new OPC items (optional) and press ‘Add’.

34

Page 39: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.5.2 QUERY OPTIONS PANEL The following is a description of options available for a custom query.

2.5.2.1 QUERY EXECUTION OPTIONS A user can choose when a query will be executed. By choosing ‘Execute Query When Values Arrive’ the query will only be triggered to execute when ALL of the OPC Items in the query have arrived. If a value for an OPC Item arrives multiple times before the query is triggered (i.e. we are still waiting for another OPC Item), the most current value will be used in the query.

Note If none of the OPC Items in an Asynchronous group change, the query will never be triggered!

By choosing ‘Execute Query At Time Interval’, the client will actually read the item's values at the rate specified and attempt to execute the query. This is a good way to trigger a query when one of the values in the query rarely changes.

2.5.2.2 OPC ITEM DELIMITERS These are the character values that will be used to identify an OPC Item in the ‘Query Text’ box.

2.5.2.3 QUERY TEXT OPTIONS Text Size: allows the user to change the font size in the ‘Query Text’ window.

2.5.2.4 OPC RETURN ITEMS When a user creates a query to write to an OPC Item, multiple rows might be returned.

This option allows the user to choose to write ALL the query results to the OPC item or only the last value returned by the query (which is assumed to be the most recent value).

2.5.2.5 QUOTATION MARKS This option allows a user to determine which OPC item properties will be automatically enclosed in quotation marks when the query is generated.

35

Page 40: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

2.6 USING STORED PROCEDURES

The OPC Client for ODBC can make use of procedures stored within a database.

2.6.1 ADDING A STORED PROCEDURE To add a stored procedure:

1) Ensure a database has been added.

2) Once a database has been added, the 'Procedure' button will become enabled. Click this button.

3) The 'Stored Procedures' dialog is displayed (Figure 43).

Figure 43 - Stored Procedures Dialog

4) Under the 'Add Procedure' tab, select the desired database from the 'Database' list.

5) Select the desired stored procedure from the 'Procedure Name' list.

6) The method signature of the stored procedure is displayed in the lower pane. Under the 'Argument Name' field 'INVAL' indicates an in parameter, 'OUTVAL' indicates and out parameter, and 'INOUTVAL' indicates an in/out parameter.

36

Page 41: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

7) For each argument, select the argument type from the 'Argument Type' list. This determines what value to pass as a parameter to the stored procedure. The available argument types are:

• Item Value

• Item Name

• Item Quality

• Item Timestamp

• Constant Number

• Constant String

Note Stored procedures will not be executed until all of the specified OPC Items have changed values. This includes items specified for 'OUT' argument values. As such, it is recommended that a 'Constant' be specified for the initial argument value for all 'OUT' parameters, as this will ensure that the procedure is triggered whenever the input items change. Note that this applies only to the initial argument value for 'OUT' parameters and not the argument value for the 'Output Result to Item' field.

8) For each argument, choose an 'Argument Value'. This may be an OPC Item or a constant value, depending on the choice made in the 'Argument Type' list. For:

• an item - Click the tag button to select an OPC Item ID.

• a constant - Type in the value in the space provided

9) Click the 'Add' button to add the stored procedure to the client's list of stored procedures.

2.6.2 VIEWING/EDITING STORED PROCEDURES To view a stored procedure:

1) Ensure a database has been added.

2) From the main screen, click the 'Procedure' button.

3) The 'Stored Procedures' dialog is displayed.

37

Page 42: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

4) Click the 'Current Procedures' tab.

Figure 44 - Stored Procedures Dialog (Current Procedures)

5) A tree view of stored procedures is displayed.

To edit a stored procedure:

1) View the stored procedure you wish to edit (see previous section).

2) Click on the procedure you wish to edit (i.e. the icon), and then right-click on the same.

3) A pop-up menu is displayed. Choose the 'Edit' option from this menu.

4) The stored procedure will be transferred to the 'Add Procedure' tab, and the 'Add' button will change to 'Update'.

5) Edit the procedure as required.

6) Clicking:

• 'Update' - will apply any changes made to the stored procedure

• 'Cancel' - discards changes made to the stored procedure

38

Page 43: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3. WALKTHROUGH OF STORING PROCESS VALUES IN AN ODBC DATABASE

3.1 CONNECT TO THE MATRIKON OPC SERVER FOR SIMULATION

The first step in storing process values is connecting to an OPC server where the data will be retrieved. An example of connecting to the Matrikon OPC Server for Simulation will be shown.

3.1.1 MATRIKON OPC SERVER FOR SIMULATION Connect to the Matrikon OPC Server for Simulation as shown in Figure 45 below.

Figure 45 - Select the OPC Simulation Server

Double-click the server name and it will be added to the “Connected Servers” display tab as show in Figure 46 below.

Figure 46 - The OPC Simulation Server Added

39

Page 44: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.2 BROWSE FOR SOME POINTS

The next step in storing process values is browsing for points that we wish to query. An example of browsing the Matrikon OPC Server for Simulation will be shown.

3.2.1 MATRIKON OPC SERVER FOR SIMULATION Create a group with default settings and add the OPC Items Random.ArrayOfReal8, Random.ArrayOfString, Random.Boolean, Random.Int1, Random.Money, Random.Qualities, Random.Real4, Random.String, Random.Time, and Random.UInt1. Add a group to the Matrikon.OPC.Simulation server as shown in Figure 47 below.

Figure 47 - Add a Group to the Server

Once the group has been added, it will appear in the “Connected Servers” display tab as shown in Figure 48 below.

Figure 48 - The Group Added

Now add the OPC items to the group that was just created. Use the browser by pressing the <<Browse>> button as shown in Figure 18. Under the Random folder, add the tags ArrayOfReal8, ArrayOfString,

40

Page 45: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Boolean, Int1, Money, Qualities, Real4, String, Time, and UInt1. The “Connected Servers” display tab will show the OPC items that you have added as seen in Figure 49 below.

Figure 49 - The OPC Items Added

41

Page 46: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.3 CONFIGURE THE ODBC DATABASE

Before process values can be stored, the ODBC database that will be storing these values must be configured. An example of setting up a Microsoft Access Database and a Microsoft SQL Database will be shown.

3.3.1 MICROSOFT ACCESS CONFIGURATION Load Microsoft Access and a dialog will appear asking whether you want to create a new database or load an existing one. Select “Create a new database using Blank Access Database” and press the <<OK>> button.

Figure 50 - Create a Blank Access Database

Microsoft Access will next prompt you to name your database. Enter a name (in this example we will use TestODBC.mdb) and press the <<Create>> button to continue.

Figure 51 - Create the Database

42

Page 47: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

A menu for setting up the new database will appear as shown in Figure 52 below. Select the “Create table in Design view” option.

Figure 52 – Setting up the new database

The design view will appear for Table1. Enter four field names: one for the item name, one for the item value, one for the item quality, and one for the item timestamp. Make sure all fields have a data type of “Text”.

Figure 53 - Designing the Table

Close the table window and Access will prompt you to save your table design. Press <<Yes>> and choose a name for your table (this example kept the default name Table1). Access will then give a warning that no primary key was defined – press <<No>>. The table records can be viewed at any time by double-clicking the table name in the database window shown in Figure 52. Close Microsoft Access.

The database must be registered with the operating system. Run the program odbcad32.exe from Start → Run. Go to the “System DSN” tab display and press the <<Add…>> button as shown in Figure 54 below.

43

Page 48: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 54 - Adding a Data Source

In the “Create New Data Source” window that appears, select the Microsoft Access Driver and press the <<Finish>> button.

Figure 55 - Select the Microsoft Access Driver

Enter a name for the data source (the name “AccessODBC” is used in this example) and press the <<Select…>> button to browse for the Access Database file that was previously saved.

44

Page 49: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 56 - Data Source Setup

Figure 57 - Selecting a Database

Once a database has been selected for the data source, press <<OK>> to exit the ODBC Data Source Administrator. The Access database is now ready to accept process data from the ODBC OPC client.

3.3.2 MICROSOFT SQL CONFIGURATION SQL Server Enterprise Manager (installed with Microsoft SQL Server) is used to create the tables for the database. Before this can be done, a connection to the SQL server of choice needs to be made. This walkthrough does not explain how to connect to an SQL server through Enterprise Manager; refer to the Microsoft SQL Server documentation.

Run Enterprise Manager, and view the database tables as shown in Figure 58 below.

45

Page 50: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 58 - Enterprise Manager

Click the “New” button circled red in Figure 58 above. Enter a name for the database table (this example will use the name Table1). The table design window will appear next as seen in Figure 59.

Figure 59 - Designing the Table

46

Enter column names for the OPC item name, value, quality, and timestamp. Make sure they have data types of “varchar”. Once this is complete, close the design table window and save the changes made.

Page 51: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

The database must now be registered with the operating system. Run the ODBC Data Source Administrator as described in section 3.3.1. Go to the “System DSN” tab display and press the <<Add…>> button as shown in Figure 54. In the “Create New Data Source” window that appears, select the SQL Driver and press the <<Finish>> button.

Figure 60 – Select the SQL Driver

A configuration window will appear as shown in Figure 61 below. Enter a name for the SQL data source (the name LocalServer is used in this example). Select the same server that you viewed in Enterprise Manager.

Figure 61 – Configuring the SQL Server DNS

Continue through the configuration process, making sure all the properties are correct. Press <<OK>> to exit the ODBC Data Source Administrator. The SQL database is now ready to accept process data from the ODBC OPC client.

3.4 ADD THE DATABASE

The ODBC OPC client must now establish a connection with the database that will store the process data. Establish connections with the Access and SQL databases that were created in section 0. Refer to section 2.3.1 on how to establish a database connection.

47

Page 52: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Figure 62 - Establishing a connection to the Access Database

Figure 63 - Establishing a connection to the SQL Database

Once the database connections are made, a tree-view of the database tables and properties will be shown in the “Connected Databases” tab view. See Figure 64 for an example of this.

Figure 64 - Viewing the database connections

48

Page 53: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5 STORE PROCESS DATA IN DATABASE

The last step in storing process values is adding a query to an OPC item. Adding a query allows the OPC Client for ODBC to take a process value from an OPC server and store the information in an ODBC database. There are two types of queries performed by the OPC Client for ODBC: update and insert. The update query updates a single record every time a process value is received. The insert query will take each received process value and insert it into a new record.

Queries are added by dragging an OPC item from the “Connected Servers” display tab and dropping it onto a database table in the “Connected Servers” display tab.

3.5.1 STORING DATA IN MICROSOFT ACCESS Drag the Random.Money OPC item onto Table1 of the AccessConnection database, as seen in Figure 65 below.

Figure 65 - Dragging and Dropping an OPC Item

49

Page 54: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

Once the OPC Item is dropped onto a table, a configuration display for the query appears in the bottom pane (see Figure 66).

Figure 66 - Query Configuration

3.5.1.1 UPDATE QUERY This query requires some database set-up prior to adding the query in the OPC Client for ODBC. The update query will update all records in a database table whose field/column entries match the specified key OPC item properties. Therefore, data must be entered into the fields of the records you wish to be updated.

Open the Microsoft Access database that was created in section 3.3.1. Open the table “Table1” in the database window, and enter the text “Random.Money” into the “the_name” field of a couple records as shown in Figure 67 below.

Figure 67 - Entering data into Key Fields

In the query configuration display of the OPC Client for ODBC, select “Update” under the title “Query Type” in the configuration display. Next, select from the “Table Column” drop-down boxes which database fields should contain the name, value, quality, and timestamp of the OPC Item. Enable the “Key” check box for the “NAME” property.

50

Page 55: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

The display should look similar to the one in Figure 68 below after configuring the query.

Figure 68 - Update Query for MS Access

Press the <<Add Query>> button and the query will begin. Refresh the Access database table and the most recent data will be seen in the correct records.

Figure 69 - OPC Items updated in MS Access

Delete the query by selecting the “Random.Money” OPC Item in the “Connected Servers” tab display, right clicking the query in the bottom pane, and selecting the Delete Query option (see Figure 70 below).

Figure 70 - Deleting the Query

51

Page 56: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5.1.2 INSERT QUERY Drag and drop the “Random.Money” OPC Item onto Table1 of the AccessConnection database, as seen in Figure 65.

In the query configuration display of the OPC Client for ODBC, select “Insert” under the title “Query Type” in the configuration display. Next, select from the “Table Column” drop-down boxes which database fields should contain the name, value, quality, and timestamp of the OPC Item. The display should look similar to the one in Figure 71 below after configuring the query.

Figure 71 - Insert Query for MS Access

Press the <<Add Query>> button and the query will begin. Refresh the Access database table and records will be seen inserted for every received process value.

Figure 72 - OPC Items inserted in MS Access

Delete the query as described at the end of section 3.5.1.1.

52

Page 57: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5.2 STORING DATA IN MICROSOFT SQL Drag the Random.Int1 OPC item onto Table1 of the SQLConnection database, as seen in Figure 73 below.

Figure 73 - Dragging and Dropping an OPC Item

Once the OPC Item is dropped onto a table, a configuration display for the query appears in the bottom pane (see Figure 74).

Figure 74 - Query Configuration

53

Page 58: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5.2.1 UPDATE QUERY Open the Microsoft SQL database that was created in section 3.3.2. Open the table “Table1” in the database window, and enter the text “Random.Int1” into the “mapname” field of a couple records as shown in Figure 75 below.

Figure 75 - Entering Data into key fields

In the query configuration display of the OPC Client for ODBC, select “Update” under the title “Query Type” in the configuration display. Next, select from the “Table Column” drop-down boxes which database fields should contain the name, value, quality, and timestamp of the OPC Item. Enable the “Key” check box for the “NAME” property. The display should look similar to the one in Figure 76 below after configuring the query.

Figure 76 - Update Query for MS Access

Press the <<Add Query>> button and the query will begin. Refresh the SQL database table and the most recent data will be seen in the correct records.

Figure 77 - OPC Items updated in MS SQL

Delete the query by selecting the “Random.Int1” OPC Item in the “Connected Servers” tab display, right clicking the query in the bottom pane, and selecting the Delete Query option (see Figure 70 for an example).

54

Page 59: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5.2.2 INSERT QUERY Drag and drop the “Random.Int1” OPC Item onto Table1 of the SQLConnection database, as seen in Figure 73.

In the query configuration display of the OPC Client for ODBC, select “Insert” under the title “Query Type” in the configuration display. Next, select from the “Table Column” drop-down boxes which database fields should contain the name, value, quality, and timestamp of the OPC Item. The display should look similar to the one in Figure 78 below after configuring the query.

Figure 78 - Insert Query for MS SQL

Press the <<Add Query>> button and the query will begin. Refresh the SQL database table and records will be seen inserted for every received process value.

Figure 79 - OPC Items inserted in MS SQL

55

Page 60: OPC Client for ODBC User Manual

Matrikon Inc OPC Client for ODBC User's Manual

3.5.3 STORING DATA IN MICROSOFT EXCEL Unfortunately, the only queries that can be done with Excel at this point are custom queries. The reason is that Excel requires square brackets around all of the parameters in the query whereas other ODBC drivers do not. An example of select custom query for excel is:

select * from [Sheet1$] where [Tagname] = 'Random.Int1'

And an insert:

insert into [Sheet1$] Values(<<i:Ran>>.n,<<i:Ran>>.v, <<i:Ran>>.q,<<i:Ran>>.t)

56