0
我在通過python cgi程序與串口通信時遇到問題。我在html中有兩個按鈕來控制兩個LED(LED1,LED2)。Python CGI與串口通信
<html>
<h1>Test Page 2</h1>
<form name="input" action="/cgi-bin/myscript-2.py" method="get">
<input type="submit" value="LED1" name="Submit">
<input type="submit" value="LED2" name="Submit1">
</form>
</html>
現在我的Python程序從這裏接收結果
#!/usr/bin/python
import cgi
import cgitb;
import serial
form = cgi.FieldStorage()
cgitb.enable()
port = "/dev/ttyACM0"
ser = serial.Serial(port, 9600, timeout=0)
if "LED1" in form:
ser.write("hello")
elif "LED2" in form:
ser.write("hello")
else:
print "Couldn't determine which button was pressed."
我總是讓想不出確定button.The Apache的錯誤日誌是這樣
[Sat Nov 08 12:41:41.579738 2014] [cgid:error] [pid 1080:tid 3004140352] [client 127.0.0.1:48698] malformed header from script 'myscript-2.py': Bad header: Couldn't determine which butto, referer: http://localhost/page2.html
當您的代碼包含「無法確定哪個按鈕被按下」時,您是否真的得到了錯誤消息「無法確定哪個按鈕」(最後沒有「n」)? – 2014-11-08 21:12:18
另外,你有沒有嘗試簡單地打印「表格」?價值最終成爲什麼? – 2014-11-08 21:13:01