简体   繁体   English

无法读取 BlueZ 特性的值

[英]Cannot read value of BlueZ characteristic

I'm having an issue where I can't read the value of a characteristic within a GATT server.我遇到了一个问题,我无法读取 GATT 服务器中的特征值。 the ReadValue() method in the TxCharacteristic (shown below) doesn't seem to get called at all and nothing returns even if I insert a test value for the return. TxCharacteristic 中的 ReadValue() 方法(如下所示)似乎根本没有被调用,即使我为返回插入一个测试值,也没有任何返回。

What I'm wondering is;我想知道的是; why does the no longer work even though I'm almost sure I haven't changed from the previous working code and how can this be fixed?为什么即使我几乎可以肯定我没有改变以前的工作代码,它也不再工作了,如何解决这个问题?

here is the class for TxCharacteristic within my code.这是我的代码中 TxCharacteristic 的 class。 this is being run on a Raspberry Pi 3B.这是在 Raspberry Pi 3B 上运行的。 the BLE scanner I am using LightBlue.我正在使用 LightBlue 的 BLE 扫描仪。 Full code can be found here in the file "Firmware.py"完整代码可“Firmware.py”文件中找到

class TxCharacteristic(Characteristic):
"""
Transmit characteristic, sends data to the client
"""
TX_CHRC_UUID = '0x0002'

def __init__(self, bus, index, service):
    Characteristic.__init__(
            self, bus, index,
            self.TX_CHRC_UUID,
            ['read', 'notify'],
            service)
    self.notifying = False
    self.value = ""

def StartNotify(self):
    if self.notifying:
        print('Already notifying, nothing to do')
        return

    self.notifying = True

def StopNotify(self):
    if not self.notifying:
        print('Not notifying, nothing to do')
        return
    self.notifying = False

def ReadValue(self):
    print("Tx read: " + bytes(self.value).decode)
    self.value = Comms.TxRead(Comms)
    return self.value

Also, as a side issue, I don't think I have implemented notifications correctly, so any help there would also be great.另外,作为一个附带问题,我认为我没有正确实施通知,所以那里的任何帮助也会很棒。

TIA, Auri TIA,奥里

So, it turns out that the return value for ReadValue() needs to be an array of dbus.Byte objects.因此,事实证明 ReadValue() 的返回值需要是 dbus.Byte 对象的数组。 once I changed my code to fit this, things worked.一旦我改变了我的代码以适应这个,事情就奏效了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM