我刚开始使用Python和Linux。
我用Python创建了一个程序,通过ttyS0与串行LCD通信,并创建了一个脚本来启动它。我禁用该行'#T0:2345:respawn:/ sbin / getty -L ttyS0 115200 vt100'在inittab中防止出现问题。我得到的是不同的行为,这取决于我如何启动该程序。
我无法使用其他ttyS *,因为还有其他设备使用它们。其他设备工作正常。 我首先尝试使用inittab这样的' null :: respawn:python /home/python/glv.py'但行为是一样的。
日志示例:
2014-10-06 13:48:30,407 - __main__ - DEBUG - *****************
2014-10-06 13:48:30,420 - __main__ - DEBUG - *** Start GLV ***
2014-10-06 13:48:30,432 - __main__ - DEBUG - *****************
2014-10-06 13:48:30,444 - lcd - INFO - Initialize
2014-10-06 13:48:35,492 - lcd - ERROR - Didn't receive an answer in ClearScreen
2014-10-06 13:48:38,588 - lcd - ERROR - Didn't receive an answer in SetLandscape
2014-10-06 13:48:41,635 - lcd - ERROR - Didn't receive an answer in SetBackgroundColor
2014-10-06 13:48:44,681 - lcd - ERROR - Didn't receive an answer in SetForegroundColor
2014-10-06 13:48:47,728 - lcd - ERROR - Didn't receive an answer in SetTextBackgroundColor
2014-10-06 13:48:50,791 - lcd - ERROR - Didn't receive an answer in EnableTouchScreen
2014-10-06 13:48:53,837 - lcd - ERROR - Didn't receive an answer in ClearScreen
2014-10-06 13:48:56,884 - lcd - ERROR - Didn't receive an answer in ClearScreen
2014-10-06 13:48:59,931 - lcd - ERROR - Didn't receive an answer in SetForegroundColorGreen
2014-10-06 13:49:02,978 - lcd - ERROR - Didn't receive an answer in SetTextBackgroundColor1
2014-10-06 13:49:06,024 - lcd - ERROR - Didn't receive an answer in preparing WriteTextPos
环境:
The Linux distro: PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
The Python version: Python 2.7.3 (default, Mar 23 2014, 01:44:56)
The Hardware: Terra Board from ACME with AriaG25
The command line in the script is just 'python /home/python/glv.py'
所以,任何人都知道为什么只有在重启后脚本启动程序时才能在LCD上获得超时? 我自己无法弄清楚。
修改
作为设置LCD的BackgroundColor的示例:
def SetBackgroundColor(self):
toSend = "\xFF\xA4\x19\xEB"
state, res = self.SendBytesAndWaitResponse(toSend, "\x06", 3)
if(state != 0):
self.logger.error("Didn't receive an answer in SetBackgroundColor")
def SendBytesAndWaitResponse(self, toSend, toWait, timeout):
strres = ""
try:
while(self.lockcomm):
time.sleep(0.1)
self.lockcomm = True
start_time = time.time()
end_time = start_time + timeout
self.ser.write(toSend)
while True:
cur_time = time.time()
if cur_time >= end_time:
return (-1, strres)
else:
result = self.ser.read()
strres += result
if(strres.find(toWait) != -1):
return (0, strres)
except:
return (-1, strres)
finally:
self.lockcomm = False
我发送4个字节,期望char并将超时设置为3秒(它很多)并且永远不会在3秒内得到LCD中实现的响应(char 0x06)。