[Tutor] Python and Web

Engineering engg at cleantechsolution.in
Fri Aug 9 14:16:27 CEST 2013


Dear All

 

After a lot of struggling for weeks , I can read the serial port readings in
my web page. Below is the code

 

#!c:\Python27\Python.exe

import cgi, cgitb;

import sys, serial ,time

cgitb.enable()

ser = serial.Serial('COM27', 9600)

numOfLines = 0

print "Content-type:text/html\n\n"

print """

            <html>

            <head>

            <title>

            Real Time Temperature

            </title>

            <body><h1>Real Time Temperature:</h1></body>

            """

while True:

    response = ser.readline()

    print """

            <script type="text/javascript">

            var int=self.setInterval(function(){refer()},1000);

            function refer()

            {

            document.getElementById('mine').innerHTML ="""+response+""";

            }

            </script>

            </head>

            <body>

            <div id="mine"></div>

            </body></html>

            """

 

ser.close()

sys.exit(0)

 

BUT is this good programming ? I personally do not feel so. 

SECONDLY , during the whole execution process , the cursor is showing busy
and I am prevented to click anything else. Why is this so? How to avoid it.


 

CLEANTECH SOLUTION

www.cleantechsolution.in

 

SAVE PAPER , SAVE EARTH

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130809/03b3964e/attachment-0001.html>


More information about the Tutor mailing list