• No results found

String Substitution

4 DOMAIN NAME SERVICE (DNS)

6.4 SERVER SIDE INCLUDES

6.4.5 String Substitution

The curly bracket characters ("{","}") are used to indicate that string substitution is required within a SSI directive. The curly brackets indicate that the value of the variable be substituted in the expression. For example, if the local variable _reqvar is equal to $VERSION, then the expression {_reqvar} is equal to Vx.xx where x.xx corresponds to the most recent software version..

Another example to consider is the file called example.stm and placed on the robot FR: device:

Example 6.4.5 (a) example.stm

<html>

<head><title>Example SSI file</title></head>

<body>

The value of <!#echo var="_reqvar" --> is <!--#echo var="{_reqvar}" -->

</body>

</html>

The file sent to the browser in response to http://<robotname>/fr/example.stm?_reqvar=$version is:

Example 6.4.5 (b) File Sent to Browser Resulting from example.stm

<html>

<head><title>Example SSI file</title></head>

<body>

The value of $VERSION is "V6.xx 02/13/xxxx"

</body>

</html>

NOTE

In this case, the request could have been generated through a form where any variable is input and the value is echoed back.

6.4.6 #ECHO Command

The #ECHO command will replace the argument with the current value of the argument. The argument can be any system variable, program variable, I/O point, local variable, or global variable. The current value of the argument will replace the SSI directive in the response sent to the client browser.

NOTE

Digital I/O values will show as "ON" or "OFF.”

Examples

The following illustrate various uses of this SSI directive:

• <!--#echo var="DIN[1]" --> is replaced by ON

• <!--#echo var="GPIN[2]" --> is replaced by 3

• <!--#echo var="[myprog]partcount" --> is replaced by 72

• <!--#echo var="_1var1" --> is replaced by Fault#1

• <!--#echo var=$numreg[3] --> is replaced by 22

• <!--#echo var="GPIN[_stylenum]" --> is replaced by 8

In each case the argument is evaluated for string substitutions based on curly/square brackets before the final value is placed in the response to the client browser. Also, the I/O points must be configured on the robot.

• TPOUT /*teach pendant digital output*/

• WDI /*weld inputs*/

• WDO /*weld outputs*/

• UOPIN /*user operator's panel input*/

• UOPOUT /*user operator's panel output*/

• LDIN /*laser DIN

• LDOUT /*laser DOUT*/

• WSIN /*weld stick input*/

• WSOUT /*weld stick output*/

• Analog/Group Types (return value is the numeric value of the port):

• GPIN /*grouped inputs*/

The #INCLUDE command places other files from the robot in the current response to the browser. Many files on the controller are generated upon request (such as MD:ERRACT.LS for an active alarms) so these included files can also include dynamic data.

NOTE

Other .STM files can be included and these will also be processed for SSI directives.

The following examples illustrate various uses of the SSI directive:

Table 6.4.7 SSI Directives Examples

Directive Description

<PRE><!—#INCLUDE FILE=“MD:ERRALL.LS” —></PRE>. Is replaced by contents of MD:ERRALL.LS

<pre><!--#include file="md:errall.ls" --></pre> Is replaced by ASCII listing of abortit.tp

<!--#include file="fr:¥somefile.stm" --> Is replaced by results of fr:¥somefile.stm

The HTML preformat specifier is needed when the requested file is not structured as an HTML document.

This is because of items such as carriage returns are not interpreted within an HTML document.

There are two considerations to nesting .STM files:

• Nesting is currently allowed to three levels.

• The local variables in one .STM file are not available to another .STM file (even when nested).

Global variables are always available and include the query string from the initial request.

6.4.8 #EXEC Command

The #EXEC command allows non-motion KAREL programs to be run within processing of the .STM file.

The results of these commands are automatically placed in the response to the client browser.

NOTE

The Server Side Include feature uses the same mechanism and follows the same rules but enables the capability within the .STM file processing using the #EXEC command.

Examples

The following example demonstrates this capability:

• The "%20" is a space (ASCII value of a space is 20). This is needed since spaces are not considered valid URL syntax. If you enter spaces in a URL some browsers (IE) will automatically change them to the % encoding, while other browsers (Netscape) return an error indicating the URL is invalid. The code of a "$" is %24.

• <!--#exec cmd ="KAREL/web_demo?{_Query_STR}" -->

• Run the non-motion KAREL program web_demo.pc and passes in arguments from the global variable _QUERY_STR.

• The KAREL program is responsible for writing RD:RESPONSE.HTM. This file will be included automatically and an error is generated if it does not exist.

The system variable associated with running KAREL programs must be set to allow execution of these commands. Refer to Section 6.2 for information on setting up the web server.

6.4.9 #SET Command

The #SET command is used to set the name and value of a local variable. Refer to Section 6.4.4 for details on maximum lengths and naming requirements.

NOTE

If the variable name already exists and the #SET command is issued, the value of the local variable is modified.

Examples

See the following #SET Command examples:

• For example, the following command will set the name of a local variable to _1var1 and the value to 12:

Example 6.4.9 (a) Set the Name of a Local Variable

<!--#set var="1var1" value="12" -->

• A subsequent command to set _1var1 will update the value:

Example 6.4.9 (b) Update the Value of the Local Variable

<!--#set var="1var1" value="15" -->

NOTE

Values are always set to uppercase.

6.4.10 #IF, #ELIF, #ELSE, #ENDIF

Conditional expressions allow results sent to the browser to be based on some condition. The conditional expression can allow the active alarms to be included only if the robot were faulted as one example.

Conditionals can be nested three levels deep. All comparisons are string comparisons unless both arguments are strictly numeric in which case a numeric compare is done. Three comparison operators are supported: >,<,=. String comparisons are not case sensitive. All conditional blocks must begin with #IF.

All conditional blocks must end with #ENDIF. The #ELSE command must come after #IF and #ELIF if it is used.

Examples

The following file called example.stm is placed on the robot FR: device:

Example 6.4.10 (a) example.stm

<html>

<head><title>Example SSI file</title></head>

<body>

<!--#if expr="tpout[1] = on" -->

<P><STRONG>ROBOT IS FAULTED!</STRONG></P>

<pre><!--#include file="md:erract.ls" --></pre>

<!--#ELSE -->

<P><STRONG>ROBOT IS NOT FAULTED!</STRONG></P>

<!--#ENDIF -->

</body>

</html>

The file sent to the browser in response to http://<robotname>/fr/example.stm (assuming robot is not faulted based on teach pendant fault LED being off) is:

Example 6.4.10 (b) File Sent to the Browser Resulting from example.stm

<html>

The #PRINTENV command is useful for debugging. It outputs all the local and global variables each time it is called. This can be a quick way to identify problems with data being passed into the .STM file through a URL request. Or it can help with problems with handling local variables.

NOTE

The HTML preformat specifier is recommended for more readable results.

Examples

The SSI directive <PRE><!--#PRINTENV --></PRE>will return the following result:

Example 6.4.11 Result of #PRINTENV SSI Directive _MYVAR : 12

_LVAR1 : MYPROG

_URL : /fr/example.stm?_myvar=12 HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,

application/vnd.ms-excel, application/msword, application/vnd.mspowerpoint,

*/*

Accept-Language: en-us

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt) Host: remora

See Example 6.4.12(a) for SSI directive examples.