AVC adbclient操作失败,RuntimeError

问题描述:

我有一个简单的代码片段,如下所示,使用AVC对Nexus3手机执行一些顺序操作。AVC adbclient操作失败,RuntimeError

#! /usr/bin/python 
import sys, os, time 

try: 
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) 
except: 
    pass 

from com.dtmilano.android.adb.adbclient import AdbClient 
#from com.dtmilano.android.viewclient import ViewClient 

adbc=AdbClient(serialno='.*') 
print 'taking snapshot...' 
adbc.takeSnapshot() 
print 'touch 1st time...' 
adbc.touch(50,70) 
time.sleep(1) 
print 'touch 2nd time...' 
adbc.touch(50,70) 

与takeSnapshot()触摸之前的代码(),触摸()失败,以下异常:

touch 1st time... 
sending 0015shell:input tap 50 70 
shell(cmd=input tap 50 70) 
__send(shell:input tap 50 70, checkok=True, reconnect=False) 
__checkOk() 
checkConnected() 
    checkConnected: returning True 
setAlarm(150) 
    __checkOk: recv= '' 
setAlarm(0) 
Traceback (most recent call last): 
    File "/home/swang/engine/test.py", line 19, in <module> 
    adbc.touch(50,70) 
    File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 430, in touch 
    self.shell('input tap %d %d' % (x, y)) 
    File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 260, in shell 
    self.__send('shell:%s' % cmd, checkok=True, reconnect=False) 
    File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 157, in __send 
    self.__checkOk() 
    File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 193, in __checkOk 
    raise RuntimeError("ERROR: %s %s" % (repr(recv), error)) 
RuntimeError: ERROR: '' 
Closing socket... <socket._socketobject object at 0xa9da60> 

,但如果我删除了takeSnapshot(),下面的2触摸()将成功的。我正在使用最近的AVC版本。我在这里忽略了什么吗?

由于历史原因AdbClient.takeSnapshot()被定义为

def takeSnapshot(self, reconnect=False): 
    ... 

这意味着将有服用后截图断开。 所以你所要做的脚本是

... 
adbc=AdbClient(serialno='.*') 
print 'taking snapshot...' 
adbc.takeSnapshot(reconnect=True) 
print 'touch 1st time...' 
adbc.touch(50,70) 
time.sleep(1) 
print 'touch 2nd time...' 
adbc.touch(50,70) 

它会工作。

+0

谢谢!有用!看起来我需要深入挖掘源代码... – 2014-09-02 02:55:41