set/get property using dbus-send
Asked Answered
H

2

12

I have made below sample xml and need some help in forming dbus-send command to set/get propoerty "Status". I know how to call methods, but not able to read/write property using dbus-send.

xml:

<node>
    <interface name="com.pgaur.GDBUS">
        <method name="HelloWorld">
            <arg name="greeting" direction="in" type="s"/>
            <arg name="response" direction="out" type="s"/>
        </method>
        <signal name="Notification">
            <arg name="roll_number" type="i"/>
            <arg name="name" type="s"/>
        </signal>
        <property name="Status" type="u" access="readwrite"/>
    </interface>
</node>
Hendricks answered 6/2, 2018 at 17:44 Comment(0)
N
27

You can Get/Set DBus properties for your DBus interface using below dbus-send commands. Replace $BUS_NAME and $OBJECT_PATH with respective names.

Get Property:

dbus-send --system --dest=$BUS_NAME --print-reply $OBJECT_PATH \
org.freedesktop.DBus.Properties.Get string:com.pgaur.GDBUS string:Status

Set Property:

dbus-send --system --dest=$BUS_NAME --print-reply $OBJECT_PATH \
 org.freedesktop.DBus.Properties.Set string:com.pgaur.GDBUS string:Status variant:uint32:10

You can read DBus specification to know more about DBus Properties.

Neona answered 7/2, 2018 at 18:6 Comment(1)
How am I supposed to know what values to use for $BUS_NAME and $OBJECT_PATH? If I use org.freedesktop.DBus and / (as I use for other dbus-send commands which work), I get > Error org.freedesktop.DBus.Error.UnknownInterface: org.freedesktop.DBus does not understand message GetMagnet
M
-2

dbus-send --system --print-reply --type=method_call --dest=org.ofono /gemalto_0 org.ofono.Modem.SetProperty string:"Powered" variant:boolean:false

Marola answered 1/5, 2019 at 7:5 Comment(1)
OP knows how to call methods, but not how to get/set properties.Hippocrene

© 2022 - 2024 — McMap. All rights reserved.