6This script runs a web server, which provides page with target variables
7and their values. Real-time access is used when reading variables via
11import isystem.connect
as ic
17if sys.version[0] ==
'2':
18 from BaseHTTPServer
import BaseHTTPRequestHandler, HTTPServer
19elif sys.version[0] ==
'3':
20 from http.server
import BaseHTTPRequestHandler, HTTPServer
22 raise Exception(
'unknown version')
25connectionMgr = ic.ConnectionMgr()
26connectionMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
27debugCtrl = ic.CDebugFacade(connectionMgr)
35targetVars = [
'main_loop_counter',
'g_char',
'g_int']
39 This function builds contents of a web page, which contains table with
43 web_str =
'<html>\n' + \
44 '<head><meta http-equiv="refresh" content="3"/>\n' + \
47 ' border: 2px solid black;\n' + \
48 ' border-collapse: collapse;\n' + \
51 ' border: 1px solid black;\n' + \
52 ' border-collapse: collapse;\n' + \
55 ' padding: 5px;\n' + \
58 '</head><body><code><table><tr><th>Variable</th><th>Value</th></tr>\n'
59 for var
in targetVars:
60 py_var = debugCtrl.evaluate(ic.IConnectDebug.fRealTime, var)
61 str_var = py_var.getResult()
63 web_str +=
'<tr><td><b>' + var +
'</b></td><td>' + str_var +
'</td></tr>\n'
65 web_str +=
'</table></code></body></html>'
66 except Exception
as ex:
72class HttpHandler(BaseHTTPRequestHandler):
76 This method processes HTTP request. It always returns
77 the same content, regardless of URL.
80 self.send_response(200)
81 self.send_header(
'Content-type',
'text/html')
84 self.wfile.write(lines.encode(
'utf-8'))
87 self.send_error(404,
'File Not Found: ' + self.path)
92 server = HTTPServer((
'', 8080), HttpHandler)
93 print(
'Http server is running ...')
94 server.serve_forever()
95 except KeyboardInterrupt:
96 print(
'Ctrl+C received, terminating the server!')
100if __name__ ==
'__main__':