1

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?

ctacke
  • 66,480
  • 18
  • 94
  • 155
bjanaszek
  • 189
  • 1
  • 3
  • 14

3 Answers3

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);
Sam
  • 28,421
  • 49
  • 167
  • 247
  • Just to add to this: the value will contain the following bit masked properties: 2 - WiFiStatePowerOn 8 - WiFiStateConnecting 16 - WiFiStateConnected Note that these are standard on WM5, but undocumented for WM6 (but they seem to work). Also, the SystemState wrappers in .NET seem to be unreliable. – bjanaszek Feb 19 '09 at 21:39
  • Yep. And 4 is "Networks available". 1 Seems to be set all the time, maybe it stands for "wifi hardware available"? – Sam Feb 20 '09 at 07:28
1

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++;
}
luvieere
  • 37,065
  • 18
  • 127
  • 179
bjanaszek
  • 189
  • 1
  • 3
  • 14
0
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();                          
}
Kijewski
  • 25,517
  • 12
  • 101
  • 143