Debian Codegraph @

expeyes-web/cgi-bin/expeyes_setoutput.cgi

raw
1 #!/usr/bin/python3
2 """
3 CGI script for setting status for output pins of expEYES Junior connected to server
4 Copyright 2016, Authors : , Jishnu R([email protected]), Rakesh K M([email protected]), Manoj.S.Nair([email protected]) [Amrita School of Engineering, Amritapuri Campus, Kollam 690525, Kerala]
5 License : GNU GPL version 3
6 """
7 import sys,os,cgi
8
9 import expeyes.eyesj as eyes
10 from contextlib import contextmanager
11
12 form= cgi.FieldStorage()#get submitted form
13
14 sys.stdout.write('Content-type: text/html \r\n\r\n')#html header
15
16 pvs = float(form.getvalue("pvs"))#get input values from get/post method
17 od1 = int(form.getvalue("od1"))#get input values from get/post method
18 sqr1 = int(form.getvalue("sqr1"))#get input values from get/post method
19 sqr2 = int(form.getvalue("sqr2"))#get input values from get/post method
20
21 @contextmanager
22 def suppress_stdout():# prevent header crash because of connection errors etc.
23 with open(os.devnull, "w") as devnull:
24 old_stdout = sys.stdout
25 sys.stdout = devnull
26 try:
27 yield
28 finally:
29 sys.stdout = old_stdout
30
31 with suppress_stdout():
32 p=eyes.open()
33
34 p.set_state(10,od1)#set OD1
35 p.set_voltage(pvs)#set PVS
36 p.set_sqr1(sqr1)#set SQR1
37 p.set_sqr2(sqr2)#set SQR2
38
39 sys.stdout.write(unicode('%s\r\n\r\n'%("Outputs are set")))#return on success execution
40 sys.stdout.flush()#flush buffers