320
Platforms
©2000-2008 Tibbo Technology Inc.
Each time this HTML page will be requested by the browser, the "HELLO SERIAL
WORLD TOO!" string will be sent out of the serial port.
Generating Dynamic HTML Pages
How to "print" dynamic HTML data
In most cases the BASIC code included into the HTML page is used to generate
dynamic HTML content, i.e. to send some dynamically generated data to the
browser. This is done in a way, similar to sending out data in a regular data mode:
you first set the data you want to send with the
method, then
commit this data for sending using
method.
Here is an example HTML page that checks the state of one of the inputs of the I/O
object and reports this state on the HTML page:
<!DOCTYPE HTML
public
"-//W3C//DTD W3 HTML//EN"
>
<HTML>
<BODY>
The state of line
0
is:!<br>
<?
'This is a BASIC code fragment. Get the state of the line.
io.num=
0
if
io.state= LOW
then
sock.setdata(
"LOW"
)
else
sock.setdata(
"HIGH"
)
end
if
sock.send
?>
</BODY>
</HTML>
Notice how we did not have to use
- it is set automatically
when control is passed to BASIC!
Be careful not to get your data truncated!
The above example is seemingly correct and in this particular case will work fine-
because there is not much static data preceding the point where we generate
dynamic content and not much dynamic content is generated as well. Generally
speaking, you cannot expect that the TX buffer will have enough space when you
need to put some data into it! If you are not careful the dynamic data you want to
generate may get truncated!
To avoid this situation always check if the necessary amount of free space is
available before attempting to put it into the TX buffer. This statement is true for
the normal data mode as well, not just for the HTTP processing- we have already
touched on this subject in
. What is different for HTTP is that you
event to "call you back" when the TX buffer
frees up!
The only solution in case of HTTP is to wait, in a loop, for the desired amount of
space to become available. Naturally, we don't want to be blocking the whole
353
353
340
304
342