Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Interfacing Flash via ASP/ASP.NET

Beckhoff Knowledge Base: Communication - Interfacing Flash via ASP/ASP.NET

Introduction

The following sample shows how to establish a communication between TwinCAT and Flash.

Prerequisites

Software

Microsoft Windows 2000/XP/2003/CE

TwinCAT PLC (version 2.10 or higher)

Macromedia (Adobe) Flash (version 8 or higher)

(If necessary) Microsoft Visual Studio (version 7.1 (".NET 2003") or higher)

Working knowledge

Programming TwinCAT PLC-Control

Communication via ADS

Creating Flash-Animations

Programming ASP and/or .NET

Installing ASP/ASP.NET applications on IIS (Internet Information Service) (version 5 or higher) and/or ASP applications on Windows CE (version 4.2 or higher)

Testing the ASP(X)-page

Information: It is not possible to view Flash pages in the Internet Explorer of a Beckhoff CX1000 system with Windows CE. These systems can only work a servers for those pages.
For simple testing you can use the attached testing program or the Flash testing application.
With these tools the corresponding HTTP requests can be invoked. You can insert the neccesary parameters in the dialog. If an error occures it will be displayed in the status bar. A correct response will be displayed in the text field 'HTTP-Response'.

Functioning

The ASP(X) pages are able to perform ADS commands. They are invoked via a HTTP-POST method. Multiple parameters where added to this request to submit which ADS command should be performed (with which values). The response consists of a string instead of a HTML page. This string contains the requested values and possible errors.

Information:

A alternative way of solving this problem would be the usage of the TwinCAT Ads-WebService. At the time when this documentation was created the Flash-WebService inplementation has had an error in its memory management. This error caused a stop of the communication after a few days of running. Furthermore the way of communication mentioned in this documentation is much faster then via SOAP, because the structure of the protocol is simpler. This can be noticed especially on low-performance systems (e.g. PDA's).

The following examples are made with the Flash testing application. The ASP page and the PLC are installed on a Beckhoff CX1000 system (with Windows CE).

Example 1 (Reading of INT16 values):

HTTP-Request

POST /TcAdsHTTPWrapper/TcAdsHTTPWrapper.asp HTTP/1.1
Accept: */*
x-flash-version: 8,0,22,0
Content-Type: application/x-www-form-urlencoded
Content-Length: 81
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: (...)
Host: (...)
Connection: Keep-Alive
Cache-Control: no-cache

IndexOffset=30&IndexGroup=16416&Port=801&AmsNetId=5%2E0%2E226%2E138%2E1%2E1&Cmd=3

The following parameters are submitted to the ASP page:

'IndexGroup' & 'IndexOffset' : Describe the memory address of the value (in this case byte 30)

'AmsNetId' & 'Port' : Indicates the PLC and its runtime system [Dots ('.') may be used as well as '%2E'].

'Cmd' : Indicates the number of the method to perform (in this case '3' for 'reading an INT16 value')

HTTP-Response

HTTP/1.0 200 OK
Date: (...)
Server: Microsoft-WinCE/5.0
Expires: (...)
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
Content-Length: 16

&data=198&eof=1&

As mentioned above only a string is returned. It is formated like it is in Flash, so the pasing of this string is simple.

'&' : Separator

'eof=1' : Termination

'data' : Describes the value of the variable to read

Example 2 (Writing of INT16 values):

HTTP-Request

POST /TcAdsHTTPWrapper/TcAdsHTTPWrapper.asp HTTP/1.1
Accept: */*
x-flash-version: 8,0,22,0
Content-Type: application/x-www-form-urlencoded
Content-Length: 90
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: (...)
Host: (...)
Connection: Keep-Alive
Cache-Control: no-cache

Data=123&IndexOffset=30&IndexGroup=16416&Port=801&AmsNetId=5%2E0%2E226%2E138%2E1%2E1&Cmd=7

'Data' : Describes the value to write

HTTP-Response

HTTP/1.0 200 OK
Date: (...)
Server: Microsoft-WinCE/5.0
Expires: (...)
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
Content-Length: 7

&eof=1&

Example 3 (Reading of BOOL arrays):

HTTP-Request

POST /TcAdsHTTPWrapper/TcAdsHTTPWrapper.asp HTTP/1.1
Accept: */*
x-flash-version: 8,0,22,0
Content-Type: application/x-www-form-urlencoded
Content-Length: 89
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: (...)
Host: (...)
Connection: Keep-Alive
Cache-Control: no-cache

Count=3&IndexOffset=30&IndexGroup=16416&Port=801&AmsNetId=5%2E0%2E226%2E138%2E1%2E1&Cmd=2

'Count' : Indicates the number of array-elements

HTTP-Response

HTTP/1.0 200 OK
Date: (...)
Server: Microsoft-WinCE/5.0
Expires: (...)
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
Content-Length: 19

&data=1|0|1|&eof=1&

'|' : Seperator for the single values of the array

Implementation into Flash

Example 1 can be realized by the following ActionScript:

At first the initialising variables must be set up:

var URL              : String   = "";
var HTTPCommand      : String   = "";
var Cmd              : Number   = 0;
var AmsNetId         : String   = "";
var Port             : Number   = 0;
var IndexGroup       : Number   = 0;
var IndexOffset      : Number   = 0;
var Data             : Number   = 0;
var HTTPResponseData : String   = "";
var Request          : LoadVars = new LoadVars();
var Response         : LoadVars = new LoadVars();
var submitListener   : Object   = new Object();

With the following operation the result is salvaged:

Response.onData = function(raw)
{
   if (raw == undefined)
   {
      HTTPResponseData = "Error";
   }
   else
   {
      HTTPResponseData = unescape(raw);
   }
}

Now the neccesary values must be filled in:

URL                 = "http://(...)/TcAdsHTTPWrapper/TcAdsHTTPWrapper.asp";
HTTPCommand         = "POST";

This shows how to attach the parameters to the HTTP request:

Request.Cmd         = 3;
Request.AmsNetId    = "5.0.226.138.1.1";
Request.Port        = 801
Request.IndexGroup  = 16416
Request.IndexOffset = 30

With the following method call the communication is started:

Request.sendAndLoad(URL,Response,HTTPCommand);

The result can be found in the variable "HTTPResponseData".

Project files

Two different possibilities are below-mentioned here.

The first is the ASP.NET application. This is only eligible for servers who support ASPX applications.
You have to compile this application first and add it to the IIS.

The second is the ASP page, which can be used for servers who do not support ASPX applications (.NET Compact Framework V1.1).
This page can be copied directly to the corresponding web folder (e.g. '\hard disk\www' on Windows CE).

Project type | Project files
ASP application | TcAdsHTTPWrapper.zip
ASP.NET application (for .NET-Framework 1.1) | TcAdsHTTPWrapperNET.zip
C# testing program | TcAdsHTTPWrapperTest.zip
Flash testing application | TcAdsFlashTest.zip
Light demo | TcAdsFlashLightDemo.zip

Light demo: