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 sample uses the Internet Information Server (IIS) or the Personal Web Server (PWS) from Microsoft.
Creating a TcScript.dll instance can be done most easily in the global.asa. The created instance is valid within the web application for all ASP pages.
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 have the structure 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 if no parameter was passed to the ASP page.
Within the HTML area the value of the VBScript variable intActual is inserted into the HTML code via the response object (provided by ASP) and transferred to the client. I.e. every time the ASP page is called (with or without parameters), the current value of the PLC variable is displayed in the explorer.
To accept input from the operator, forms are used within HTML. These entries are passed as parameters to a particular page. In our sample, the same page (default.asp) is called again. set is passed as a parameter (name of the input field), with the corresponding value entered by the operator. 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>
Presentation in Internet Explorer:
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 smartphones). 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 sample program ADS-Script-DLLSample03.zip, 'Active Server Pages'.