Python libmm problems

colin.helliwell at ln-systems.com colin.helliwell at ln-systems.com
Wed Sep 13 16:23:16 UTC 2017


I'm trying to write some python to get the operator id off the modem. 
Due to limited knowledge of such things, I'm *not* using any notifcation
callbacks etc, but simply trying to poll things.
I've wrapped the functionality into a class (thinking to thus be able to
easily contain the modem's objects etc in the instance).
I poll an initial 'get modem' method:

        if self.connection is None:
            self.connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None)
        self.manager = ModemManager.Manager.new_sync (self.connection,
Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None)
        if self.manager is None:
            # MM not found
            self.connection = None
            self.modem = None
            self.obj = None
            return None
        # Search for the modem
        for obj in self.manager.get_objects():
            m = obj.get_modem()
            # Look for my modem
            if (m.get_primary_port() == "ttyS1"):
                self.obj = obj
                self.modem = m
        return self.modem

Then, once the modem has been found by this, I go on to try to get the
operator code by polling a further method:

        MccMnc  = None
        if self.modem is not None:
            # Return MCC/MNC if registered
            if (self.modem.get_state() >=
ModemManager.ModemState.REGISTERED):
                    MccMnc = self.obj.get_modem_3gpp().get_operator_code()
            else:
                    print 'GetMccMnc', self.modem.get_state()
        return MccMnc

What I'm seeing is that, even though mmcli shows the modem getting to
'connected', this function continues to just get a state of
'MM_MODEM_STATE_ENABLING'.
If I (re)run the script after the modem has got connected, then it's working
as expected.

I'm not sure if this in an error in my python oop, or incorrect use of
libmm. Why aren't the repeated calls to get_state() seeing the change of
state?

Any tips please?!





More information about the ModemManager-devel mailing list