AC500 Communication With A MS Excel OPC Client
AC500 Communication With A MS Excel OPC Client
abb
Content
1 Disclaimer ..................................................................................................................3
1.1 For customers domiciled outside Germany/ Fr Kunden mit Sitz auerhalb Deutschlands............................................................................................................ 3 1.2 Nur fr Kunden mit Sitz in Deutschland ......................................................................... 3
2 3
3.1.1
3.1.1.1
3.1.2
3.1.2.1
3.2
3.2.1 3.2.2
3.2.1.1
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
4.2
4.2.1 4.3
The file OPCServer.log ................................................................................................... 22 The file OPCServer.log of this example .................................................................. 22
4.3.1 4.4
Application Example
-2-
AC500/Issue: 07.2010
1 Disclaimer
1.1 For customers domiciled outside Germany/ Fr Kunden mit Sitz auerhalb 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)." "Gewhrleistung und Haftung: Der Nutzer ist allein fr die Verwendung des in dieser Datei beschriebenen Anwendungsbeispiels verantwortlich. ABB unterliegt keiner Gewhrleistung. 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 Fahrlssigkeit. Diese Erklrung unterliegt Schweizer Recht unter Ausschlu der Verweisungsnormen und des UN-Kaufrechts (CISG)."
Application Example
-3-
AC500/Issue: 07.2010
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 Jrgen 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 customers 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, Jrgen Lange; Published by: Hthig 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
AC500
PLC project
PC
Excel OPC Server VBA Sheet
RS485
USB
TK503
Application Example
-4-
AC500/Issue: 07.2010
Application Example
-5-
AC500/Issue: 07.2010
3.1.1.1.1
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
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
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
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
Application Example
-8-
AC500/Issue: 07.2010
3.1.1.2.2
Task configuration
Important ! Do not configure the program as a freewheeling program, please use a task configuration. 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, 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
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
3.1.1.3.1
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
Application Example
- 10 -
AC500/Issue: 07.2010
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
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
NOTICE
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
Chose the same communication parameters as used for the programming with AC500 Control Builder PS501.
Application Example
- 13 -
AC500/Issue: 07.2010
3.1.2.1.1
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
Application Example
- 14 -
AC500/Issue: 07.2010
3.1.2.1.2
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.
Application Example
- 15 -
AC500/Issue: 07.2010
Click to Group, Right mouse click /Add Items Add to Tag List or Add All Items to Tag List
Application Example
- 16 -
AC500/Issue: 07.2010
If the Matrikon OPC Explores displays the quality Good, nonspecific, 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. 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.
NOTICE
3.1.2.1.3
If the test with the OPC Client/Tool was not successfully, then all previous steps (from chapterSymbol 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
The worksheet CoDeSys.OPC.02 is the Control panel for the communication with the OPC-Server.
Application Example
- 18 -
AC500/Issue: 07.2010
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
The worksheet Overview is a simple example, how the user can design the own application with the help of standard Excel functions.
Application Example
- 20 -
AC500/Issue: 07.2010
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.
Application Example
- 21 -
AC500/Issue: 07.2010
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
Application Example
- 22 -
AC500/Issue: 07.2010
A useful tool for monitoring of logging file outputs in real-time is the freeware WinTail. NOTICE
Set GroupColl = SvrSample.OPCGroups 'Add Group with given or default Name Set SmplSvrGroup = GroupColl.Add(CStr(Cells(6, 2))) '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
'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)) '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
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
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
Doc. kind:
No. o. p.:
Helpline document
Title:
29
Lang.:
EN
Application Example
- 26 -
AC500/Issue: 07.2010
abb
ABB STOTZ-KONTAKT GmbH Eppelheimer Strae 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