Sample
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
![]() | 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 server 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 necessary parameters in the dialog. If an error occurs, 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 can perform ADS commands. They are invoked via a HTTP-POST method. Multiple parameters were 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:
An 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 than 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 formatted like it is in Flash, so the passing 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 necessary 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 must 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 | |
ASP.NET application | |
C# testing program | |
Flash testing application | |
Light demo |
Light demo
