首页 > 解决方案 > 将结构数据传递给 Dbus

问题描述

我有一个正在运行的进程,它有一个采用结构的 DBUS 端点。这是使用 qt 和 q-dbus 开发的。

在 dfeet 中,我看到了端点方法的详细信息

setScreen (Struct of (Int32, Struct of (String), Boolean, Struct of (Int32, UInt32, Byte, Boolean, Byte, Int32, String, String, String, String, String, String, String, String, String), Struct of (Int32, UInt32, Byte, Boolean, Byte, Int32, String, String, String, String, String, String, String, String, String)) screenUi) ↦ (Boolean arg_0)

我试图弄清楚如何以这种格式发送一些示例数据。任何指针?

在此处输入图像描述

我尝试使用下面的 dbus-send 但出现格式错误

    gdbus call --session --dest com.semanect.S8Displayd  --object-path /com/semanect/S8Displayd --method com.semanect.S8Displayd.SetScreen "(0,('JBN1'),true,(2,0,0,true,0,0,'','','','','abc','def','ghi','mmm'),(2,0,0,true,0,0,'','','','','abc','def','ghi','mmm')"
Error: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method 'SetScreen' in interface 'com.semaconnect.S8Displayd' at object path '/com/semaconnect/S8Displayd' (signature 's')

使用 d-feet introspect 我得到方法 dbus 格式为

 '    <method name="setScreen">\n'
 '      <arg type="b" direction="out"/>\n'
 '      <arg name="screenUi" type="(i(s)b(iuybyisssssssss)(iuybyisssssssss))" '
 'direction="in"/>\n'
 '      <annotation name="org.qtproject.QtDBus.QtTypeName.In0" '
 'value="screen_ui_t"/>\n'
 '    </method>\n'

如果有人对如何使用它有建议/指示,我也愿意使用 python

更新 :

我能够使用 dbus-send 发送数据

gdbus call --session --dest com.semanect.S8Displayd  --object-path /com/semanect/S8Displayd --method com.semanect.S8Displayd.setScreen "(0,('JBN1',),true,(2,0,0,true,0,0,'','','','','abc','def','ghi','mmm','kkk'),(2,0,0,true,0,0,'','','','','abc','def','ghi','mmm','kkk'))"
(true,)

如何使用 python 脚本/C 程序执行此操作?

标签: linuxshelldbus

解决方案


不是真正的答案,而是更多信息的呼吁,但由于格式方面的挑战,更容易在此处发布......

我个人发现方法签名busctl更容易阅读。您能否在您的问题中发布以下命令的输出:

busctl introspect com.semanect.S8Displayd  /com/semanect/S8Displayd

正如你提到的Python。我发现pydbus非常适合 D-Bus。您能否也发布以下内容的输出:

import pydbus
adapter = pydbus.SessionBus().get('com.semanect.S8Displayd', '/com/semanect/S8Displayd')
help(adapter.SetScreen)

推荐阅读