在 Windows Mobile 6/C# 中监控 WLAN 无线电连接

发布于 2024-07-13 11:05:02 字数 339 浏览 6 评论 0原文

我目前正在开发一个针对 HP IPAQ 210 的应用程序。该应用程序的一部分需要启用/打开 WLAN 无线电以连接到预先配置的接入点。 我目前正在使用 IPAQ SDK(通过 P/Invoke)来启用 WLAN 无线电,但我无法可靠地确定无线电何时与首选接入点建立连接。 我当前正在监视 Microsoft.WindowsMo​​bile.Status.SystemState.WiFiStateConnected 属性,但我更愿意订阅一个事件,以便在建立连接时收到通知。

我在 OpenNETCF 库中浏览了一下,2.3 中似乎有一些有前途的东西,但我们暂时停留在 2.2 上。

有没有可靠的方法来确定连接状态?

I am currently developing an app targeted for the HP IPAQ 210. Part of this app requires the WLAN radio to be enabled/powered on to connect to a pre-configured access point. I'm currently using the IPAQ SDK (via P/Invoke) to enable the WLAN radio, but I'm having trouble reliably determining when the radio has established a connection with the preferred access point. I'm currently monitoring the Microsoft.WindowsMobile.Status.SystemState.WiFiStateConnected property, but I would prefer to subscribe to an event to be notified when the connection is established.

I've looked around a bit in the OpenNETCF library, and there seems to be promising things in 2.3, but we're stuck on 2.2 for the moment.

Is there a reliable way to determine the connection status?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

⒈起吃苦の倖褔 2024-07-20 11:05:04
System.Windows.Forms.Button Btn = new System.Windows.Forms.Button();
if (flag == true)
{
    for (int i = 0; i < node; i++)
    {
        Btn = new Button();
        Btn.Height = 25;
        Btn.Width =30;
        Btn.ForeColor = Color.Blue;
        Btn.BackColor = Color.Brown;                 
        Btn.AutoSize = false;
        x = rd.Next(130, 800);
        y = rd.Next(130, 500);
        Btn.Location = new Point(x, y);
        Console.WriteLine(x + "," + y);
        Btn.Text = "U" + i.ToString();
        Btn.Name = "U" + i.ToString();
        m_streamWriter.WriteLine("{0} {1} {2}",
                                 Btn.Name.ToString(),
                                 Btn.Location.X.ToString(),
                                 Btn.Location.Y.ToString());
        Btn.Click += new System.EventHandler(this.Btn_Click);
        this.Controls.Add(Btn);                    
    }
    flag = false;
    m_streamWriter.Dispose();
    startConvert();
    get_combo1();                          
}
System.Windows.Forms.Button Btn = new System.Windows.Forms.Button();
if (flag == true)
{
    for (int i = 0; i < node; i++)
    {
        Btn = new Button();
        Btn.Height = 25;
        Btn.Width =30;
        Btn.ForeColor = Color.Blue;
        Btn.BackColor = Color.Brown;                 
        Btn.AutoSize = false;
        x = rd.Next(130, 800);
        y = rd.Next(130, 500);
        Btn.Location = new Point(x, y);
        Console.WriteLine(x + "," + y);
        Btn.Text = "U" + i.ToString();
        Btn.Name = "U" + i.ToString();
        m_streamWriter.WriteLine("{0} {1} {2}",
                                 Btn.Name.ToString(),
                                 Btn.Location.X.ToString(),
                                 Btn.Location.Y.ToString());
        Btn.Click += new System.EventHandler(this.Btn_Click);
        this.Controls.Add(Btn);                    
    }
    flag = false;
    m_streamWriter.Dispose();
    startConvert();
    get_combo1();                          
}
安穩 2024-07-20 11:05:03

它很难看,也不是事件,但如果所有其他方法都失败,您可以尝试通过读取其注册表项来检查 Wifi 硬件状态:

int key = (int)Registry.GetValue("HKEY_LOCAL_MACHINE\\System\\State\\Hardware", "WiFi", -1);

It is ugly, and it is no event, but if all else fails, you could try and check the Wifi hardware state by reading it's registry key:

int key = (int)Registry.GetValue("HKEY_LOCAL_MACHINE\\System\\State\\Hardware", "WiFi", -1);
戏剧牡丹亭 2024-07-20 11:05:03

因此,如果其他人遇到这种情况,我发现上述注册表项方法大多可靠,但我需要一种更可靠的方法。 我已转而使用 OpenNETCF 2.2 NetworkInformation 库来监视 WirelessZeroConfigInterface 的 CurrentIPAddress 属性。 我仍在使用 IPAQUtils 来管理 WLAN 无线电电源(我发现缺少 OpenNETCF 2.2 无线电控制,并且设备只有一个 WiFi 网络条目),但以下是我监控接口 IP 地址的方法:

NetworkInterface[] netIntfs = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in netIntfs)
{
    if (ni is WirelessZeroConfigNetworkInterface)
    {
       wzcni = (WirelessZeroConfigNetworkInterface)ni;
    }
}

while (wzcni.CurrentIpAddress.ToString() == "0.0.0.0" && tryCount < 10)
{
    wzcni.Refresh();
    System.Threading.Thread.Sleep(3000);
    tryCount++;
}

So, in case anyone else happens upon this, I've found the registry key method described above to mostly reliable, but I needed a more reliable method. I've moved to using the OpenNETCF 2.2 NetworkInformation library to monitor the CurrentIPAddress property of the WirelessZeroConfigInterface. I'm still using the IPAQUtils for managing the WLAN radio power (I've found the OpenNETCF 2.2 radio control to be lacking and the device will only have a single WiFi network entry), but here's how I monitor the IP Address of the interface:

NetworkInterface[] netIntfs = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in netIntfs)
{
    if (ni is WirelessZeroConfigNetworkInterface)
    {
       wzcni = (WirelessZeroConfigNetworkInterface)ni;
    }
}

while (wzcni.CurrentIpAddress.ToString() == "0.0.0.0" && tryCount < 10)
{
    wzcni.Refresh();
    System.Threading.Thread.Sleep(3000);
    tryCount++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文