AC500 Communication With a MS Excel OPC Client



Comments



Description

Application ExampleAC500 Scalable PLC for Individual Automation AC500 communication with a MS Excel OPC client abb 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 3 Introduction ...............................................................................................................4 Commissioning instructions for the example.........................................................5 3.1 AC500 application example.............................................................................................. 5 Set-up the AC500 project .......................................................................................... 5 Set-up a new AC500 project........................................................................................... 5 Connection programming system with the AC500 ..................................................... 6 Test of the previous steps........................................................................................... 7 Import of the example to this project (or to your existing project)................................... 8 Insert the program Process_Simulation_OPC(PRG) into PLC_PRG(PRG) .............. 8 Task configuration ...................................................................................................... 9 Test of the previous steps........................................................................................... 9 Symbol Configuration.................................................................................................... 10 Empty existing entries in the symbol files................................................................. 10 Configuration of the new symbol files....................................................................... 10 Store project ............................................................................................................. 11 Creating and transmission of the symbol file to the gateway ................................... 11 3.1.1.1.1 3.1.1.1.2 3.1.1.2 3.1.1.2.1 3.1.1.2.2 3.1.1.2.3 3.1.1.3 3.1.1.3.1 3.1.1.3.2 3.1.1.3.3 3.1.1.3.4 3.1.1 3.1.1.1 3.1.2 CoDeSys OPC Configuration .................................................................................. 12 Test of the previous Steps, Test of the OPC Configuration.......................................... 14 Setup of the Matrikon OPC Explorer ........................................................................ 14 Test with Matrikon OPC Explorer ............................................................................. 15 Check the OPC configuration files............................................................................ 17 3.1.2.1.1 3.1.2.1.2 3.1.2.1.3 3.1.2.1 3.2 MS Excel Project ............................................................................................................. 18 Working with the OPC_Excel_Client.xls.................................................................. 18 Raw functional sequence.............................................................................................. 18 3.2.1 3.2.2 3.2.1.1 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 The file AC500_to_OPC_Excel_Client.SYM of this example .................................. 21 4.1.1 Application Example -1- AC500/Issue: 07.2010 ...................................................ini.............................................................. 21 The file CoDeSysOPC.. 22 The file OPCServer..log of this example .........1 4...................log .......ini of this example .......... 23 Application Example -2- AC500/Issue: 07...4 Visual Basis program ............1 4..................3 The file OPCServer................................................2...................................2 The file CoDeSysOPC.........................................................2010 .................4....3..................................................................... 22 4.......... 21 4... Diese Erklärung unterliegt Schweizer Recht unter Ausschluß der Verweisungsnormen und des UN-Kaufrechts (CISG).1 Disclaimer 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. sind aber keine fertigen Lösungen. Liability: The user shall be solely responsible for the use of this application example described within this file. 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). im Falle der Verletzung des Lebens." "Gewährleistung und Haftung: Der Nutzer ist allein für die Verwendung des in dieser Datei beschriebenen Anwendungsbeispiels verantwortlich. zeigen eine mögliche Einsatzart der Steuerung. irrespective of the legal ground. Dieser Ausschluß gilt nicht im Falle von Vorsatz oder grober Fahrlässigkeit. Eine Änderung der Beweislast zum Nachteil des Nutzers ist hiermit nicht verbunden. Im Falle der teilweisen oder ganzen Übernahme der Programmierbeispiele können gegen ABB keine Ansprüche geltend gemacht werden. shall be excluded. der groben Fahrlässigkeit. ABB unterliegt keiner Gewährleistung.1 For customers domiciled outside Germany/ Für Kunden mit Sitz außerhalb Deutschlands "Warranty. bei Ansprüchen nach dem Produkthaftungsgesetz. vorhersehbaren Schaden begrenzt. Es gilt materielles deutsches Recht unter Ausschluß des UN-Kaufrechts. Der Nutzer ist für die ordnungsgemäße. The exclusion of liability shall not apply in the case of intention or gross negligence. im Zusammenhang mit den Anwendungsbeispielen oder den in dieser Datei enthaltenen Dateien wird ausgeschlossen.ist ausgeschlossen. Sie stellen nur Beispiele für Programmierungen dar. Eine Gewähr kann nicht übernommen werden. insbesondere vollständige und fehlerfreie Programmierung der Steuerungen selbst verantwortlich.2010 . ABB's liability in connection with this application example or the files included within this file. gleich aus welchem Rechtsgrund. Der Haftungsausschluß gilt jedoch nicht in Fällen des Vorsatzes.gleich aus welchem Rechtsgrund . Die Haftung von ABB im Zusammenhang mit diesem Anwendungsbeispiel oder den in dieser Datei enthaltenen Dateien ." 1. des Körpers oder der Gesundheit oder bei schuldhafter Verletzung einer wesentlichen Vertragspflicht. Die Haftung von ABB. soweit nicht zugleich ein anderer der in Satz 2 dieses Unterabsatzes erwähnten Fälle gegeben ist. Im Falle der Verletzung einer wesentlichen Vertragspflicht ist die Haftung jedoch auf den vertragstypischen. ABB shall be under no warranty whatsoever." Application Example -3- AC500/Issue: 07. OPC-Server V2.2 Introduction Often wish a customer.2009-06-05 (Build:5731. Implementation and Application".3. 5. therefore the OPC-Server V2. The idea of this application based on the example in the OPC Book. witch is included in most of the MS Office programs.3.3. AC500 PM564(FW) : V1. OPC Book. Used documents: 1. a simple tool which makes him possible to set values in the PLC. In this book described Frank Iwanitz and Jürgen Lange how it is possible to communicate with VBA (MS Visual Basic for Application).3. observe these values and work on and on with these values in a calculation tool like Microsoft (MS) Excel. Personal Computer (PC) with MS Windows XP SP3 and MS Excel 2003 SP3 (it should work also with different MS versions. among the CoDeSysHMI visualization. Online help documentation of the AC500 Control Builder PS501 Version 1.xls: MS Excel sheet with VBA program AC500 PLC project PC Excel OPC Server VBA Sheet RS485 USB TK503 Application Example -4- AC500/Issue: 07. Written by: Frank Iwanitz. "OPC . but it seems that it is not so user-friendly and therefore little known/popular.3 DA will be used.2 4. OPC-Server and Gateway (without CoDeSys) can be also installed standalone on a target PC (see „Opt.Fundamentals.  The example uses the OPC Data Access functionality.2010 .xls functionality can be easy expanded by every customer he is familiar with VBA programming.2 in the folder …\CD_AC500\CoDeSys\ServicePack\ProgramFiles\Projects\Examples\OPC\EXCEL_Client\. That is a new trial to announce this possibility.x DA (from CD AC500 Control Builder PS501 Version 1. Published by: Hüthig Fachverlag ISBN 3-7785-2904-8) The example consist of two parts: 1. OPC_Excel_Client. There is already an example on the CD AC500 Control Builder PS501 Version 1.pro: AC500eCo project with symbol and CoDeSysOPC configuration 2.Rel) 2. AC500_to_OPC_Excel_Client. with the OPCServer via an Automation Interface.  The OPC_Excel_Client. but it is not tested).2).3. TK503 programing cable 3.4. revised and extended. 2006.2 2. third edition.16:19:21.  The example can be easily adapted to the customer´s application and every type of the AC500. Used components and tools: 1. AC500 Control Builder PS501 Version 1.  The example programs allow to read 20 to 990 variables and to write 10 word variables. Jürgen Lange. 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.3. 2: Installation OPC Server”). 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.1 Set-up a new AC500 project CoDeSys <File> <New> Set the Target Settings for e.SYM readable Symbol configuration  OPC_Excel_Client. you can continue with step “Import of the example to this project (or to your existing project)” 3.ini CoDeSys OPC configuration of this example  \CoDeSysOPC\ OPCServer.1 Set-up the AC500 project For demonstration of all necessary steps we will start with a new AC500 project.zip into a folder e.3 3.xls MS Excel sheet with VBA program  \CoDeSysOPC\ CoDeSysOPC.g.pdf this application example description itself  AC500_to_OPC_Excel_Client.1 AC500 application example Start AC500 Control Builder CoDeSys V2.pro PLC application example for AC500 PM564  PROCESS_SIMULATION_OPC. AC500_OPC_Excel.g.1. If you liked to insert this example in an existing program.1.2010 . In the attachment AC500_to_OPC_Excel_Client.SDB Symbol configuration of this example  AC500_to_OPC_Excel_Client.zip there are following files:  AC500 communication with a MS Exel OPC client.1.log OPC-Server logging file 3. AC500 PM564 Application Example -5- AC500/Issue: 07.3 Commissioning instructions for the example Unzip the attachment AC500_to_OPC_Excel_Client. AC500_to_OPC_Excel_Client. Set the communication parameters: On this PC the COM13 is linked to the TK503 programming cable. In this example the TK503 programming cable is used.1.1 Connection programming system with the AC500 Connect the PC via a programming cable with the AC500. e. Application Example -6- AC500/Issue: 07.2010 .1.pro 3. Save the project CoDeSys <File> <Save As>.1.g.Enter one statement. 2 Test of the previous steps CoDeSys <Online> <Login> Download the new program CoDeSys <Online> <Run> When the AC500 is running.2010 .1. all of the previous steps were right.1. Help.1. Application Example -7- AC500/Issue: 07.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. chapter 1.2 „Fields of application of the OPC server“. 3. there are a program Process_Simulation_OPC(PRG) and a folder of global OPC variables.2.1 Insert the program Process_Simulation_OPC(PRG) into PLC_PRG(PRG) In PLC_PRG(PRG) press <F2> Select User defined Programs.2010 .1. CoDeSys <Project> <Import> PROCESS_SIMULATION_OPC. that the OPC variables are on life.1.2 Import of the example to this project (or to your existing project). Only this folder must be added later to the symbol file. Process_Simulation_OPC(PRG) OK Application Example -8- AC500/Issue: 07.3. chapter 4 “Behaviour of the OPC server”) 3. (See AC500 Control Builder PS501.EXP After that.1.1. With collecting of the OPC variables in a extra folder is it easier to reduce the number of variables. Help. The program Process_Simulation_OPC(PRG) is only for the demonstration. which have to be communicated. 2.1. Application Example -9- AC500/Issue: 07. Task configuration.2010 . select PLC_PRG(PRG) 3.3. So the CPU has time to answer the OPC request from the Server between the tasks.2.1. right mouse click. CoDeSys. insert the interval to e. t#20ms Select the task name. use a task time of 50 or 60ms. NOTICE 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.1. right mouse click. please use a task configuration.g. Resources.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.2 Task configuration Important ! Do not configure the program as a freewheeling program. Append Program Call Program Call.g Main. all of the previous steps were right. Append Task Rename the task to e.1. 3.2 Configuration of the new symbol files Application Example .1.1. chapter 3 “Use of the CoDeSys OPC server”) 3.1.1.1. <OK> <OK> 3.1 Empty existing entries in the symbol files CoDeSys.3 Symbol Configuration The configuration is described also in AC500 Control Builder PS501 (see Help. with it all variables are deselected. <Project> <Options> <Symbol Configuration> Select checkbox <Dump symbol entries> Select <Configure symbol file…> First deselect all check boxes. It is important specially in older existing projects.2010 .10 - AC500/Issue: 07.3.3.1. Enter CoDeSys.SYM is readable with e.3.SDB is created again and loaded to the gateway (path C:\WINNT\Gateway Files\ ). can be checked (see also “The file AC500_to_OPC_Excel_Client. The communication with the OPC server uses the settings of the symbol file located there.1.1. The OPC variables (items). <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.SDB were simultaneously created and stored in the project folder of the AC500 project.2010 .1. which were configured before.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.3.1. Store the program with CoDeSys <Online> <Create boot project> in the Flash memory of the AC500. <OK> <OK> 3. 3.g.3 Store project With CoDeSys <Project> <Clean all> and <Project> <Rebuild all and then File> <Save> the symbol files AC500_to_OPC_Excel_Client. Application Example .11 - AC500/Issue: 07. which will be needed in the control or visual software to avoid a high load on data transmission from PLC to OPC Server. Test of the previous step Check the time and date of the creation of these files.SYM of this example”). notepad. Test of the previous step Check the time and date of the creation of this file.SYM and AC500_to_OPC_Excel_Client. The file AC500_to_OPC_Excel_Client. When there is a configured OPC Client (how in this example). In the Single-PLC and Multi-PLC configuration are the prefixes of the OPC variables different. too.12 - AC500/Issue: 07.3 with <Windows> <Start> <Programs> >3S Software> <Communication> >CoDeSys OPC Configurator> Chose <Single PLC> or <Multi PLC> configuration.2010 .1. otherwise the variables of the OPC Client must be renamed.log. then use Multi-PLC configuration with PLC name PLC1. then all actions of the OPCServer are recorded in C:\Program Files\3S Software\CoDeSysOPC\OPCServer.3. NOTICE NOTICE For trouble shooting! Chose the check box "Log Events:".2 CoDeSys OPC Configuration Start the configuration of the OPC-Server V2. Application Example . 13 - AC500/Issue: 07. Save the OPC configuration.Chose the same communication parameters as used for the programming with AC500 Control Builder PS501. Application Example .2010 . The easiest way to do it. not only with this example.1 Setup of the Matrikon OPC Explorer The latest version of the Matrikon OPC is available on http://www. etc. is the using of a freeware OPC Client/Tool like e. 3. Softing OPC Demo Client. 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. An older version is on the AC500 Control Builder PS501.1.matrikonopc.1.EXE Next Next Next Next to Start Installation Application Example .g.2.3.1 Test of the previous Steps.2.1. Matrikon OPC Explorer. Important for trouble shooting and demarcation of errors! NOTICE A successful test makes sure that the OPC Server and its configuration are correct.14 - AC500/Issue: 07.com. Test of the OPC Configuration Basically. is it reasonable method to test now the OPC configuration.2010 . 02 (this is the name of the CoDeSys OPC-Server V 2.15 - AC500/Issue: 07.OPC.02.1.2010 .3.3 DA) and  CoDeSys.OPC. In the following picture it founds two servers:  CoDeSys.OPC.2.1. Select the server CoDeSys. Right mouse click /Add Group Application Example .DA (this is the name of the CoDeSys OPC-Server version 3).2 Test with Matrikon OPC Explorer Start the Matrikon OPC Explorer. Right mouse click/Connect Click to Server. Click to Server. The Matrikon Explorer search first the local PC for available OPC servers and indicates them. Click to Group.2010 . 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. PLC1:.OPC.2010 . then all previous steps (from chapter“Symbol file configuration”) must be repeated and checked carefully.2.zip and in the chapter “Appendix”.   Check if the time stamp of the generated files is right.xls to avoid error messages in Excel.Check the items If the Matrikon OPC Explores displays the quality “Good.17 - AC500/Issue: 07. Compare the contents of the files with the files in the attachment AC500_to_OPC_Excel_Client.word_out_00 or PLC1:. Important ! The identical names and spellings of the OPC server (CoDeSys.1. The following chapter “Check of the OPC configuration files” can be jumped over and be gone on working with the chapter “MS Excel Project”.02) and OPC variables (e. non–specific”.3 Check the OPC configuration files If the test with the OPC Client/Tool was not successfully.g. the OPC configuration is in order. NOTICE 3.word_in_04) must be used by the application OPC_Excel_Client.1. Application Example . OPC.xls. row 1) the name of the OPC-Server and from cell B11 to B1000 (empty cell are ignored) the names of the OPC items.2. Initialization of the communication.1 Working with the OPC_Excel_Client.2010 .18 - AC500/Issue: 07. 2.xls Start the program Microsoft Excel and open the file OPC_Excel_Client. 3.2. The worksheet CoDeSys. Application Example . With push “Connect” the application starts.02 is the “Control panel” for the communication with the OPC-Server.2 MS Excel Project 3. VBA program reads from cell B1 (column B.1.3.1 Raw functional sequence 1. 19 - AC500/Issue: 07. Writing values into AC500. in the cell on the left of “Write_06”.2010 . To avoid this. 3. Data exchange. 4. is it a good practice. If not.g. The blue cells are for enter the values. With push the button “Disconnect” the application stops and so the communication with the OPC-Server.NOTICE Important! The names and spellings of the OPC server (CoDeSys. With push the button e.02) and of the OPC variables (or the cells must be empty) in the yellow cells must be right. VBA program asks the OPC server for the values and writes those in the green cells. then a window with "Microsoft Visual Basic Runtime error" will be shown. will be written into the AC500. Application Example . 5. Several OPC clients can work in parallel with the OPC-Server.OPC. Stop of the application. Matrikon OPC Explorer. to check the names with e.g “Write_06” the value. how the user can design the own application with the help of standard Excel functions.20 - AC500/Issue: 07.OPC.The worksheet Overview is a simple example.2010 .2. Application Example .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. 3.02 A print out of the program is also in Appendix. ProjectId=489241 .word_out_03:WORD:5:1538:2:b:16#02000040 .word_in_08:WORD:5:1528:2:b:16#02000040 .word_out_00:WORD:5:1532:2:b:16#02000040 .Array_out[146]:WORD:4:492:2:b:16#02000020 .SDB are simultaneously created and stored in the project folder of the CoDeSys AC500 project.1 The files AC500_to_OPC_Excel_Client.word_in_04:WORD:5:1520:2:b:16#02000040 .SDB is also stored in the folder C:\WINNT\Gateway Files\ AC500_to_OPC_Excel_Client.SYM of this example .Array_out[148]:WORD:4:496:2:b:16#02000020 .1. then the file AC500_to_OPC_Excel_Client.Filesize=0 .Array_out[0]:WORD:4:200:2:b:16#02000020 … … .ini.word_in_09:WORD:5:1530:2:b:16#02000040 .2010 . The file AC500_to_OPC_Excel_Client.word_out_01:WORD:5:1534:2:b:16#02000040 .SYM is readable and can so easilly checked by the user.word_in_01:WORD:5:1514:2:b:16#02000040 .1 The file CoDeSysOPC.word_in_06:WORD:5:1524:2:b:16#02000040 . The OPCServer uses this file for the communication with the AC500.word_out_07:WORD:5:1546:2:b:16#02000040 .2.word_in_07:WORD:5:1526:2:b:16#02000040 .word_in_00:WORD:5:1512:2:b:16#02000040 .2 The file CoDeSysOPC.SYM and AC500_to_OPC_Excel_Client.word_out_08:WORD:5:1548:2:b:16#02000040 .Array_out[149]:WORD:4:498:2:b:16#02000020 .word_in_03:WORD:5:1518:2:b:16#02000040 .Array_out[147]:WORD:4:494:2:b:16#02000020 .Checksum=0 .word_in_05:WORD:5:1522:2:b:16#02000040 .word_out_02:WORD:5:1536:2:b:16#02000040 .ini of this example [Server] Application Example . When the example is loaded in the PS501 programming system into the AC500.Version=2 .rel_out_01:REAL:5:1552:4:b:16#02000040 .21 - AC500/Issue: 07.word_out_04:WORD:5:1540:2:b:16#02000040 .word_out_05:WORD:5:1542:2:b:16#02000040 . 4.word_in_02:WORD:5:1516:2:b:16#02000040 .word_out_09:WORD:5:1550:2:b:16#02000040 4.4 Appendix 4. 4.SDB.SYM and AC500_to_OPC_Excel_Client.SDB When the example is stored in the PS501 programming system.ini The result of the configuration with CoDeSys OPC Configurator is stored in C:\Program Files\3S Software\CoDeSysOPC\CoDeSysOPC.word_out_06:WORD:5:1544:2:b:16#02000040 .1 The file AC500_to_OPC_Excel_Client. the files AC500_to_OPC_Excel_Client. 07.234) Server 2.312) Gateway Version: 2.2010.11 (04. 12:39:30.2010 . 12:39:30.2010.375) <PLC1> Reconnect successful.07.1 The file OPCServer.07.' (04.2010.2010.ini).07.log of this example That is an example of a successful setting up of the connection with an OPC client.2010.log If in the CoDeSys OPC configuration the check box "Log Events:" is checked (logevents=1 in the OPCserver. 12:39:30.3.07. SYM=489241 (04.3.07.234) 1. BufferSize[B]=4800. Reconnect to <PLC1> (04.2010.2010. 12:39:30. 12:39:30.375) Timeout[ms]=10000.0 ========================================================================== Filter=0xffffffff (04. ProjectName='AC500_to_OPC_Excel_Client.3 The file OPCServer.>: PLC=489241.9. 12:39:30. Logfile for OPC-Server V2.22 - AC500/Issue: 07. 12:39:30.3 started (04. Reconnecttime[s]=10 (04.07.453) <PLC1> ProjectID matched.375) Motorola=1.546) Client attached to server (04.3.07.07. 12:39:30.2010.234) UpdateRate[ms]=200. 12:39:50.2010.07. SyncInit=1.2010.07.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. 12:39:30.2010.312) [PLC1]: ::ConnectGateway(): m_ulGatewayChannels=1 (04.453) <PLC1> 171 symbols loaded (04. then all actions of the OPCServer are recorded in C:\Program Files\3S Software\CoDeSysOPC\OPCServer.13.07. Project <AC500_to_OPC_Excel_Client.2010.log 4. NoLogin=1 (04. LogEvents=1 (04. PublicGroups=0.390) <PLC1> 171 active items Application Example . 12:39:30. 12:39:30. Waitime[s]=10. 2)) 'Item from row i. 2) = SvrSample.VendorInfo Cells(3.A useful tool for monitoring of logging file outputs in real-time is the freeware WinTail. 2006.3 '"WinCoDeSysOPC" = CoDeSys OPC Server V3 'Write ServerName to cell 'Write VendorInfo to cell 'Write ServerState to cell 'Set Checkbox value to true Cells(5.23 - AC500/Issue: 07. 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.Value = True Set GroupColl = SvrSample.AddItem(szItemId.ServerState chbSampleGroupActive. revised and extended.02" = CoDeSys OPC Server V2.IsSubscribed = True 'set Group active state with Checkboxvalue SmplSvrGroup. if no name was given Cells(6. column B) 'as OPCServer name. 2)) 'write to sheet.OPCItems If ItemColl Is Nothing Then Exit Sub TEST = ItemColl End If 'VBASample '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) = SvrSample.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 . 2)) 'Provide the OPCServer object with memory 'Takes the name of the cell (row 1.10) = ItemColl.UpdateRate '500 'There was a group name created.Fundamentals.Add(CStr(Cells(6.OPC. 2) = SmplSvrGroup. NOTICE 4.IsActive = True 'set updaterate with value in Excel sheet SmplSvrGroup.UpdateRate = CLng(Cells(7. column B If szItemId <> "" Then 'If cell is not empty. Jürgen Lange. 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 SvrSample. third edition.2010 . 2) = SmplSvrGroup. revised updaterate may be different Cells(7. 'Written by: Frank Iwanitz.Name 'VBASample 'add same items here Set ItemColl = SmplSvrGroup. i) End If i=i+1 Loop End Sub Private Sub StopSampleServer() Dim GroupColl As OPCGroups Application Example . 'With AC500 OPC-Server: "CoDeSys.Connect CStr(Cells(1.ServerName Cells(2.OPCGroups 'Add Group with given or default Name Set SmplSvrGroup = GroupColl. 'add item to collection Set SMPLItem(i .OPCItems 'Set ItemColl = SmplSvrGroup. Implementation and Application". 2))) 'allow Subscriptions SmplSvrGroup. 2) = SvrSample. 2) = "" End Sub Private Sub cmdConnect_click() cmdDisconnect. 4)) End Sub Private Sub cmdWrite_04_Click() SMPLItem(15 . 2) = "" 'clear vendorinfo Cells(3.10).Remove locGroup.OPCGroups For Each locGroup In GroupColl If Not (locGroup Is Nothing) Then locGroup.ServerHandle ItemColl. 4)) End Sub Private Sub cmdWrite_02_Click() SMPLItem(13 .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. from the cell on the left of the button 'into the addressed item of the collection object. Errors Next Item GroupColl. 4)) End Sub Private Sub cmdWrite_03_Click() SMPLItem(14 . column 4 (=D) into 'OPCItem-Object 1 (row 11 . 4)) 'Writes value from cell (row 11.Value End If End Sub Private Sub cmdDisconnect_Click() cmdDisconnect.IsActive = False Set ItemColl = locGroup.Enabled = True Call StopSampleServer End Sub 'Subroutine writes the value.10). SH.10).Dim locGroup As OPCGroup Dim ItemColl As OPCItems Dim Item As OPCItem Set GroupColl = SvrSample. 4)) End Sub Private Sub cmdWrite_05_Click() SMPLItem(16 .Write CLng(Cells(15.OPCItems For Each Item In ItemColl Dim SH(1) As Long Dim Errors() As Long SH(1) = Item. Private Sub cmdWrite_00_Click() 'ObjectName of the CommandButton SMPLItem(11 . 4)) End Sub Application Example .offset) End Sub Private Sub cmdWrite_01_Click() SMPLItem(12 .24 - AC500/Issue: 07.Enabled = False cmdConnect.Write CLng(Cells(14.10).IsSubscribed = False locGroup.2010 .Write CLng(Cells(16.Disconnect Set SvrSample = Nothing End If chbSampleGroupActive.Value = False Cells(2.IsActive = SmplSvrGroupActive.Enabled = True cmdConnect.Enabled = False Call StartSampleServer End Sub Private Sub SAMPLEGroupActive_Click() If Not (SmplSvrGroup Is Nothing) Then SmplSvrGroup.Write CLng(Cells(12.Remove 1&.Write CLng(Cells(13.10).Write CLng(Cells(11.10). 4)) End Sub Private Sub cmdWrite_07_Click() SMPLItem(18 .ClientHandle.10). qualities() As Long. it happened sometimes with mouse clicks.10). ByVal NumItems As Long.OPCItems On Error Resume Next 'For avoid "run time error 50290" 'The reason is unknown.Private Sub cmdWrite_06_Click() SMPLItem(17 .Write CLng(Cells(20. 3) = Item.Write CLng(Cells(18. TimeStamps() As Date) Dim ItemColl As OPCItems Dim Item As OPCItem Set ItemColl = SmplSvrGroup.2010 . ItemValues() As Variant. 4)) End Sub Private Sub cmdWrite_09_Click() SMPLItem(20 .10). 4)) End Sub Private Sub cmdWrite_08_Click() SMPLItem(19 .10). chja For Each Item In ItemColl Cells(Item.Write CLng(Cells(19. ClientHandles() As Long.Write CLng(Cells(17.Value 'The values read out of the OPC server 'are wrote into culumn 3 (= C) Next Item End Sub Application Example . 4)) End Sub Private Sub SmplSvrGroup_DataChange(ByVal TransactionID As Long.25 - AC500/Issue: 07. 2010 .: Helpline document Title: 29 Lang. o. kind: No.26 - AC500/Issue: 07.: AC500 communication with a MS Excel OPC client EN Application Example . p.Doc. abb. Germany 69006 Heidelberg.com Internet http://www.abb.abb ABB STOTZ-KONTAKT GmbH Eppelheimer Straße 82 Postfach 101680 69123 [email protected]/plc Manual No. Germany Telephone (06221) 701-0 Telefax (06221) 701-240 E-Mail automation-helpline. 2CDC 125 120 M0201 .
Copyright © 2024 DOKUMEN.SITE Inc.