C# – MBN API – Get signal strength from mobile broadband network adapter

Getting signal strength from the MBN API.

Have a look at the Microsoft documentation for GetSignalStrength. Note that the GetSignalStrength method returns a coded value so you need to convert it to dBm. Check out the Microsoft documentation for more details


using System;
using System.Collections.Generic;
using System.Text;
// Add a reference to COM Tab: 'Definition: UCM Extension API for MBN Type Library' 
using MbnApi; 

namespace MBN_Test
{
    class Program
    {
        static void Main(string[] args)
        {

            MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
            IMbnInterfaceManager infMgr = (IMbnInterfaceManager)mbnInfMgr;


            MbnConnectionManager mbnConnectionMgr = new MbnConnectionManager();
            IMbnConnectionManager ImbnConnectionMgr = (IMbnConnectionManager)mbnConnectionMgr;


            IMbnConnection[] connections = (IMbnConnection[])ImbnConnectionMgr.GetConnections();
            foreach (IMbnConnection conn in connections)
            {
                IMbnInterface mobileInterface = infMgr.GetInterface(conn.InterfaceID) as IMbnInterface;
                IMbnSignal sig = (IMbnSignal)mobileInterface;

                uint signalStrength = sig.GetSignalStrength();
                if (signalStrength != (uint)MBN_SIGNAL_CONSTANTS.MBN_RSSI_UNKNOWN)
                {
                    int signalStrengthDB = -113 + ((int)signalStrength * 2);
                    Console.WriteLine("Signal Strength:" + signalStrengthDB.ToString() + " dBm");
                    Console.WriteLine("");
                    Console.WriteLine("NOTE -113 means -113 or less");
                    Console.WriteLine("      -51 means -51 or greater");
                }
                else
                {
                    Console.WriteLine("Signal Strength unknown");
                }
            }
            Console.ReadKey(true);
        }
    }
}