Python-Dbus定义整数数组

时间:2018-07-06 23:09:47

标签: python linux python-3.x bus

我正在尝试使用Python-DBus将整数数组从一个python脚本返回到另一个。

DBus服务器看起来像这样:

def int_to_bytestring(number):
    bytestring = number.to_bytes(4,'little')
    return bytestring

def bytestring_to_int(bytestring):
    return struct.unpack("<i", bytestring)[0]

@dbus.service.method('tld.domain.sub.classyfan', out_signature="ai")
    def getTargetTemp(self):
        global TargetTemp
        print("TempController: getTargetTemp called: %s"%(TargetTemp))
        tg = int_to_bytestring(TargetTemp)
        toReturn = []
        for t in tg:
            toReturn.append(t)
        return toReturn

DBus客户端如下所示:

class TargetTemperatureChrc(Characteristic):
    TEMP_UUID = '2c51d80c-b912-4100-bb39-939824930480'

    def __init__(self, bus, index, service):
        Characteristic.__init__(self, bus, index,self.TEMP_UUID,['read'],service)
        self.service = service
    def ReadValue(self, options):
        try:
            currentTarget = self.service.dbus_interface.getTargetTemp()
        except Exception as err:
            print("Error: %s"%(err))
        print("Got Target Temp: %s"%(currentTarget))
        return [currentTarget]

问题是我在这里显示了一个异常:

Got Target Temp: dbus.Array([dbus.Int32(0), dbus.Int32(2), dbus.Int32(0), dbus.Int32(0)], signature=dbus.Signature('i'))
ERROR:dbus.service:Unable to append ([dbus.Array([dbus.Int32(0), dbus.Int32(2), dbus.Int32(0), dbus.Int32(0)], signature=dbus.Signature('i'))],) to message with signature ay: <class 'TypeError'>: an integer is required (got type dbus.Array)

我将out_signature定义为“ ai”-DBus表示整数数组。

我在做什么错?谢谢。

0 个答案:

没有答案