DBus Interface to MM and No Modems?

Dan Williams dcbw at redhat.com
Fri Jun 12 07:50:32 PDT 2015


On Fri, 2015-06-12 at 15:03 +0100, John Whitmore wrote:
> I'm going through the DBus documentation and can't seem to find what I'm
> looking for. Then perhaps what I'm looking for is not actually valid. 
> 
> The documentation goes through the creation of a connection but I'm at the
> step before that trying to find out how many, if any modems are actually
> connected. If there's none then that's fine I have nothing to do but how to
> determine that?

ModemManager uses the standard D-Bus "Object manager" interfaces as
described here:

http://www.freedesktop.org/software/ModemManager/api/latest/ref-dbus-standard-interfaces-objectmanager.html

which means you can get the list of modems by doing this:

sudo dbus-send --system --print-reply
--dest=org.freedesktop.ModemManager1 /org/freedesktop/ModemManager1
org.freedesktop.DBus.ObjectManager.GetManagedObjects

and that'll send you back a dict of the all modems managed by MM keyed
by object path.  For example:

method return sender=:1.5 -> dest=:1.139 reply_serial=2
   array [
      dict entry(
         object path "/org/freedesktop/ModemManager1/Modem/0"
         array [
            dict entry(
               string "org.freedesktop.ModemManager1.Modem"
               array [
                  dict entry(
                     string "Plugin"
                     variant                         string "Sierra"
                  )
                  dict entry(
                     string "PrimaryPort"
                     variant                         string "cdc-wdm0"
                  )
                  dict entry(
                     string "State"
                     variant                         int32 3
                  )

You can either grab the properties out of the dict here, or just use
this reply to build up the list of modem objects and query the state
later.  In this case, my modem is in state 3 (MM_MODEM_STATE_DISABLED)
because that's what the State property of the
org.freedesktop.ModemManager1.Modem interface is.  If the modem was
already connected, the org.freedesktop.ModemManager1.Modem.State
property would be either 10 (CONNECTING) or 11 (CONNECTED).

Here's a python example:

-----
import dbus, sys

bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.ModemManager1",
"/org/freedesktop/ModemManager1")
om = dbus.Interface(proxy, "org.freedesktop.DBus.ObjectManager")

states = { 10: "Connecting", 11: "Connected" }

modems = om.GetManagedObjects()
for mpath in modems.keys():
    modem_state =
modems[mpath]['org.freedesktop.ModemManager1.Modem']['State']
    try:
        state = states[modem_state]
    except KeyError:
        state = "Not connected"
    print "Modem object path: " + mpath + "  (" + state + ")"
-----

Let us know if any of this is unclear or if you've got more questions!

Dan




More information about the ModemManager-devel mailing list