Documente Academic
Documente Profesional
Documente Cultură
Configuration
ProTool/Pro V6.0
EXCEL 2000 or Visual Basic development environment, V.6 for VB program
1. Scope of delivery
File Contents Prerequisites
Dokumentation.doc This document Microsoft Word 97/2000
OPCServer.fwd ProTool/Pro OPC Server Siemens ProTool/Pro Runtime 6.0
OPC-Client.xls Excel OPC Client Microsoft Excel 2000
OPCClient.exe Visual Basic OPC Client
Tips:
If communication does not function, the following steps can be taken in an attempt to correct the problem:
- Unregister and re-register the library. (Unregister the library with the command: 'regsvr32 -u
sopcdaauto.dll')
- Reinstall Excel 2000 or the complete Office package (Office 2000).
- It will certainly help if as few programs as possible are installed on the computer.
3. Program description
A so-called node name has to be entered for the clients. It can be either an IP address (e.g. 192.168.0.80) or
a computer name (e.g. ‘NB1207’ or ‘NB1207.siemens.de’). It is the address or the name of the computer on
which the server is running.
ProTool/Pro Runtime, Version 6.0, is required for executing the OPC server.
The OPC server is automatically started when the program is called up (OPCServer.fwd).
There are six variables (VAR_1 to VAR_6). The first four are integer values and VAR_5 and VAR_6 are texts.
The slide control represents VAR_1.
If an OPC client is connected, the variables at the client automatically change as soon as an entry in the server is
completed with the Enter key (or changed with the slide control).
After the node name (see also 3.1.General information) has been entered, the client is “connected” to the server
(which, of course, must have been started) by pressing the “Start Client” button. If you now change one of the
values in the lower half of the worksheet (cells C13 – C18), this value is automatically transmitted to the OPC
server. Of course, this communication also operates in the opposite direction. Before exiting the Excel document
and the server, exit the client by pressing the “Stop Client” button.
value of the variable can be changed; synchronization with the OPC server takes place automatically.
Before closing the client or exiting the server, the client is stopped by pressing the “Stop” button.
4.0. Programming
4.1. ProTool/Pro
Select the 'OPC-Server' option in the 'Target system' -> 'Settings'.
Appendix
Sub StartClient()
ClientHandles(1) = 1
ClientHandles(2) = 2
ClientHandles(3) = 3
ClientHandles(4) = 4
ClientHandles(5) = 5
ClientHandles(6) = 6
ServerName = Range("A2").Value
GroupName = Range("C2").Value
NodeName = Range("B2").Value
ItemIDs(1) = Range("A6").Value
ItemIDs(2) = Range("A7").Value
ItemIDs(3) = Range("A8").Value
ItemIDs(4) = Range("A9").Value
ItemIDs(5) = Range("A10").Value
ItemIDs(6) = Range("A11").Value
Exit Sub
ErrorHandler:
End Sub
Sub StopClient()
MyOPCGroupColl.RemoveAll
MyOPCServer.Disconnect
End Sub
'If NumItems > 1 Then Range("B7").Value = ItemValues(2) 'Condition if first item changes is that the second value is
unknown
Range("F2").Value = CStr(MyOPCServer.LastUpdateTime)
End Sub
The MyOPCGroup_DataChange event is activated if ‘something’ in the 'MyOPCGroup' group has changed.
The condition that a query only takes place when a variable changes was implemented for user-related
reasons.
Values(1) = Range("B6").Value
Values(2) = Range("B7").Value
Values(3) = Range("B8").Value
Values(4) = Range("B9").Value
Values(5) = Range("B10").Value
Values(6) = Range("B11").Value
MyOPCGroup.SyncWrite 6, ServerHandles, Values, Errors 'Write values in synchronous mode on the server
End Sub
The Worksheet_Change event is immediately activated when there is a change in the Excel worksheet. All
variables are then transferred to the OPC server.
While the program can be extended by a wide range of error checks, this example is sufficient to
demonstrate the basic features of the OPC.
There are two basic methods of reading or writing the values:
synchronous and
asynchronous.
In the example, writing is synchronous and reading is asynchronous.
An additional option is available if special errors need to be intercepted for separate handling. For example,
all methods of the OPCServer object return an array of “Errors”. These are values of the long type that can
then be converted to text using the GetErrorString function. This can also be realized using other objects
(OPCGroup,OPCGroup,OPCItems etc.).
The following is a list of all errors that can occur in the OPCServer:
OPCInvalidHandle, OPCBadType, OPCPublic, OPCBadRights, OPCUnknownItemID, OPCInvalidItemID,
OPCInvalidFilter, OPCUnknownPath, OPCRange, OPCDuplicateName, OPCUnsupportedRate,
OPCClamp, OPCInuse, OPCInvalidConfig, OPCNotFound, OPCInvalidPID
An exact description is found in the “Data Access Automation Interface Standard“ description of the OPC
Foundation (document included).
DCOM settings
A detailed description of how to set up the DCOM interface with the “dmcnfg” tool of Windows NT is contained
in the SIMATIC HMI Communication manual for windows based Systems.
The figures illustrate the settings that must be made for both partners.
Important!!
The settings of the rights should either be assigned for “everyone” (as shown in the figures), or explicitly for the
user on the local and remote computer.
This applies to users in “workgroups” as well as to users in domains.
Standard properties:
General settings
User identity:
The settings shown up to this point offer only a limited degree of security. Security can be tightened as follows:
Instead of setting up the rights for “everyone”, two users can be set up on the server side and the client side.
The users must have identical names and passwords on both computers. The security settings are then made
for these two users only (on the client and on the server!)
A domain can be used instead of a workgroup. This heightens security since the users are exactly the same.
Of course, it is then no longer necessary to set the users up locally.
The authentification level (on the “General” page of the OPC server) can be set to “connect” or higher.
A user group for an OPC server can be set up in a domain. This group is then integrated into the security
settings of the corresponding “dcomcnfg” settings for the OPC server. In this way, the users of different
client computers can access the server.
DCOM also features an error handling procedure. The following notes and example pertain to this procedure:
Question: What is the proper way for a client to determine that a server has failed and what should it do
when this does happen?
Background: The failure can occur at any time (i.e. during any method). If such a failure does occur the
client will need to reconnect to the server.
Resolution: For each interface method call, its return value should be checked for error as indicated above.
Note that Release() does not have to be called on all interface pointers in this case, as (a) the connection has been
lost and such calls will not go through and (b) the server object will be garbage collected eventually (six
minutes) as mentioned earlier.
Note: do not use QueryInterface() as a 'ping' mechanism because a QueryInterface() for the same IID is cached
and never goes remote, and proxies are not automatically updated of server status. Instead, use a call such as
IOPCServer->GetStatus().