7

まず、背景は次のとおりです。

現在、完全な Windows 7 タブレットで実行されている Windows フォーム アプリケーション (C#、.NET Framework 3.5 で記述) があり、データ接続に使用される 3G モジュールが組み込まれています。データ接続は、Windows で通常のモバイル ブロードバンド接続として構成され (したがって、Windows が接続自体を管理します)、接続は [コントロール パネル] > [ネットワークとインターネット] > [ネットワーク接続] に表示され、正常に動作します。アプリケーションは、私たちのウェブサービスでインターネット。将来のある時点で、別のデバイス (完全な Windows 8 ベースのタブレット) に移行する予定です。

次に、このモバイル ブロードバンド接続の接続状態を読み取る必要があります。つまり、信号強度とキャリア名 (Vodafone UK など) を取得します。Windows 7 SDK のモバイル ブロードバンド API 部分を使用してこれを行う方法を見つけました (ここここを参照)。ただし、Windows 8 では動作しないか、少なくともここにあるデバイス。

.NET フレームワークを使用してモバイル ブロードバンド接続のプロパティを読み取る一般的な方法はありますか?

または、現在使用している Windows 7 のようなモバイル ブロードバンド API を含む Windows 8 SDK を知っている人はいますか?

前もって感謝します。

更新 - これはさまざまな Win 7 / Win 8 デバイスで動作するようになりました。Lenovo デバイスでさえ正常に動作しています。回答として、メインビットのサンプルコード (接続ステータスの読み取り、接続の構成、SIM ステータスの確認) を投稿します。コードは少し長すぎて質問に入ることができず、うっとうしいです。

4

5 に答える 5

3

接続ステータスの読み取り:

try
        {
            MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
            IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
            if (mbnInfMgrInterface != null)
            {
                IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                {
                    // Use the first interface, as there should only be one mobile data adapter
                    IMbnSignal signalDetails = mobileInterfaces[0] as IMbnSignal;

                    Int32.TryParse(signalDetails.GetSignalStrength().ToString(), out PhoneSignal);
                    PhoneSignal = Convert.ToInt32(((float)PhoneSignal / 16) * 100);

                    MBN_PROVIDER provider = mobileInterfaces[0].GetHomeProvider();
                    PhoneNetwork = provider.providerName.ToString();

                    if (String.IsNullOrEmpty(SIMNumber))
                    {
                        try
                        {
                            IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                            if (subInfo != null)
                            {
                                SIMNumber = subInfo.SimIccID;
                            }
                            else
                            {
                                SIMNumber = "Unable to read SIM info";
                            }
                        }
                        catch (Exception)
                        {
                            SIMNumber = "Unable to read SIM info";
                        }
                    }

                    // Check whether the connection is active
                    IMbnConnection connection = mobileInterfaces[0].GetConnection();

                    if (connection != null)
                    {
                        MBN_ACTIVATION_STATE state;
                        string profileName = String.Empty;
                        connection.GetConnectionState(out state, out profileName);

                        Connected = (state == MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED);
                    }
                    else
                    {
                        MessageBox.Show("Connection not found.");
                    }
                }
                else
                {
                    MessageBox.Show("No mobile interfaces found.");
                }
            }
            else
            {
                MessageBox.Show("mbnInfMgrInterface is null.");
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.Contains("SIM is not inserted."))
            {
                SIMNumber = "No SIM inserted.";
            }
            else
            {
                MessageBox.Show("LoginForm.DataConnection GetWindowsMobileDataStatus " + ex.Message);
            }
            PhoneSignal = 0;
            PhoneNetwork = "Unknown";
        }
于 2013-11-18T15:50:21.897 に答える
2

モバイル ブロードバンド API は、Windows 8 デスクトップでも利用できます。

Windows 8 Metro/RT などの名前を使用している場合は、これらの WindowsRT API (Windows.Connectivity.NetworkInformation など) が必要です。

于 2013-09-14T17:44:44.183 に答える
2

SIM が挿入され、機能しているか、有効になっていることを確認します。

try
        {
            MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
            IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
            if (mbnInfMgrInterface != null)
            {
                IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                {
                    try
                    {
                        MBN_READY_STATE readyState = mobileInterfaces[0].GetReadyState();

                        switch (readyState)
                        {
                            case MBN_READY_STATE.MBN_READY_STATE_BAD_SIM:
                                MessageBox.Show("The SIM is invalid (PIN Unblock Key retrials have exceeded the limit).");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_DEVICE_BLOCKED:
                                MessageBox.Show("The device is blocked by a PIN or password which is preventing the device from initializing and registering onto the network.");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_DEVICE_LOCKED:
                                MessageBox.Show("The device is locked by a PIN or password which is preventing the device from initializing and registering onto the network.");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_FAILURE:
                                MessageBox.Show("General device failure.");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_INITIALIZED:
                                try
                                {
                                    IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                                    if (subInfo != null)
                                    {
                                        SIMNumber = subInfo.SimIccID;
                                    }
                                    else
                                    {
                                        SIMNumber = "Unable to read SIM info";
                                    }
                                }
                                catch (Exception)
                                {
                                    SIMNumber = "Unable to read SIM info";
                                }

                                IMbnRegistration registration = mobileInterfaces[0] as IMbnRegistration;
                                if (registration != null)
                                {
                                    try
                                    {
                                        MBN_REGISTER_STATE regState = registration.GetRegisterState();

                                        switch (regState)
                                        {
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_DENIED:
                                                // SIM Inactive
                                                simInactive = true;
                                                MessageBox.Show("The device was denied registration. The most likely cause of this error is an Inactive SIM.");
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_DEREGISTERED:
                                                // Do nothing - this is returned before the device has tried to register
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_HOME:
                                                // Do nothing
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_NONE:
                                                MessageBox.Show("The device registration state is unknown. This state may be set upon failure of registration mode change requests.");
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_PARTNER:
                                                // Do nothing
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_ROAMING:
                                                // Do nothing
                                                break;
                                            case MBN_REGISTER_STATE.MBN_REGISTER_STATE_SEARCHING:
                                                // Do nothing
                                                break;
                                            default:
                                                MessageBox.Show("GetRegisterState returned an unexpected state: " + regState.ToString());
                                                break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("GetRegisterState Error: " + ex.Message);
                                    }
                                }
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_NOT_ACTIVATED:
                                MessageBox.Show("The subscription is not activated.");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_OFF:
                                MessageBox.Show("The mobile broadband device stack is off.");
                                break;
                            case MBN_READY_STATE.MBN_READY_STATE_SIM_NOT_INSERTED:
                                MessageBox.Show("The SIM is not inserted.");
                                break;
                            default:
                                MessageBox.Show("GetReadyState returned an unexpected state: " + readyState.ToString());
                                break;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("GetReadyState Error: " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("No mobileInterfaces found.");
                }
            }
            else
            {
                MessageBox.Show("mbnInfMgrInterface is null.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
于 2013-11-18T15:54:07.833 に答える