DBus Interface to MM and No Modems?

John Whitmore arigead at gmail.com
Wed Jun 17 08:43:19 PDT 2015


On Wed, Jun 17, 2015 at 09:48:13AM -0500, Dan Williams wrote:
> On Wed, 2015-06-17 at 14:23 +0100, John Whitmore wrote:
> > On Fri, Jun 12, 2015 at 09:50:32AM -0500, Dan Williams wrote:
> > > 
> > > 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
> > > 
> > > 
> > 
> > Thanks for all that, and sorry I've been distracted from this for a few
> > days. Got back to it and have one good modem I'm working on and one modem I've
> > not been able to modeswitch as yet. 
> > 
> > With the one that is switching I've got the DBus object. I was going to
> > attempt to connect with the Simple DBus interface but I'm pulling back a
> > SignalStrength of 0 so thought that might be to do with the current
> > state. That I'm sure just means that I have to activate the radio on the
> > device, so that gets into bearers and the like. So forget the Simple interface
> > as I don't want to just connect. I want to enable radios check coverage and
> > then connect.
> 
> A signal of '0' doesn't mean that you need to get into bearers, you just
> need to 'enable' the modem.  ModemManager starts all modems in a
> 'disabled' state when they are recognized, and they must then be enabled
> to become useful.  That basically means opening up the modem's ports,
> setting up listeners for unsolicited messages (like SMS receipt, signal
> strength indications, access technology change indications, operator
> change indications, etc).  This is because it's pretty useless to have
> all that stuff turned on and the modem powered up if no program actually
> cares about it :)
> 
> Bearers only come into play when you want a data connection.
> 
> > All that means that I'd really like to use some of the enumerated types that
> > the DBus interface defines but struggling to find how to get them and use
> > them. So for example in your code you use states of {10: "Connecting", 11:
> > "Connected"} How would I use the enumeration:
> > 
> > http://www.freedesktop.org/software/ModemManager/api/latest/ModemManager-Flags-and-Enumerations.html#MMModemState
> > 
> > I'm looking into DBus tutorials and they never seem to go over
> > enumerations. Just using a bad search term I guess.
> 
> The enums are just numbers; so if (in the above example) you see that
> the org.freedesktop.ModemManager1.Modem.State property is '10', you look
> that up in the ModemManager D-Bus specification linked above and you
> know that this property's numbers all map to the MMModemState
> enumeration.  If you're not using C (and thus not using libmm-glib) then
> you get to create the mapping yourself in your code, if you like.  Or
> just use the numbers, but mapping them in your own code would help
> readability.
> 
> That's essentially what I did in the python code with the 'states' dict.
> 
> Dan
> 

Your numbering for the states has confused me, I would not have said that
Connecting was the value 10. But I now understand and will create my own
states as per your example. I am still confused by numbering starting to count
at either zero or one doesn't seem correct.

I have a lot of DBus reading to catch up with.

John


More information about the ModemManager-devel mailing list