Download DDE Communication Between InTouch...
DDE Communication Between InTouch, Excel, and the I/O Servers All Tech Notes and KBCD documents and software are provided "as is" without warranty of any kind. See the Terms of Use for more information. Topic#: 000254 Created: June-26-1996
Summary DDE communication between Wonderware® InTouch™, Microsoft Excel and the
Wonderware® I/O servers can be configured in different ways, depending on the requirements of the application. This is a guide that will help you choose which types of DDE links are best for your application and how to quickly set up the links. The types of DDE links are:
"Hot" links – a continuous Read and/or Write operation; where one or more DDE channels are opened by the client application and where the client is advised by the I/O Server whenever the data points are changed. "Cold" links – a Read or Write operation that is performed only once; where a client application opens a DDE channel to a I/O Server program, pokes information or requests information from the I/O Server, then finally closes the DDE channel.
Wonderware Technical Support recommends that you use DDE cold links, where possible. Since hot links are always open and constantly updating, they will consume memory and CPU time on your computer. This could cause other applications that are running on your computer to slow down. And, since you need a link for every variable, your computer's memory and system resources can quickly be consumed as your InTouch application grows. Cold links use only the CPU time when they are executed — then then only on a one-time basis. Also, instead of using one DDE link per variable, you can open a DDE channel (link) and access all the variables' data, then close the DDE channel. This makes the InTouch-Excel DDE link very efficient. There are times when using a DDE hot link makes sense. In general, if you have about 30 DDE links or less, then it should be O.K. to use hot links to extract data from your InTouch application. But it will depend on your application, so you may need to perform some trial and error. Typically, InTouch is used with a I/O Server and Excel to read data from a PLC, display it in an InTouch window or write it to an Excel file for archiving, printing, data manipulation, and so on. Excel can also write the data to InTouch or the I/O Server using recipes or other formats. Or, Excel can read the data from the I/O Server to
produce reports, batch logs, and so on. There can be three types of DDE links which are described below: 1. InTouch to I/O Server – InTouch requests data from or writes data to the DDE server. 2. Excel to I/O Server – Excel requests data from or writes data to the I/O Server. 3. InTouch and Excel InTouch requests data from or writes data to Excel. o Excel requests data from or writes data to InTouch. o
Here is how to configure the three DDE links: Step 1 InTouch to I/O Server – InTouch is the client application. These DDE links are set up automatically. You only need to define the DDE tags in InTouch. All data points that are read from the PLC via the I/O Server need to be defined as DDE tagnames in InTouch. For example, here is a typical DDE tag for the Modbus I/O Server: Tagname: Type: DDE Access name: Application/server name: DDE Topic Name: Item:
Temperature1 DDE Real PLC1 Modbus PLC1 40000
Then, for InTouch and the I/O Server to communicate with each other, you need to define a DDE topic in the Modbus server called "PLC1". You can choose any name for the topic as long as it matches the DDE topic name in the I/O Server. (The topic names are case insensitive, but make sure there are no spaces at the end of the topic name.) The tag Temperature1 can now be linked to an analog input touch link so that when a new value is entered in InTouch (setpoint), it will be written to the PLC via the I/O Server. Or, Temperature1 could be linked to an analog value output where it could display the current value of the PLC register 40000 (the actual process value). When WindowViewer starts up or when Temperature1 is active*, InTouch tells the DDE server that the data point needs to be updated. Once the server is initialized, it will monitor the point in the PLC and it will advise InTouch when it changes. If the tag is not active in InTouch or its value is unchanged in the PLC, then the I/O Server will not advise InTouch of the point's value. This efficient communication between InTouch and the I/O Server.
Note An InTouch tag is active under one of six conditions:
The tag is displayed in an active InTouch window. The tag is in one of the six types of scripts. The tag is being alarmed.
The tag is being trended. The tag is being logged. The tag is being accessed by another node through NetDDE.
To set up an input touch link in InTouch so that you can write values to a PLC, do these steps: 1. Start up your InTouch application under WindowMaker. Open a window, choose the text tool in the toolbox, and type the "#" character on the window. 2. Double click the "#" character, choose Analog input touch link, and type "Temperature1" for the tagname. 3. Save your changes in the InTouch application and select the menus / File / WindowViewer. 4. To test the link, click the input field and enter a number. You should then see it written to the PLC.
Step 2 Excel to I/O Server – Excel is the client application. You can set up either a DDE hot link or cold link. The hot link requires entering a formula in an Excel spreadsheet cell that specifies the application and the DDE topic and item names. This is useful if you want to monitor the current value in a PLC address. For example, to set this up for the Modbus server, you would enter this in the spreadsheet cell: =Modbus|PLC1!'40000'. It is more useful to use a cold link where Excel could make requests from the DDE server or poke values to the I/O Server at a specified time according to a macro that you write in Excel. The following macros could be used in Excel and triggered by the SendKeys function in an InTouch script: RequestMacro - Channel=INITIATE("Modbus","PLC1") {This opens a DDE channel to the server} Data=REQUEST(Channel,"40000") {Puts data from PLC register 40000 in "Data"} =TERMINATE(Channel) {This terminates the DDE channel} =RETURN() {End of macro} PokeMacro - Channel=INITIATE("Modbus","PLC1") {This opens a DDE channel to the server} =POKE(Channel,"40000",Sheet1.xls!r1c1){Pokes value in r1c1 of sheet1.xls into 40000} =TERMINATE(Channel) {This terminates the DDE channel} =RETURN() {End of macro} These two Excel macros read or write values to and from a PLC through Excel and the DDE server. To read or write to more than one address, you need to use a Request or Poke command for each address. You can trigger these macros to run based on a time or an event. To use trigger by time, monitor the InTouch system variables $Hour, $Minute and $Second and perform a Sendkeys function at the desired time. To trigger by an event, link the Sendkeys function to an event in an InTouch script. If desired, you can start up Excel first, then load the Excel macro sheet and/or worksheet when the script is triggered.
Follow these steps to define, trigger and run a macro that would access the values of PLC address 40000: 1. In Excel, select the menus / File / New / Macrosheet. 2. Click the cell R1C1 and select / Formula / Define Name. Type in Name: RequestMacro. Click the Command button and press the keys. 3. In R1C1, enter the above request macro exactly, starting with the title RequestMacro - . 4. In your InTouch application, create an Pushbutton Action script and enter the following lines for "On Button Down": ActivateApp "Microsoft Excel" {The title must be same as in Task List}. SendKeys "^(R)"; {This Ctrl + R IS case sensitive}. 1. Start up the I/O Server, InTouch, and Excel and open the Excel macrosheet. 2. Click the Action pushbutton to run the request macro. 3. To view the data temporarily in Excel, select the Excel menus / Formula / Define Name, scroll down to 40000, and single click it. The value of register 40000 should display in the "refers to" data box. To move your data to an Excel worksheet will be covered later in this note.
Step 3a InTouch to Excel – If InTouch is going to read values from or write values to Excel, then the tagnames need to be defined as DDE tags. The link between InTouch and Excel will be set up automatically with InTouch as the client and Excel as the server. As an example, here is how the tagname Temperature1 would be defined: Tagname: Type: DDE Access name: Application/server name: DDE Topic Name: Item:
Temperature1 DDE Real Sheet1.xls Excel Sheet1.xls R1C1
The current value of Temperature1 in InTouch would display in row 1, column 1 of SHEET1.XLS in Excel. Also, a value entered in row 1, column 1 would be written to Temperature1. This acts as a two-way link so that a value entered in InTouch will automatically update in Excel, and a value entered in Excel will automatically update in InTouch. The disadvantage is that a value could be entered on top of the data on the receiving end, thus corrupting data integrity. El valor actual de Temperature1 en InTouch exhibiría en la fila 1, columna 1 de SHEET1.XLS en Excel. También, un valor incorporado en la fila 1, columna 1 sería escrito a Temperature1. Esto actúa como acoplamiento de dos vías de modo que un valor incorporado a InTouch se ponga al día automáticamente en Excel, y un valor incorporado a Excel se ponga al día automáticamente en InTouch. La desventaja es que
un valor se podría incorporar encima de los datos sobre el lado receptor, integridad de datos así de la corrupción.
Step 3b Excel to InTouch -- It is better to have Excel acting as the client and InTouch as the server. You can set up a hot link or cold link. The hot link would consist of a formula entered in an Excel spreadsheet cell that would read the current value of a tagname in InTouch. Enter a formula similiar to this: =View|Tagname!Temperature1 (where Temperature1 is our example DDE tag). More useful is to set up cold links where Excel would request data from and poke data in the InTouch application just one time based on an Excel macro. Here are some examples of a request and a poke macro: RequestMacro Channel=INITIATE("View","Tagname") {This opens a DDE channel to View} Data=REQUEST(Channel,"Temperature1") {Puts Temperature1 value in "Data"} =TERMINATE(Channel) {This terminates the DDE channel} =RETURN() {End of Macro} PokeMacro Channel=INITIATE("View","Tagname") {This opens a DDE channel to View} =POKE(Channel,"Temperature1",Sheet1.xls|R1C1) {Pokes value in r1c1 of sheet1.xls into Temperature1} =TERMINATE(Channel) =RETURN() {End of Macro} These two macros allow you to read or write values to InTouch by using Excel. If you want to read or write to multiple addresses, then you need to use a request or poke statement for each address. Again, you can trigger these macros by time or event. Thus, you can use the same macro example that is listed in the section "2) Excel to DDE server".
For Report Generation: Given the above information, you may be able to visualize how you generate reports or download recipes in your InTouch application. Here are two cases for generating reports:
Case 1: Values are read from InTouch or a I/O Server using cold links. Case 2: Values are read from InTouch or a I/O Server using hot links.
Case 1
An InTouch script executes a Sendkeys function to run the Excel macro or macros. An Excel request macro gets the data either from the InTouch tagnames or directly from the I/O Server, then copies the data to an Excel worksheet and inserts a line for the next sampling of data. At the desired time, an Excel Print macro is run to generate a report of the data that was acquired from the Excel request macro.
Case 2
An Excel spreadsheet contains DDE hot links for the variables that is to be included in a report. (Note: This is a viable solution if you have 30 or less variables to report.) An InTouch script executes a Sendkeys function to run the Excel macro or macros. An Excel Move macro moves (copies) the data from the spreadsheet cells with the active DDE links to other worksheet cells. Then the macro inserts a line for next sampling of data. At the desired time, an Excel Print macro is run to generate a report of the data that was acquired using the above sequence.
For Recipe Download: Case 1: Enter the values in Excel and run an Excel macro that pokes the values to the I/O Server. Case 2: Enter the values in an InTouch application using DDE tags which will later be written to an Excel spreadsheet. Use a Pushbutton Action script to execute a Sendkeys function to initiate an Excel poke macro that will pokes the values from Excel to the PLC. Case 3: Define recipes in Excel spreadsheets. Then, use a Pushbutton Action script in InTouch to load the Excel spreadsheet and/or macrosheet by executing a Sendkeys function that runs a poke macro which write theses the values to the PLC. Here is an example of generating a report using Case 1 which uses ten tagnames that are read from InTouch: First, define an Application script in InTouch. Set the scan rate to the interval at which you want to sample the data. Type in the following script. ActivateApp "Microsoft Excel" SendKeys "^(R)"; SendKeys "^(M)"; SendKeys "^(S)"; SendKeys "^(I)"; This script will trigger Excel macros that will read the InTouch data and copy it to an Excel spreadsheet. Then, monitor a time variable in InTouch and execute a Sendkeys
function at the appropriate time to trigger the printing of the report. Here is a Condition script that accomplishes this task: Condition: If $Hour == 16 AND $Minute == 30 AND $Second == 00 ON True ActivateApp "Microsoft Excel"; SendKeys "^(P)"; ActivateApp "InTouch WindowViewer - C:\Excel_App"; This example script will print a report at 4:30:00 pm and bring WindowViewer window back into the focus so that the report printing is transparent to the user. Here are the Excel macros can accomplish these functions are listed below. RequestMacro - Ctrl R Channel=INITIATE("View","Tagname") {Opens a DDE channel to View} Data1=REQUEST(Channel,"Temperature1") {Reads value of temperature1 into "Data1"} Data2=REQUEST(Channel,"Temperature2") {Reads value of temperature2 into "Data2"} Data3=REQUEST(Channel,"Temperature3") . Data4=REQUEST(Channel,"Temperature4") . Data5=REQUEST(Channel,"Temperature5") . Data6=REQUEST(Channel,"Temperature6") Data7=REQUEST(Channel,"Temperature7") Data8=REQUEST(Channel,"Temperature8") Data9=REQUEST(Channel,"Temperature9") Data10=REQUEST(Channel,"Temperature10") =TERMINATE(Channel) {Closes the DDE channel to View} =Return() MoveMacro - Ctrl M =FORMULA(Data1,'Sheet1.xls'!R1C1) {This macro will move the values in =FORMULA(Data2,'Sheet1.xls'!R1C2) {Data1-Data10 to row1 in sheet1.xls} =FORMULA(Data3,'Sheet1.xls'!R1C3) =FORMULA(Data4,'Sheet1.xls'!R1C4) =FORMULA(Data5,'Sheet1.xls'!R1C5) =FORMULA(Data6,'Sheet1.xls'!R1C6) =FORMULA(Data7,'Sheet1.xls'!R1C7) =FORMULA(Data8,'Sheet1.xls'!R1C8) =FORMULA(Data9,'Sheet1.xls'!R1C9) =FORMULA(Data10,'Sheet1.xls'!R1C10) =RETURN() StoreMacro - Ctrl S =ACTIVATE("Sheet1.xls") {This macro moves the values from row1} =SELECT("R1C1:R1C10") {to a location in the spreadsheet to be} =COPY() {archived for a report} =SELECT("R11C1:R11C10") =PASTE() =RETURN()
InsertMacro - Ctrl I =ACTIVATE("SHEET1.XLS")
{This macro shifts the values down one}
=SELECT("R11C1:R11C10") {row and inserts a blank line for next} =COPY() {sampling of data} =SELECT("R11C1:R11C10") =INSERT(2) =RETURN() PrintMacro - Ctrl P =ACTIVATE("SHEET1.XLS") {This macro selects an area of 29 rows of} =SELECT("R11C1:R40C10") {data to be printed.(You could choose as} =SET.PRINT.AREA() {as much data as you like to be printed)} =PRINT(1,,,1,FALSE,FALSE,1,FALSE,1) =RETURN() For technical support questions, send an e-mail to
[email protected].
back to top ©2012 Invensys Systems, Inc. All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying, recording, broadcasting, or by any information storage and retrieval system, without permission in writing from Invensys Systems, Inc.