Support Home


Knowledge Base


Documentation


Contact Support


Unofficial Forum

Handling Dynamic Information for the Web

Question: When I pass dynamic information to the web page, it often does not show everything, and it seems that the data lost are not always the same, why is that?

Answer: Even though the EM200 and EM1000 can be used as web servers, they are still small modules with limited resources. Generally speaking, you cannot expect that the TX buffer to readily have the required 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! And because the TX buffer is always varying, as there are constant data being transferred, the data does not always get truncated at the same places, thus the reason for the differences between each instance of loosing data.

So, it is important to check to see if there are enough space within the TX buffer before putting data into it. What we want to do is to wait in a loop until the desired amount of space becomes available, but at the same time, we do not want to halt the device up waiting. To achieve this, we will use the doevents statement.

For Example:

    io.num=0
 
    if io.state= LOW then
      sock.setdata("LOW")
    else
      sock.setdata("HIGH")
    end if
 
    sock.send

The above might seem correct, but actually has the hidden problem of not always getting the required buffer space. We will modify the code so that data sent will always have enough buffer to handle it:

<?
  dim s as string
  io.num=0
  if io.state= LOW then
    s = "LOW"
  else
    s = "HIGH"
  end if

  while sock.txfree<len(s)
    doevents
  wend

  sock.setdata(s)
  sock.send

?>

Now things should sail smoothly with the data waiting quietly on the side without blocking other processes!


© Tibbo Technology Inc. 2001-2009   Contact Us | Account