ac500 communication with a ms excel opc client

28
abb Application Example AC500 Scalable PLC for Individual Automation AC500 communication with a MS Excel OPC client

Upload: hans-morten

Post on 03-Jan-2016

163 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: AC500 Communication With a MS Excel OPC Client

abb

Application Example AC500

Scalable PLC for Individual Automation

AC500 communication with a MS Excel OPC client

Page 2: AC500 Communication With a MS Excel OPC Client

Content

1 Disclaimer ..................................................................................................................3

1.1 For customers domiciled outside Germany/ Für Kunden mit Sitz außerhalb Deutschlands............................................................................................................ 3

1.2 Nur für Kunden mit Sitz in Deutschland ......................................................................... 3

2 Introduction ...............................................................................................................4

3 Commissioning instructions for the example.........................................................5

3.1 AC500 application example.............................................................................................. 5

3.1.1 Set-up the AC500 project .......................................................................................... 5

3.1.1.1 Set-up a new AC500 project........................................................................................... 5

3.1.1.1.1 Connection programming system with the AC500 ..................................................... 6

3.1.1.1.2 Test of the previous steps........................................................................................... 7

3.1.1.2 Import of the example to this project (or to your existing project)................................... 8

3.1.1.2.1 Insert the program Process_Simulation_OPC(PRG) into PLC_PRG(PRG) .............. 8

3.1.1.2.2 Task configuration ...................................................................................................... 9

3.1.1.2.3 Test of the previous steps........................................................................................... 9

3.1.1.3 Symbol Configuration.................................................................................................... 10

3.1.1.3.1 Empty existing entries in the symbol files................................................................. 10

3.1.1.3.2 Configuration of the new symbol files....................................................................... 10

3.1.1.3.3 Store project ............................................................................................................. 11

3.1.1.3.4 Creating and transmission of the symbol file to the gateway ................................... 11

3.1.2 CoDeSys OPC Configuration .................................................................................. 12

3.1.2.1 Test of the previous Steps, Test of the OPC Configuration.......................................... 14

3.1.2.1.1 Setup of the Matrikon OPC Explorer ........................................................................ 14

3.1.2.1.2 Test with Matrikon OPC Explorer ............................................................................. 15

3.1.2.1.3 Check the OPC configuration files............................................................................ 17

3.2 MS Excel Project ............................................................................................................. 18

3.2.1 Working with the OPC_Excel_Client.xls.................................................................. 18

3.2.1.1 Raw functional sequence.............................................................................................. 18

3.2.2 Visual Basis program .............................................................................................. 20

4 Appendix ..................................................................................................................21

4.1 The files AC500_to_OPC_Excel_Client.SYM and AC500_to_OPC_Excel_Client.SDB 21

4.1.1 The file AC500_to_OPC_Excel_Client.SYM of this example .................................. 21

Application Example - 1 - AC500/Issue: 07.2010

Page 3: AC500 Communication With a MS Excel OPC Client

4.2 The file CoDeSysOPC.ini................................................................................................ 21

4.2.1 The file CoDeSysOPC.ini of this example ............................................................... 21

4.3 The file OPCServer.log ................................................................................................... 22

4.3.1 The file OPCServer.log of this example .................................................................. 22

4.4 Visual Basis program ..................................................................................................... 23

Application Example - 2 - AC500/Issue: 07.2010

Page 4: AC500 Communication With a MS Excel OPC Client

1 Disclaimer

1.1 For customers domiciled outside Germany/ Für Kunden mit Sitz außerhalb Deutschlands

"Warranty, Liability: The user shall be solely responsible for the use of this application example described within this file. ABB shall be under no warranty whatsoever. ABB's liability in connection with this application example or the files included within this file, irrespective of the legal ground, shall be excluded. The exclusion of liability shall not apply in the case of intention or gross negligence. The present declaration shall be governed by and construed in accordance with the laws of Switzerland under exclusion of its conflict of laws rules and of the Vienna Convention on the International Sale of Goods (CISG)." "Gewährleistung und Haftung: Der Nutzer ist allein für die Verwendung des in dieser Datei beschriebenen Anwendungsbeispiels verantwortlich. ABB unterliegt keiner Gewährleistung. Die Haftung von ABB im Zusammenhang mit diesem Anwendungsbeispiel oder den in dieser Datei enthaltenen Dateien - gleich aus welchem Rechtsgrund - ist ausgeschlossen. Dieser Ausschluß gilt nicht im Falle von Vorsatz oder grober Fahrlässigkeit. Diese Erklärung unterliegt Schweizer Recht unter Ausschluß der Verweisungsnormen und des UN-Kaufrechts (CISG)."

1.2 Nur für Kunden mit Sitz in Deutschland

"Gewährleistung und Haftung: Die in diesem Anwendungsbeispiel enthaltenen Dateien beschreiben eine mögliche Anwendung der Steuerung AC500 bzw. zeigen eine mögliche Einsatzart der Steuerung. Sie stellen nur Beispiele für Programmierungen dar, sind aber keine fertigen Lösungen. Eine Gewähr kann nicht übernommen werden. Der Nutzer ist für die ordnungsgemäße, insbesondere vollständige und fehlerfreie Programmierung der Steuerungen selbst verantwortlich. Im Falle der teilweisen oder ganzen Übernahme der Programmierbeispiele können gegen ABB keine Ansprüche geltend gemacht werden. Die Haftung von ABB, gleich aus welchem Rechtsgrund, im Zusammenhang mit den Anwendungsbeispielen oder den in dieser Datei enthaltenen Dateien wird ausgeschlossen. Der Haftungsausschluß gilt jedoch nicht in Fällen des Vorsatzes, der groben Fahrlässigkeit, bei Ansprüchen nach dem Produkthaftungsgesetz, im Falle der Verletzung des Lebens, des Körpers oder der Gesundheit oder bei schuldhafter Verletzung einer wesentlichen Vertragspflicht. Im Falle der Verletzung einer wesentlichen Vertragspflicht ist die Haftung jedoch auf den vertragstypischen, vorhersehbaren Schaden begrenzt, soweit nicht zugleich ein anderer der in Satz 2 dieses Unterabsatzes erwähnten Fälle gegeben ist. Eine Änderung der Beweislast zum Nachteil des Nutzers ist hiermit nicht verbunden. Es gilt materielles deutsches Recht unter Ausschluß des UN-Kaufrechts."

Application Example - 3 - AC500/Issue: 07.2010

Page 5: AC500 Communication With a MS Excel OPC Client

2 Introduction

Often wish a customer, among the CoDeSysHMI visualization, a simple tool which makes him possible to set values in the PLC, observe these values and work on and on with these values in a calculation tool like Microsoft (MS) Excel. This application describes how it is possible to build up a simple low cost visualisation and operation station with AC500 and one PC with MS Windows XP and MS Excel. The idea of this application based on the example in the OPC Book. In this book described Frank Iwanitz and Jürgen Lange how it is possible to communicate with VBA (MS Visual Basic for Application), witch is included in most of the MS Office programs, with the OPCServer via an Automation Interface. There is already an example on the CD AC500 Control Builder PS501 Version 1.3.2 in the folder …\CD_AC500\CoDeSys\ServicePack\ProgramFiles\Projects\Examples\OPC\EXCEL_Client\, but it seems that it is not so user-friendly and therefore little known/popular. That is a new trial to announce this possibility. The example programs allow to read 20 to 990 variables and to write 10 word variables. The example can be easily adapted to the customer´s application and every type of the AC500. The example uses the OPC Data Access functionality, therefore the OPC-Server V2.3 DA will be used. The OPC_Excel_Client.xls functionality can be easy expanded by every customer he is familiar with VBA

programming. Used components and tools: 1. AC500 PM564(FW) : V1.3.4,2009-06-05 (Build:5731,16:19:21,Rel) 2. TK503 programing cable 3. AC500 Control Builder PS501 Version 1.3.2 4. Personal Computer (PC) with MS Windows XP SP3 and MS Excel 2003 SP3 (it should work also with

different MS versions, but it is not tested). 5. OPC-Server V2.3.x DA (from CD AC500 Control Builder PS501 Version 1.3.2). OPC-Server and

Gateway (without CoDeSys) can be also installed standalone on a target PC (see „Opt. 2: Installation OPC Server”).

Used documents: 1. Online help documentation of the AC500 Control Builder PS501 Version 1.3.2 2. OPC Book. "OPC - Fundamentals, Implementation and Application", third edition, revised and extended,

2006; Written by: Frank Iwanitz, Jürgen Lange; Published by: Hüthig Fachverlag ISBN 3-7785-2904-8) The example consist of two parts: 1. AC500_to_OPC_Excel_Client.pro: AC500eCo project with symbol and CoDeSysOPC configuration 2. OPC_Excel_Client.xls: MS Excel sheet with VBA program

PCAC500

TK503

RS485 USB

OPC Server

PLCproject

Excel

VBA Sheet

Application Example - 4 - AC500/Issue: 07.2010

Page 6: AC500 Communication With a MS Excel OPC Client

3 Commissioning instructions for the example

Unzip the attachment AC500_to_OPC_Excel_Client.zip into a folder e.g. AC500_OPC_Excel. In the attachment AC500_to_OPC_Excel_Client.zip there are following files: AC500 communication with a MS Exel OPC client.pdf this application example description itself AC500_to_OPC_Excel_Client.pro PLC application example for AC500 PM564 PROCESS_SIMULATION_OPC.EXP the export file of the PLC application

example with the program Process_Simulation_OPC(PRG) and it’s Global OPC variables AC500_to_OPC_Excel_Client.SDB Symbol configuration of this example AC500_to_OPC_Excel_Client.SYM readable Symbol configuration OPC_Excel_Client.xls MS Excel sheet with VBA program \CoDeSysOPC\ CoDeSysOPC.ini CoDeSys OPC configuration of this example \CoDeSysOPC\ OPCServer.log OPC-Server logging file

3.1 AC500 application example

Start AC500 Control Builder CoDeSys V2.3

3.1.1 Set-up the AC500 project

For demonstration of all necessary steps we will start with a new AC500 project. If you liked to insert this example in an existing program, you can continue with step “Import of the example to this project (or to your existing project)”

3.1.1.1 Set-up a new AC500 project

CoDeSys <File> <New> Set the Target Settings for e.g. AC500 PM564

Application Example - 5 - AC500/Issue: 07.2010

Page 7: AC500 Communication With a MS Excel OPC Client

Enter one statement.

Save the project CoDeSys <File> <Save As>, e.g. AC500_to_OPC_Excel_Client.pro

3.1.1.1.1 Connection programming system with the AC500

Connect the PC via a programming cable with the AC500. In this example the TK503 programming cable is used. Set the communication parameters: On this PC the COM13 is linked to the TK503 programming cable.

Application Example - 6 - AC500/Issue: 07.2010

Page 8: AC500 Communication With a MS Excel OPC Client

NOTICE

Important ! Check on your PC which COM port is linked to the TK503 programming cable! It can be checked in Windows <Start> <Settings> <Control Panel> <Sytem> <Hardware> <Device Manager> <Ports>

Further information about useable drivers for OPC communication is on AC500 Control Builder PS501, Help, chapter 1.2 „Fields of application of the OPC server“.

3.1.1.1.2 Test of the previous steps

CoDeSys <Online> <Login> Download the new program CoDeSys <Online> <Run> When the AC500 is running, all of the previous steps were right.

Application Example - 7 - AC500/Issue: 07.2010

Page 9: AC500 Communication With a MS Excel OPC Client

3.1.1.2 Import of the example to this project (or to your existing project).

CoDeSys <Project> <Import> PROCESS_SIMULATION_OPC.EXP

After that, there are a program Process_Simulation_OPC(PRG) and a folder of global OPC variables.

The program Process_Simulation_OPC(PRG) is only for the demonstration, that the OPC variables are on life. With collecting of the OPC variables in a extra folder is it easier to reduce the number of variables, which have to be communicated. Only this folder must be added later to the symbol file. (See AC500 Control Builder PS501, Help, chapter 4 “Behaviour of the OPC server”)

3.1.1.2.1 Insert the program Process_Simulation_OPC(PRG) into PLC_PRG(PRG)

In PLC_PRG(PRG) press <F2> Select User defined Programs, Process_Simulation_OPC(PRG) OK

Application Example - 8 - AC500/Issue: 07.2010

Page 10: AC500 Communication With a MS Excel OPC Client

3.1.1.2.2 Task configuration

NOTICE

Important ! Do not configure the program as a freewheeling program, please use a task configuration. Call the PLC Browser and have a look to the task time (command “tsk in the command line). For example the program has a cycle time of 40ms, use a task time of 50 or 60ms. So the CPU has time to answer the OPC request from the Server between the tasks.

CoDeSys, Resources, Task configuration, right mouse click, Append Task Rename the task to e.g Main, insert the interval to e.g. t#20ms Select the task name, right mouse click, Append Program Call Program Call, select PLC_PRG(PRG)

3.1.1.2.3 Test of the previous steps

CoDeSys <Online> <Login> Download the new program CoDeSys <Online> <Run> When the AC500 is running and some of the OPC variables are on life, all of the previous steps were right.

Application Example - 9 - AC500/Issue: 07.2010

Page 11: AC500 Communication With a MS Excel OPC Client

3.1.1.3 Symbol Configuration

The configuration is described also in AC500 Control Builder PS501 (see Help, chapter 3 “Use of the CoDeSys OPC server”)

3.1.1.3.1 Empty existing entries in the symbol files

CoDeSys, <Project> <Options> <Symbol Configuration> Select checkbox <Dump symbol entries> Select <Configure symbol file…>

First deselect all check boxes, with it all variables are deselected. It is important specially in older existing projects.

<OK> <OK>

3.1.1.3.2 Configuration of the new symbol files

Application Example - 10 - AC500/Issue: 07.2010

Page 12: AC500 Communication With a MS Excel OPC Client

Enter CoDeSys, <Project> <Options> <Symbol Configuration> Select <Configure symbol file…> once more

Mark Program and Variables (multiple choice with <Ctrl> + mouse Click) Please mark only this Variables, which will be needed in the control or visual software to avoid a high load on data transmission from PLC to OPC Server. <OK> <OK>

3.1.1.3.3 Store project

With CoDeSys <Project> <Clean all> and <Project> <Rebuild all and then File> <Save> the symbol files AC500_to_OPC_Excel_Client.SYM and AC500_to_OPC_Excel_Client.SDB were simultaneously created and stored in the project folder of the AC500 project. Test of the previous step Check the time and date of the creation of these files. The file AC500_to_OPC_Excel_Client.SYM is readable with e.g. notepad. The OPC variables (items), which were configured before, can be checked (see also “The file AC500_to_OPC_Excel_Client.SYM of this example”).

3.1.1.3.4 Creating and transmission of the symbol file to the gateway

With downloading the project (CoDeSys <Online> <Login> -> 'Download') into the AC500 the symbol file AC500_to_OPC_Excel_Client.SDB is created again and loaded to the gateway (path C:\WINNT\Gateway Files\ ). The communication with the OPC server uses the settings of the symbol file located there. Store the program with CoDeSys <Online> <Create boot project> in the Flash memory of the AC500. Test of the previous step Check the time and date of the creation of this file.

Application Example - 11 - AC500/Issue: 07.2010

Page 13: AC500 Communication With a MS Excel OPC Client

3.1.2 CoDeSys OPC Configuration

Start the configuration of the OPC-Server V2.3 with <Windows> <Start> <Programs> >3S Software> <Communication> >CoDeSys OPC Configurator> Chose <Single PLC> or <Multi PLC> configuration.

NOTICE

In the Single-PLC and Multi-PLC configuration are the prefixes of the OPC variables different. When there is a configured OPC Client (how in this example), then use Multi-PLC configuration with PLC name PLC1, otherwise the variables of the OPC Client must be renamed, too.

NOTICE

For trouble shooting! Chose the check box "Log Events:", then all actions of the OPCServer are recorded in C:\Program Files\3S Software\CoDeSysOPC\OPCServer.log.

Application Example - 12 - AC500/Issue: 07.2010

Page 14: AC500 Communication With a MS Excel OPC Client

Chose the same communication parameters as used for the programming with AC500 Control Builder PS501.

Save the OPC configuration.

Application Example - 13 - AC500/Issue: 07.2010

Page 15: AC500 Communication With a MS Excel OPC Client

Application Example - 14 - AC500/Issue: 07.2010

3.1.2.1 Test of the previous Steps, Test of the OPC Configuration

Basically, not only with this example, is it reasonable method to test now the OPC configuration. The easiest way to do it, is the using of a freeware OPC Client/Tool like e.g. Matrikon OPC Explorer, Softing OPC Demo Client, etc.

NOTICE

Important for trouble shooting and demarcation of errors! A successful test makes sure that the OPC Server and its configuration are correct.

3.1.2.1.1 Setup of the Matrikon OPC Explorer

The latest version of the Matrikon OPC is available on http://www.matrikonopc.com. An older version is on the AC500 Control Builder PS501. Instalation from the CD PS501 Install OPC Explorer as follows CD PS501 Directory D:\CD_AC500\CoDeSys\ServicePack\ProgramFiles\Projects\Examples\OPC\Matrikon \Testclient Double click to File „MatrikonOPCsim.EXE

Next Next

Next

o Start Installation Next t

Page 16: AC500 Communication With a MS Excel OPC Client

3.1.2.1.2 Test with Matrikon OPC Explorer

Start the Matrikon OPC Explorer. The Matrikon Explorer search first the local PC for available OPC servers and indicates them. In the following picture it founds two servers: CoDeSys.OPC.02 (this is the name of the CoDeSys OPC-Server V 2.3 DA) and CoDeSys.OPC.DA (this is the name of the CoDeSys OPC-Server version 3). Select the server CoDeSys.OPC.02.

Click to Server, Right mouse click/Connect

Click to Server, Right mouse click /Add Group

Application Example - 15 - AC500/Issue: 07.2010

Page 17: AC500 Communication With a MS Excel OPC Client

Click to Group, Right mouse click /Add Items „Add to Tag List“ or „Add All Items to Tag List“

Close the item browse and add the selected items

Application Example - 16 - AC500/Issue: 07.2010

Page 18: AC500 Communication With a MS Excel OPC Client

Check the items

If the Matrikon OPC Explores displays the quality “Good, non–specific”, the OPC configuration is in order. The following chapter “Check of the OPC configuration files” can be jumped over and be gone on working with the chapter “MS Excel Project”.

NOTICE

Important ! The identical names and spellings of the OPC server (CoDeSys.OPC.02) and OPC variables (e.g. PLC1:.word_out_00 or PLC1:.word_in_04) must be used by the application OPC_Excel_Client.xls to avoid error messages in Excel.

3.1.2.1.3 Check the OPC configuration files

If the test with the OPC Client/Tool was not successfully, then all previous steps (from chapter“Symbol file configuration”) must be repeated and checked carefully. Check if the time stamp of the generated files is right. Compare the contents of the files with the files in the attachment AC500_to_OPC_Excel_Client.zip and

in the chapter “Appendix”.

Application Example - 17 - AC500/Issue: 07.2010

Page 19: AC500 Communication With a MS Excel OPC Client

3.2 MS Excel Project

3.2.1 Working with the OPC_Excel_Client.xls

Start the program Microsoft Excel and open the file OPC_Excel_Client.xls.

The worksheet CoDeSys.OPC.02 is the “Control panel” for the communication with the OPC-Server.

3.2.1.1 Raw functional sequence

1. With push “Connect” the application starts. 2. Initialization of the communication. VBA program reads from cell B1 (column B, row 1) the name of the

OPC-Server and from cell B11 to B1000 (empty cell are ignored) the names of the OPC items.

Application Example - 18 - AC500/Issue: 07.2010

Page 20: AC500 Communication With a MS Excel OPC Client

NOTICE

Important! The names and spellings of the OPC server (CoDeSys.OPC.02) and of the OPC variables (or the cells must be empty) in the yellow cells must be right. If not, then a window with "Microsoft Visual Basic Runtime error" will be shown. To avoid this, is it a good practice, to check the names with e.g. Matrikon OPC Explorer. Several OPC clients can work in parallel with the OPC-Server.

3. Data exchange. VBA program asks the OPC server for the values and writes those in the green cells.

4. Writing values into AC500. With push the button e.g “Write_06” the value, in the cell on the left of

“Write_06”, will be written into the AC500. The blue cells are for enter the values. 5. Stop of the application. With push the button “Disconnect” the application stops and so the

communication with the OPC-Server.

Application Example - 19 - AC500/Issue: 07.2010

Page 21: AC500 Communication With a MS Excel OPC Client

The worksheet Overview is a simple example, how the user can design the own application with the help of standard Excel functions.

3.2.2 Visual Basis program

Open Visual Basic editor in the Excel with <Extra> <Macro> <Visual Basic editor> The application program is in the table CoDeSys.OPC.02 A print out of the program is also in Appendix.

Application Example - 20 - AC500/Issue: 07.2010

Page 22: AC500 Communication With a MS Excel OPC Client

4 Appendix

4.1 The files AC500_to_OPC_Excel_Client.SYM and AC500_to_OPC_Excel_Client.SDB

When the example is stored in the PS501 programming system, the files AC500_to_OPC_Excel_Client.SYM and AC500_to_OPC_Excel_Client.SDB are simultaneously created and stored in the project folder of the CoDeSys AC500 project. The file AC500_to_OPC_Excel_Client.SYM is readable and can so easilly checked by the user. When the example is loaded in the PS501 programming system into the AC500, then the file AC500_to_OPC_Excel_Client.SDB is also stored in the folder C:\WINNT\Gateway Files\ AC500_to_OPC_Excel_Client.SDB. The OPCServer uses this file for the communication with the AC500.

4.1.1 The file AC500_to_OPC_Excel_Client.SYM of this example

;Version=2 ;ProjectId=489241 ;Checksum=0 ;Filesize=0 .Array_out[0]:WORD:4:200:2:b:16#02000020 … … .Array_out[146]:WORD:4:492:2:b:16#02000020 .Array_out[147]:WORD:4:494:2:b:16#02000020 .Array_out[148]:WORD:4:496:2:b:16#02000020 .Array_out[149]:WORD:4:498:2:b:16#02000020 .rel_out_01:REAL:5:1552:4:b:16#02000040 .word_in_00:WORD:5:1512:2:b:16#02000040 .word_in_01:WORD:5:1514:2:b:16#02000040 .word_in_02:WORD:5:1516:2:b:16#02000040 .word_in_03:WORD:5:1518:2:b:16#02000040 .word_in_04:WORD:5:1520:2:b:16#02000040 .word_in_05:WORD:5:1522:2:b:16#02000040 .word_in_06:WORD:5:1524:2:b:16#02000040 .word_in_07:WORD:5:1526:2:b:16#02000040 .word_in_08:WORD:5:1528:2:b:16#02000040 .word_in_09:WORD:5:1530:2:b:16#02000040 .word_out_00:WORD:5:1532:2:b:16#02000040 .word_out_01:WORD:5:1534:2:b:16#02000040 .word_out_02:WORD:5:1536:2:b:16#02000040 .word_out_03:WORD:5:1538:2:b:16#02000040 .word_out_04:WORD:5:1540:2:b:16#02000040 .word_out_05:WORD:5:1542:2:b:16#02000040 .word_out_06:WORD:5:1544:2:b:16#02000040 .word_out_07:WORD:5:1546:2:b:16#02000040 .word_out_08:WORD:5:1548:2:b:16#02000040 .word_out_09:WORD:5:1550:2:b:16#02000040

4.2 The file CoDeSysOPC.ini

The result of the configuration with CoDeSys OPC Configurator is stored in C:\Program Files\3S Software\CoDeSysOPC\CoDeSysOPC.ini.

4.2.1 The file CoDeSysOPC.ini of this example

[Server]

Application Example - 21 - AC500/Issue: 07.2010

Page 23: AC500 Communication With a MS Excel OPC Client

updaterate=200 publicgroups=0 logevents=1 syncinit=1 PLCs=1 PLC0=PLC1 [PLC:PLC1] active=1 motorola=1 nologin=1 timeout=10000 tries=3 waittime=10 reconnecttime=10 buffersize=4800 project=AC500_to_OPC_Excel_Client gateway=Local device=Serial (RS232) instance=TK503_USB_To_Serial parameters=6 parameter0=Port value0=COM13 parameter1=Baudrate value1=19200 parameter2=Parity value2=No parameter3=Stop bits value3=1 parameter4=Motorola byteorder value4=Yes parameter5=Flow Control value5=Off

4.3 The file OPCServer.log

If in the CoDeSys OPC configuration the check box "Log Events:" is checked (logevents=1 in the OPCserver.ini), then all actions of the OPCServer are recorded in C:\Program Files\3S Software\CoDeSysOPC\OPCServer.log

4.3.1 The file OPCServer.log of this example

That is an example of a successful setting up of the connection with an OPC client. Logfile for OPC-Server V2.0 ========================================================================== Filter=0xffffffff (04.07.2010, 12:39:30.234) Server 2.3.13.3 started (04.07.2010, 12:39:30.234) UpdateRate[ms]=200, PublicGroups=0, SyncInit=1, LogEvents=1 (04.07.2010, 12:39:30.234) 1. Reconnect to <PLC1> (04.07.2010, 12:39:30.312) [PLC1]: ::ConnectGateway(): m_ulGatewayChannels=1 (04.07.2010, 12:39:30.312) Gateway Version: 2.3.9.11 (04.07.2010, 12:39:30.375) <PLC1> Reconnect successful, ProjectName='AC500_to_OPC_Excel_Client.' (04.07.2010, 12:39:30.375) Timeout[ms]=10000, BufferSize[B]=4800, Waitime[s]=10, Reconnecttime[s]=10 (04.07.2010, 12:39:30.375) Motorola=1, NoLogin=1 (04.07.2010, 12:39:30.453) <PLC1> ProjectID matched, Project <AC500_to_OPC_Excel_Client.>: PLC=489241, SYM=489241 (04.07.2010, 12:39:30.453) <PLC1> 171 symbols loaded (04.07.2010, 12:39:30.546) Client attached to server (04.07.2010, 12:39:50.390) <PLC1> 171 active items

Application Example - 22 - AC500/Issue: 07.2010

Page 24: AC500 Communication With a MS Excel OPC Client

NOTICE

A useful tool for monitoring of logging file outputs in real-time is the freeware WinTail.

4.4 Visual Basis program

'Example: OPC Client vor AC500 19 July 2010 chja '************************************************************************************************ 'The idea of this application based on the example in the OPC Book '"OPC - Fundamentals, Implementation and Application", third edition, revised and extended, 2006; 'Written by: Frank Iwanitz, Jürgen Lange; Published by: Hüthig Fachverlag ISBN 3-7785-2904-8 '************************************************************************************************ Option Explicit 'All variables must be declared Option Base 1 'Sets the default lower limit index of an array to 1 Dim SvrSample As OPCServer 'Variable for the OPCServer object Dim WithEvents SmplSvrGroup As OPCGroup 'Variable for the OPCGroup object, it supports VB events Dim SMPLItem(1 To 1000) As OPCItem 'Variable for the OPCItem object Dim i As Integer Dim TEST As Variant Dim szItemId As Variant Private Sub StartSampleServer() Dim GroupColl As OPCGroups Dim ItemColl As OPCItems Set SvrSample = New OPCServer 'Provide the OPCServer object with memory SvrSample.Connect CStr(Cells(1, 2)) 'Takes the name of the cell (row 1, column B) 'as OPCServer name. 'With AC500 OPC-Server: "CoDeSys.OPC.02" = CoDeSys OPC Server V2.3 '"WinCoDeSysOPC" = CoDeSys OPC Server V3 Cells(5, 2) = SvrSample.ServerName 'Write ServerName to cell Cells(2, 2) = SvrSample.VendorInfo 'Write VendorInfo to cell Cells(3, 2) = SvrSample.ServerState 'Write ServerState to cell chbSampleGroupActive.Value = True 'Set Checkbox value to true Set GroupColl = SvrSample.OPCGroups 'Add Group with given or default Name Set SmplSvrGroup = GroupColl.Add(CStr(Cells(6, 2))) 'VBASample 'allow Subscriptions SmplSvrGroup.IsSubscribed = True 'set Group active state with Checkboxvalue SmplSvrGroup.IsActive = True 'set updaterate with value in Excel sheet SmplSvrGroup.UpdateRate = CLng(Cells(7, 2)) 'write to sheet, revised updaterate may be different Cells(7, 2) = SmplSvrGroup.UpdateRate '500 'There was a group name created, if no name was given Cells(6, 2) = SmplSvrGroup.Name 'VBASample 'add same items here Set ItemColl = SmplSvrGroup.OPCItems 'Set ItemColl = SmplSvrGroup.OPCItems If ItemColl Is Nothing Then Exit Sub TEST = ItemColl End If 'This loop generates from the Excel sheet the items for the collection object i = 11 'from row 11 Do While i < 1001 'to row 1000 szItemId = CStr(Cells(i, 2)) 'Item from row i, column B If szItemId <> "" Then 'If cell is not empty, 'add item to collection Set SMPLItem(i - 10) = ItemColl.AddItem(szItemId, i) End If i = i + 1 Loop End Sub Private Sub StopSampleServer() Dim GroupColl As OPCGroups

Application Example - 23 - AC500/Issue: 07.2010

Page 25: AC500 Communication With a MS Excel OPC Client

Dim locGroup As OPCGroup Dim ItemColl As OPCItems Dim Item As OPCItem Set GroupColl = SvrSample.OPCGroups For Each locGroup In GroupColl If Not (locGroup Is Nothing) Then locGroup.IsSubscribed = False locGroup.IsActive = False Set ItemColl = locGroup.OPCItems For Each Item In ItemColl Dim SH(1) As Long Dim Errors() As Long SH(1) = Item.ServerHandle ItemColl.Remove 1&, SH, Errors Next Item GroupColl.Remove locGroup.ServerHandle End If Next locGroup If Not (SmplSvrGroup Is Nothing) Then Set SmplSvrGroup = Nothing 'release PBGroup in OPC Server End If If Not (SvrSample Is Nothing) Then SvrSample.Disconnect Set SvrSample = Nothing End If chbSampleGroupActive.Value = False Cells(2, 2) = "" 'clear vendorinfo Cells(3, 2) = "" End Sub Private Sub cmdConnect_click() cmdDisconnect.Enabled = True cmdConnect.Enabled = False Call StartSampleServer End Sub Private Sub SAMPLEGroupActive_Click() If Not (SmplSvrGroup Is Nothing) Then SmplSvrGroup.IsActive = SmplSvrGroupActive.Value End If End Sub Private Sub cmdDisconnect_Click() cmdDisconnect.Enabled = False cmdConnect.Enabled = True Call StopSampleServer End Sub 'Subroutine writes the value, from the cell on the left of the button 'into the addressed item of the collection object. Private Sub cmdWrite_00_Click() 'ObjectName of the CommandButton SMPLItem(11 - 10).Write CLng(Cells(11, 4)) 'Writes value from cell (row 11, column 4 (=D) into 'OPCItem-Object 1 (row 11 - offset) End Sub Private Sub cmdWrite_01_Click() SMPLItem(12 - 10).Write CLng(Cells(12, 4)) End Sub Private Sub cmdWrite_02_Click() SMPLItem(13 - 10).Write CLng(Cells(13, 4)) End Sub Private Sub cmdWrite_03_Click() SMPLItem(14 - 10).Write CLng(Cells(14, 4)) End Sub Private Sub cmdWrite_04_Click() SMPLItem(15 - 10).Write CLng(Cells(15, 4)) End Sub Private Sub cmdWrite_05_Click() SMPLItem(16 - 10).Write CLng(Cells(16, 4)) End Sub

Application Example - 24 - AC500/Issue: 07.2010

Page 26: AC500 Communication With a MS Excel OPC Client

Private Sub cmdWrite_06_Click() SMPLItem(17 - 10).Write CLng(Cells(17, 4)) End Sub Private Sub cmdWrite_07_Click() SMPLItem(18 - 10).Write CLng(Cells(18, 4)) End Sub Private Sub cmdWrite_08_Click() SMPLItem(19 - 10).Write CLng(Cells(19, 4)) End Sub Private Sub cmdWrite_09_Click() SMPLItem(20 - 10).Write CLng(Cells(20, 4)) End Sub Private Sub SmplSvrGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, qualities() As Long, TimeStamps() As Date) Dim ItemColl As OPCItems Dim Item As OPCItem Set ItemColl = SmplSvrGroup.OPCItems On Error Resume Next 'For avoid "run time error 50290" 'The reason is unknown, it happened sometimes with mouse clicks. chja For Each Item In ItemColl Cells(Item.ClientHandle, 3) = Item.Value 'The values read out of the OPC server 'are wrote into culumn 3 (= C) Next Item End Sub

Application Example - 25 - AC500/Issue: 07.2010

Page 27: AC500 Communication With a MS Excel OPC Client

Application Example - 26 - AC500/Issue: 07.2010

Doc. kind: No. o. p.:

Helpline document 29

Title: Lang.:

AC500 communication with a MS Excel OPC client EN

Page 28: AC500 Communication With a MS Excel OPC Client

Man

ual

No.

2C

DC

12

5 12

0 M

020

1

abb

ABB STOTZ-KONTAKT GmbH Eppelheimer Straße 82 Postfach 101680 69123 Heidelberg, Germany 69006 Heidelberg, Germany Telephone (06221) 701-0 Telefax (06221) 701-240 E-Mail [email protected] Internet http://www.abb.com/plc