利用SDF2.3获取Windows Mobile上的WiFi接入点信息

    在《Windows Mobile上的无线网络接入点扫描》一文中,讲述了用native code来获取WiFi接入点信息(名字、MAC地址、信号强度RSSI、Wifi信道以及是否需要密码等)的方法。然而,OpenNETCFSmart Device Framework为开发者提供了许多开发捷径,我们可以很方便地获得AP信息,直接使用C#语言,就只需几行代码就可以搞定。

    首先,新建一个智能设备项目,以VS2008+Windows Mobile 6.0 Professional为例,在新建好的项目中,加入对OpenNETCF和OpenNETCF.net的引用,如下图1所示:

截图02_2

图1 加入对OpenNETCF的引用

    然后,在Form.cs中,加入对OpenNETCF的引用。

        using OpenNETCF.Net;
        using OpenNETCF.Net.NetworkInformation;

    接着,在需要得到AP信息的地方,使用如下方式获得(以显示在listBox上的方式为例)

foreach (OpenNETCF.Net.NetworkInformation.INetworkInterface currentNetworkInterface in OpenNETCF.Net.NetworkInformation.WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces())
{
    // Make sure we are dealing with a WZC Network Interface
    if (currentNetworkInterface is OpenNETCF.Net.NetworkInformation.WirelessZeroConfigNetworkInterface)
    {
        // Get all the Nearby Access Points that the WZC Network Interface can see
        foreach (OpenNETCF.Net.NetworkInformation.AccessPoint currentAccessPoint in ((OpenNETCF.Net.NetworkInformation.WirelessZeroConfigNetworkInterface)currentNetworkInterface).NearbyAccessPoints)
        {
            // Output the name and the signal stregth of this access point
            this.listBox1.Items.Add(currentAccessPoint.Name + " : " + currentAccessPoint.SignalStrength.Decibels.ToString() + " : " + currentAccessPoint.PhysicalAddress.ToString());
        }
    }
}

    以下是在我的Cingular8125(WM6.0)上得到的结果:

Screen01

图2:测试结果图

    当然,在测试之前,需要事先打开WiFi模块,可以通过设备管理器打开,如下图2所示:

Screen02

图3:通过通讯管理打开无线WiFi

    也可以通过代码打开,即使用DevicePowerNotifySetDevicePower

 

参考链接:

1.Windows Mobile上的无线网络接入点扫描

2.Smart Device Framework

3.DevicePowerNotifySetDevicePower

posted on 2010-03-06 13:01  施炯  阅读(3149)  评论(1编辑  收藏  举报