【问题标题】:Disable or Enable phone radio in windows mobile 6.5.3在 windows mobile 6.5.3 中禁用或启用电话无线电
【发布时间】:2014-08-09 19:30:10
【问题描述】:

我想在低连接区域启用或禁用电话无线电。是否有可能做到这一点?我正在使用摩托罗拉 ES400 进行开发。

【问题讨论】:

  • 除了下面的答案,另一种选择是使用供应商的设备 SDK(Moto 将其称为 EMDK)。

标签: c# windows-mobile compact-framework windows-mobile-6.5 .net-cf-3.5


【解决方案1】:

也检查这个线程。有趣的线程调用和监控设备连接状态以及在 windows mobile 上打开和关闭蜂窝无线电。

http://www.codeproject.com/Messages/4117749/Re-Csharp-Wrapper.aspx

【讨论】:

    【解决方案2】:

    首先:导入这些 dll

        [DllImport("ossvcs.dll", EntryPoint = "#276", CharSet = CharSet.Unicode)]
        private static extern uint GetWirelessDevice(ref IntPtr pDevice, int pDevVal);
    
        [DllImport("ossvcs.dll", EntryPoint = "#273", CharSet = CharSet.Unicode)]
        private static extern uint ChangeRadioState(ref RDD pDevice, int dwState, int saveAction);
    
        [DllImport("ossvcs.dll", EntryPoint = "#280", CharSet = CharSet.Unicode)]
        private static extern uint FreeDeviceList(IntPtr pDevice);
    

    这是我用于摩托罗拉 MC65 的代码副本,它也应该适用于您的代码。

        [StructLayout(LayoutKind.Auto)]
        struct RADIODEVSTATE
        {
            public const int RADIODEVICES_ON = 1;
            public const int RADIODEVICES_OFF = 0;
        }
    
        /*
        typedef enum _RADIODEVTYPE
        {
            RADIODEVICES_MANAGED = 1,
            RADIODEVICES_PHONE,
            RADIODEVICES_BLUETOOTH,
        } RADIODEVTYPE;
         */
        [StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)]
        struct RADIODEVTYPE
        {
            public const int RADIODEVICES_MANAGED = 1;
            public const int RADIODEVICES_PHONE = 2;
            public const int RADIODEVICES_BLUETOOTH = 3;
        }
    
        /*
        typedef enum _SAVEACTION
        {
            RADIODEVICES_DONT_SAVE = 0,
            RADIODEVICES_PRE_SAVE,
            RADIODEVICES_POST_SAVE,
        } SAVEACTION;
         */
        [StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)]
        struct SAVEACTION
        {
            public const int RADIODEVICES_DONT_SAVE = 0;
            public const int RADIODEVICES_PRE_SAVE = 1;
            public const int RADIODEVICES_POST_SAVE = 2;
        }
    
        /*
        struct RDD 
        {
            RDD() : pszDeviceName(NULL), pNext(NULL), pszDisplayName(NULL) {}
            ~RDD() { LocalFree(pszDeviceName); LocalFree(pszDisplayName); }
            LPTSTR   pszDeviceName;  // Device name for registry setting.
            LPTSTR   pszDisplayName; // Name to show the world
            DWORD    dwState;        // ON/off/[Discoverable for BT]
            DWORD    dwDesired;      // desired state - used for setting registry etc.
            RADIODEVTYPE    DeviceType;         // Managed, phone, BT etc.
            RDD * pNext;    // Next device in list
        }; //radio device details
         */
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        struct RDD
        {
            [MarshalAs(UnmanagedType.LPTStr)]
            public string pszDeviceName;
    
            [MarshalAs(UnmanagedType.LPTStr)]
            public string pszDisplayName;
    
            public uint dwState;
            public uint dwDesired;
            public int DeviceType;
            public IntPtr pNext;
        }
    
    
        private static bool SetDeviceState(int dwDevice, int dwState)
        {
            var pDevice = new IntPtr(0);
    
            //Get the first wireless device
            var result = GetWirelessDevice(ref pDevice, 0);
    
            if (result != 0)
                return false;
    
                //While we're still looking at wireless devices
                while (pDevice != IntPtr.Zero)
                {
                    //Marshall the pointer into a C# structure
                    var device = (RDD)System.Runtime.InteropServices.Marshal.PtrToStructure(pDevice, typeof(RDD));
    
                    //If this device is the device we're looking for
                    if (device.DeviceType == dwDevice)
                    {
                        //Change the state of the radio
                        result = ChangeRadioState(ref device, dwState, SAVEACTION.RADIODEVICES_PRE_SAVE);
                    }
    
                    //Set the pointer to the next device in the linked list
                    pDevice = device.pNext;
                }
    
                //Free the list of devices
                FreeDeviceList(pDevice);
    
            //Turning off radios doesn't correctly report the status, so return true anyway.
            return result == 0 || dwState == RADIODEVSTATE.RADIODEVICES_OFF;
        }
    

    要关闭手机,只需调用以下方法:

        /// <summary>
        /// Disables the phone radio on device
        /// </summary>
        public void DisablePhoneRadio()
        {
                SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_OFF);
        }
    

    因此,只需使用所需的任何条件语句,并在需要禁用它时调用 DisablePhoneRadio(),并在启用电话无线电时,只需像这样用 RADIODEVSTATE.RADIODEVICES_ON 敲击 RADIODEVSTATE.RADIODEVICES_OFF:

        /// <summary>
        /// Enables the phone radio on device
        /// </summary>
        public void EnablePhoneRadio()
        {
                SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_ON);
        }
    

    希望这会有所帮助!

    【讨论】:

      【解决方案3】:

      您需要从ossvcs.dll 发送/调用GetDeviceListChangeRadioState。实际执行此操作的代码对于 SO 帖子来说有点长,所以我会把它留给你来解决 - 这并不是很难(有一些 C code here,甚至还有一些 C# code on CodeProject,我'没用过所以YMMV)。

      另一种选择是在 SDF 中使用 Radios 类,它已经封装了这些。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-08
        • 1970-01-01
        • 2010-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多