TwinCAT ADS-Script-DLL - Reference

Active Server Pages

Active Server Pages (ASP) provide a facility for the creation of HTML pages on the HTTP server dynamically, i.e. in response to events. This is achieved by embedding script segments in the HTML code. The scripts are then executed by the web server. TcScript.dll is used for access to TwinCAT. The following example uses either the Internet Information Server (IIS) or the Personal Web Server (PWS) from Microsoft.
The generation of an instance of TcScript.dll can most easily be carried out in global.asa. The instance that has been generated is valid for all ASP pages within the web application.

global.asa:

<OBJECT RUNAT="Server" SCOPE="Application" ID="TcPLC" PROGID="TcScript.TcScriptSync"> </OBJECT>
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart()
  Call TcPLC.ConnectTo("", 801)
End Sub

</SCRIPT>


Parameters can be appended to the URL of an ASP page. These parameters are separated from the URL by a '?', and take the form VarName=VarWert. At the beginning of an ASP page a check is made for whether the parameter set has been passed, and whether the value can be converted into a number. In that case, the parameter is copied to the VBScript variable intSet, and then passed to the global PLC variable .PLCVarInt. The PLC variable is read at the end of the script, and written into the VBScript variable intActual. The PLC variable is also read out if no parameters were passed to the ASP page.
Within the HTML region, the response object (which makes the ASP available) inserts the value of the VBScript variable intActual into the HTML code, and the code is then passed to the client. In other words, every time the ASP page is called (with or without parameters) the current value of the PLC variable is displayed in the Explorer.
Forms are used within HTML in order to accept input from the user. These entries are passed as parameters to a particular page. In our example, the same page (default.asp) is called again, with set being passed as the parameter (name of the input field), along with the corresponding value that was entered by the user. Since the page is being called again with the parameter set, the value following the set parameter is written into the PLC.


default.asp:

<%@ Language=VBScript %>
<%Option Explicit
Dim intActual, intSet
Application.Lock
If Not (IsEmpty(Request.Querystring("set"))) Then
  If (IsNumeric(Request.Querystring("set"))) Then
    intSet = cint(Request.Querystring("set"))
    call TcPLC.WriteVar(".PLCVarInt", intSet)
  End if
End If
intActual = TcPLC.ReadVar(".PLCVarInt")
Application.Unlock%>

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<form method="get" action="default.asp" name="tempSet">set: <input name="set" size="4" value="<% Response.Write intSet %>"></form>
actual: <% Response.Write intActual %>
</body>
</html>

Appearance in Internet Explorer:

002

Pure HTML is sent back here to the client (Internet Explorer). It is also possible for the pages to be called by computers on which TwinCAT is not installed (e.g. a handheld PC, or even by smart phones). TwinCAT is here exclusively accessed by web servers.

The HTML page sent to the client (Internet Explorer):

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<form method="get" action="default.asp" name="tempSet">set: <input name="set" size="4" value="100"></form>
actual: 100
</body>
</html>

Unpack the example program 'Active Server Pages'.