Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 异常AssertionError:AssertionError()在';pyobjus.protocol_forwardInvocation';忽略_Python_Kivy - Fatal编程技术网

Python 异常AssertionError:AssertionError()在';pyobjus.protocol_forwardInvocation';忽略

Python 异常AssertionError:AssertionError()在';pyobjus.protocol_forwardInvocation';忽略,python,kivy,Python,Kivy,我正在构建一个Kivy应用程序,它使用pyobjus连接到。我已成功让应用程序在扫描过程中找到传感器,但我无法让它连接。我找到了一些代码,但它是针对不同的传感器的。我得到的错误是:Exception-AssertionError:AssertionError()中的'pyobjus.protocol_forwardInvocation'忽略了来自pyobjus的,但我不知道如何跟踪错误,因为它被忽略了 如何找到导致错误的原因(例如,防止pyobjus忽略错误) 更好的是,有没有人有一个简单的工作

我正在构建一个Kivy应用程序,它使用pyobjus连接到。我已成功让应用程序在扫描过程中找到传感器,但我无法让它连接。我找到了一些代码,但它是针对不同的传感器的。我得到的错误是:
Exception-AssertionError:AssertionError()中的'pyobjus.protocol_forwardInvocation'忽略了来自pyobjus的
,但我不知道如何跟踪错误,因为它被忽略了

  • 如何找到导致错误的原因(例如,防止pyobjus忽略错误)
  • 更好的是,有没有人有一个简单的工作示例,说明如何通过BLE将设备连接到MacOSX
  • 编辑

    下面是代码,问题似乎出在connect()函数上

    Ble类(对象):
    def检查(自我、中央):
    状态=中央状态
    如果状态==CBCentralManager状态未知:
    打印“CentralManager:未知状态”
    elif状态==CBCentralManagerStatePoweredOn:
    打印“CentralManager:准备就绪!”
    返回真值
    elif状态==CBCentralManagerStatePoweredOff:
    打印“CentralManager:蓝牙已关闭”
    elif状态==CBCentralManager状态未经授权:
    打印“CentralManager:应用程序无权使用BLE”#noqa
    elif状态==CBCentralManager状态不受支持:
    打印“CentralManager:此硬件不支持BLE”
    def连接(自身、外围设备):
    打印“连接”
    self.stop_scan()
    self.central.cancel外设连接(外设)
    self.central.connectPeripheral\u选项(外设、无、无)
    def断开连接(自身、外围设备):
    #XXX!
    打印“未执行断开连接!”
    def创建(自我):
    self.callback=None
    self.peripherals={}
    加载\u框架(包括.IOBluetooth)
    CBCentralManager=自动类('CBCentralManager')
    self.central=CBCentralManager.alloc().initWithDelegate\u队列_(
    自我,无)
    def start_扫描(自):
    打印“在Mac OSX MJR上开始扫描”
    self.asked_services=[]
    self.central.scan用于带有服务选项的外围设备(无,无)
    时钟计划间隔(self.pop_队列,0.04)
    def停止扫描(自我):
    打印“停止扫描”
    self.central.stopScan()
    def pop_队列(自身,dt):
    如果self.queue:
    self.callback(*self.queue.pop(0))
    @协议('CBCentralManagerDelegate')
    def CentralManagerDipDateState(自身,中央):
    打印“中央州”,central.state
    自我检查(中央)
    self.start_scan()
    @协议('CBCentralManagerDelegate')
    def中央管理器发现外围设备广告数据_(
    自身、中央、外围、数据、rssi):
    #打印('centralManager:DidDiscoveryPeripheral:advertisementData:RSSI:')
    #uuid=peripheral.identifier.UUIDString().cString()
    #如果是peripheral.name:
    #打印('->name=',peripheral.name.cString())
    #打印“uuid:”,uuid
    keys=data.allKeys()
    count=keys.count()
    如果计数小于2:
    返回
    name=peripheral.name.cString()
    #name=data.objectForKey(key.objectAtIndex(count-2)).cString()
    values=data.objectForKey(key.objectAtIndex(count-1))
    sensor=c.get_from_ptr(values.bytes().arg_ref,'c',values.length())
    uuid=peripheral.description().cString()
    如果self.callback:
    self.callback(rssi.intValue(),名称,传感器)
    其他:
    打印uuid、名称、传感器、rssi
    如果uuid不在自身外围设备中:
    通过
    #自连接(外围设备)
    self.peripherals[name]=(外围设备,rssi)
    @协议('CBCentralManagerDelegate')
    def centralManager_didConnectPeripheral_(自身、中央、外围设备):
    如果不是外围设备。name.UTF8String():
    返回
    peripheral.delegate=self
    CBUUID=自动类('CBUUID')
    service=CBUUID.UUIDWithString_u1;('1901')
    外围设备。discoverServices(服务)
    @协议('CBPeripheralDelegate')
    def外围设备_didDiscoverServices_(自身、外围设备、错误):
    对于范围内的i(peripheral.services.count()):
    服务=外围设备。服务。对象索引(i)
    如果service.UUID.UUIDString.cString()=“1901”:
    打破
    其他:
    断言(0)
    外围设备。发现特性\u用于服务\u([],服务)
    @协议('CBPeripheralDelegate')
    def外围设备发现特性服务错误(自身、外围设备、服务、错误):
    打印“发现的特征:”,服务,服务。特征
    对于范围内的i(service.characteristics.count()):
    ch=服务.特性.对象索引(i)
    如果ch.UUID.UUIDString.cString()=“2B01”:
    peripheral.setNotifyValue\u用于特性(True,ch)
    打印“为chr{}设置通知”。格式(i)
    @协议('CBPeripheralDelegate')
    def peripheral_didUpdateNotificationStateForCharacteristic_错误_(
    自身、外围设备、特性、错误):
    #可能需要像广告一样解码
    #sensor=c.get_from_ptr(values.bytes().arg_ref,'c',values.length())
    打印“characteristic:{}notifying:{}”。格式(characteristic.UUID.UUIDString.cString(),characteristic.isNotifying)
    通过
    @协议('CBPeripheralDelegate')
    def peripheral_DidUpdateValue for characteristic_error(自身、外围设备、特征、错误):
    #可能需要像广告一样解码
    #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())
    名称=外围设备
    
    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