- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在构建一个 Kivy 应用程序,它使用 pyobjus 连接到 TI SensorTag 。我已成功让应用程序在扫描期间找到传感器,但无法连接它。我找到了一些代码here ,但它适用于不同的传感器。我收到的错误是:Exception AssertionError: AssertionError() in 'pyobjus.protocol_forwardInvocation' ignored
来自 pyobjus,但我不知道如何跟踪错误,因为它被忽略了。
编辑
这是代码,似乎问题出在 connect() 函数
class Ble(object):
def check_le(self, central):
state = central.state
if state == CBCentralManagerStateUnknown:
print 'CentralManager: Unknown state'
elif state == CBCentralManagerStatePoweredOn:
print 'CentralManager: Ready to go!'
return True
elif state == CBCentralManagerStatePoweredOff:
print 'CentralManager: Bluetooth is powered off'
elif state == CBCentralManagerStateUnauthorized:
print 'CentralManager: The application is not authorized to use BLE' # noqa
elif state == CBCentralManagerStateUnsupported:
print 'CentralManager: This hardware doesnt support BLE'
def connect(self, peripheral):
print "connecting"
self.stop_scan()
self.central.cancelPeripheralConnection_(peripheral)
self.central.connectPeripheral_options_(peripheral, None, None)
def disconnecte(self, peripheral):
# XXX !
print "Disconnect Not Implemented!"
def create(self):
self.callback = None
self.peripherals = {}
load_framework(INCLUDE.IOBluetooth)
CBCentralManager = autoclass('CBCentralManager')
self.central = CBCentralManager.alloc().initWithDelegate_queue_(
self, None)
def start_scan(self):
print 'Scanning started on Mac OSX MJR'
self.asked_services = []
self.central.scanForPeripheralsWithServices_options_(None, None)
Clock.schedule_interval(self.pop_queue, 0.04)
def stop_scan(self):
print "stopping scan"
self.central.stopScan()
def pop_queue(self, dt):
if self.queue:
self.callback(*self.queue.pop(0))
@protocol('CBCentralManagerDelegate')
def centralManagerDidUpdateState_(self, central):
print 'central state', central.state
self.check_le(central)
self.start_scan()
@protocol('CBCentralManagerDelegate')
def centralManager_didDiscoverPeripheral_advertisementData_RSSI_(
self, central, peripheral, data, rssi):
# print('centralManager:didDiscoverPeripheral:advertisementData:RSSI:')
# uuid = peripheral.identifier.UUIDString().cString()
# if peripheral.name:
# print('-> name=', peripheral.name.cString())
# print 'uuid:', uuid
keys = data.allKeys()
count = keys.count()
if count < 2:
return
name = peripheral.name.cString()
# name = data.objectForKey_(keys.objectAtIndex_(count - 2)).cString()
values = data.objectForKey_(keys.objectAtIndex_(count - 1))
sensor = c.get_from_ptr(values.bytes().arg_ref, 'c', values.length())
uuid = peripheral.description().cString()
if self.callback:
self.callback(rssi.intValue(), name, sensor)
else:
print uuid, name, sensor, rssi
if uuid not in self.peripherals:
pass
#self.connect(peripheral)
self.peripherals[name] = (peripheral, rssi)
@protocol('CBCentralManagerDelegate')
def centralManager_didConnectPeripheral_(self, central, peripheral):
if not peripheral.name.UTF8String():
return
peripheral.delegate = self
CBUUID = autoclass('CBUUID')
service = CBUUID.UUIDWithString_('1901')
peripheral.discoverServices_([service])
@protocol('CBPeripheralDelegate')
def peripheral_didDiscoverServices_(self, peripheral, error):
for i in range(peripheral.services.count()):
service = peripheral.services.objectAtIndex_(i)
if service.UUID.UUIDString.cString() == '1901':
break
else:
assert(0)
peripheral.discoverCharacteristics_forService_([], service)
@protocol('CBPeripheralDelegate')
def peripheral_didDiscoverCharacteristicsForService_error_(self, peripheral, service, error):
print "discovered characteristic: ", service, service.characteristics
for i in range(service.characteristics.count()):
ch = service.characteristics.objectAtIndex_(i)
if ch.UUID.UUIDString.cString() == '2B01':
peripheral.setNotifyValue_forCharacteristic_(True, ch)
print "set notify for chr {}".format(i)
@protocol('CBPeripheralDelegate')
def peripheral_didUpdateNotificationStateForCharacteristic_error_(
self, peripheral, characteristic, error):
# probably needs to decode like for advertising
# sensor = c.get_from_ptr(values.bytes().arg_ref, 'c', values.length())
print "characteristic: {} notifying: {}".format(characteristic.UUID.UUIDString.cString(), characteristic.isNotifying)
pass
@protocol('CBPeripheralDelegate')
def peripheral_didUpdateValueForCharacteristic_error_(self, peripheral, characteristic, error):
# probably needs to decode like for advertising
# sensor = c.get_from_ptr(values.bytes().arg_ref, 'c', values.length())
data = c.get_from_ptr(characteristic.value.bytes().arg_ref, 'c', characteristic.value.length())
name = peripheral.name.cString()
peripheral.readRSSI()
rssi = peripheral.RSSI and peripheral.RSSI.intValue() or 0
if self.callback:
if self.queue is not None:
self.queue.append((rssi, name, data))
else:
self.callback(rssi, name, data)
else:
print name, rsii, data
最佳答案
这意味着您的协议(protocol)方法之一存在错误,例如 centralManager_didDiscoverPeripheral_advertisementData_RSSI_()
。但您没有提供任何代码。
我现在也更新了我的 plyer BLE 代码 - 它支持连接和基本的特征读取/写入。这是一项正在进行中的工作,代码相当困惑,因为它是我的 BLE 测试和学习环境。您可以在这里查看:https://github.com/kivy/plyer/pull/185
如果您尝试为此编写自己的代码,请记住以下几点。首先,确保在连接时保留对 CBPeripheral 对象的引用 - 否则该对象将被释放,并且您的连接将默默失败。其次,确保通过 peripheral.setDelegate_(self)
设置 CBPeripheralDelegate
而不是 peripheral.delegate = self
- 后者将不起作用,并且您的协议(protocol)方法将不会被调用。最后,pyobjus 中存在一个将字节传递给 void* 参数的错误 - 这将阻止您创建二进制 NSData 对象来读取/写入特征值。不过,我有一个针对该错误的 PR ( https://github.com/kivy/pyobjus/pull/26 )。
关于python - 异常断言错误: AssertionError() in 'pyobjus.protocol_forwardInvocation' ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36551634/
我有以下实体字段: /** * @Assert\Regex( * pattern = "/^d+\.(jpg|png|gif)$/", * htmlPattern = "/^d+\.(j
我有一个显示查询结果的表。 我使用这个检查表包含结果: cy.get("table", {timeout: 60000}).find("tr[data-index]").should("have.le
void (assert)(int e) { assert(e); } 这里是如何工作的? 最佳答案 void (assert)(int e) 相当于 void assert(int) 为什么
大家好,我的第一次测试遇到了一些问题 我正在写这个 fragment ,但我一直遇到这个问题: java.lang.AssertionError at org.junit.Assert.fail(As
从表中,我获取字符串列表,并想检查当 val!= "A"时,表列表中是否存在字符串“x”: for (int i = 0; i list = new ArrayList(); for(int i=0
我想在现有代码中为 VHDL 断言操作添加一个错误计数器。基本上,我的代码如下所示: assert data = good_data report "Bad data" severity er
我有一个无法处理的问题,所以我想也许你可以帮助我。基本上我有一个函数,它接收 char* 作为参数并对其执行一些操作(我已经检查了这些步骤/函数,它们工作得很好)。如果函数中给出的 char* 是“”
我有一些代码用于检查输入日期是否正确。只需检查是否不超过 12 个月,给定月份中的日期是否正确,并且还应该考虑闰年(因此,基本上是正常的日期检查)。唯一不合适的是年份不应低于 2000。如果日期无效,
我有一个关于 Cypress 断言的问题,最近才开始使用这个测试平台,但是当 URL 返回一个随机数时卡住了,如下所示。 /Geocortex/Essentials/REST/sites/SITE?f
我有一个 Python mock对象,我想断言是否设置了该对象的任何属性。 我不相信PropertyMock将适用于我的目的,因为我必须知道是否设置了任何属性,而不是特定属性。 它也不像我可以模拟模拟
考虑这个简单的基类 Foo 有一个函数 foo 调用一个纯虚函数 foo_,用 Doxygen 记录: class Foo { public: /** \brief This functi
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我在这段代码中执行 malloc 时遇到问题, /*function starts*/ if(NULL==(partial_results=(bignum_t**)malloc(sizeof
大家好,我想知道如何将整个代码块放入一个断言中? 例如,我有一个数组,我想对数组的每个值进行断言。这是我的代码的样子: for (int value : values) { assert Wi
这不是我的作业——我只是在练习。我似乎无法完全理解这个断言概念。 1) Determine the pre-condition for x that guarantees the post-condi
是否可以在带有时间戳的断言失败时记录信息 例如 int a = 10 assert( a > 100 ); 那么它将失败并像时间戳一样输出 2013-12-02 , 17:00:05 assert f
由于我们公司不使用单元测试,所以我正在自学对自己的代码进行单元测试。我正在使用标准的 .net 测试框架进行一些非常基本的单元测试。 我的一个方法返回一个 IEnumerable我想测试它的输出。所以
我有一个如下所示的对象数组,并且只想针对数组中的某些字段进行断言。 对象数组 - var a = [{"key":"key2","value":"value2","updatedBy":"name1"
我正在尝试编写一个 PSL 断言来检查输入断言的数量是否与输出断言的数量相匹配。 例如: . 在输入上任何时候都可能发生任何事情,输出也可以在任何时候断言。确切时间未知,也不重要。我要验证的是没有信息
我想在Cypress中做一个断言如下: cy.get(a).should('be.visible').or(()=>{ cy.get(b).should('be.visible'); });
我是一名优秀的程序员,十分优秀!