Servlets are described above, and in detail at the Sun website Java tutorial listed above. SmartPage is a particular servlet that is quite useful for displaying live data from a SoftPLC. SmartPage works by filtering an HTML page looking for hyperlinks that are in a special format. The modified HTML page is created in memory on the fly and streamed to the browser with live process information in it.
The input HTML files that are processed by this servlet have the same name as the request URI, except the extensions are different. The request URI must end in ".stp", whereas the input files must be the same root filename but with an extension of ".htm". So for example, a URI of somefile.stp would invoke the SmartPage servlet and cause it to look for somefile.htm as its input for this request. You can have any number of input files, so the utility of this servlet is quite good.
Here is the sequence of events:
- URI: somefile.stp comes into weblet.
- weblet sees from SERVER.LST that URI’s with extensions of ".stp" are to be sent to the SmartPage servlet.
- SmartPage servlet is run, passing it the request URI somefile.stp.
- SmartPage servlet swaps the trailing ".stp" with ".htm" and looks for somefile.htm and processes that file through its filter mechanism.
To embed dynamic information you put one of 3 types of special hyperlink URL macros into the input file: @DecimalFmt(), @TextChoice(), or @ImageChoice(). You simply add a hyperlink with your HTML editor and instead of keying in a URL to jump to, you key in one of the macros. The text or image that holds the hyperlink will not be shown, but rather it will be removed in favor of whatever the chosen macro produces.
Pay close attention to spaces within the macro specification, avoiding them unless specifically called for.
This macro substitutes the hyperlinked text or image with a numeric decimal string whose current value is determined by a SoftPLC data table word. This macro takes two parameters:
- address is some data table word address such as I:0, B3:34, N23:456, T4:0.ACC, PD13:23.SP or F8:12. Bits, structures, strings and indirect addresses are not supported.
- format specifies how the value is to appear, including whether the displayed value is to have leading zeros and/or a decimal point.
@DecimalFmt(PD13:0.SP,#.0) will display as an integer the value of the Setpoint word of the structure PD13:0.
@DecimalFmt(F8:0,#.000) will display the value of F8:0 as a fixed decimal with 3 places after the decimal
A DecimalFormat comprises a pattern and a set of symbols that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). The underlying formatting mechanism used is the standard Java API DecimalFormat object, which is described at DecimalFormat.
The table below includes some commonly used examples. Refer to the previous link for a very detailed description. Basically, "#" means to place a number in this location, if it is available, and "0" means to place a number if it is available, otherwise place a zero. Other symbols like "%" and "$" can be used normally.
|SoftPLC Value||DecimalFmt "format" parameter||Displayed result|
To dynamically display a certain word or words based on a value in the SoftPLC, TextChoice can be used. This macro takes at least 6 parameters.
- address: PLC Data Table address whose value will determine the text to be displayed.
- bitmask: hex value bitmask (given in 0xABCD format) that will be ANDed with the word at address to yield a set of important bits. If all 16 bits are important, then use 0xFFFF.
- defaultText: default text to display when none of the other bit comparisons match.
compare1: equality comparison bitmask. The algorithm is:
if ( bitmask AND address ) = compare1 then Use text1
- text1: displayed on the HTML page if the above algorithm succeeds.
- [comparen, textn]: additional pairs of these may follow, as many as is needed.
For example, the tag below would show "on" when the value PD13:4.0 has the first bit set to 1, "off" if the bit is set to 0, and "error" on any other case.
<a href="@TextChoice(PD13:4.0,0x1,'error',0x1,'on',0x0,'off')"> </a>
Below are some examples with sample values in a PLC (in binary, hex and decimal), the bitmask, and the result if they were to be ANDed together. Following that is a TextCoice tag and the result if it were used with the given parameters and the mentioned values.
Binary Hex Dec 8 4 2 1 0 1 1 0 0x6 6 Value in PLC AND 0 0 1 0 0x2 2 Bitmask = 0 0 1 0 0x2 2 Result <a href="@TextChoice(N7:2,0x2,'off',0x2,'on')"> </a> = on
Binary Hex Dec 8 4 2 1 0 1 1 1 0x7 7 Value in PLC AND 1 1 0 1 0xD 13 Bitmask = 0 1 0 1 0x5 5 Result <a href="@TextChoice(N7:2,0xD,'off',0x5,'on')"> </a> = on
Binary Hex Dec 8 4 2 1 1 1 0 1 0xD 13 Value in PLC AND 0 1 1 0 0x6 6 Bitmask = 0 1 0 0 0x4 4 Result <a href="@TextChoice(N7:2,0x6,'off',0x3,'on')"> </a> = off
This tag is the same as TextChoice except for there is no need for quote marks. For example, the tag below shows the image “/graphics/comfort.gif” when the value PD13:5.1 does not have 0x4 and 0x8 under the mask 0xC
<a href="@ImageChoice(PD13:5.1,0xC,/graphics/comfort.gif,0x4,/graphics/hot.gif,0x8,/graphics/cold.gif)"> </a>
Below is a table that shows the possible resultant images based on certain values in the SoftPLC.
Bitmask: 1 1 0 0 (0xC) Example case Possible Result 1: 0 1 0 0 (0x4) /graphics/hot.gif when PD13:5.1 is 4 (0100) Possible Result 2: 1 0 0 0 (0x8) /graphics/cold.gif when PD13:5.1 is 8 (1000) Default: N/A /graphics/comfort.gif when PD13:5.1 is 2 (0010)