Пример #1
0
        private Program()
        {
            OneTimeConfig();

            _lcd = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            Touch.Initialize(this);

            this.MainWindow = new Window();
            this.MainWindow.TouchDown += MainWindow_TouchDown;
            this.MainWindow.TouchUp += MainWindow_TouchUp;
            this.MainWindow.TouchMove += MainWindow_TouchMove;

            var eth = new EthernetBuiltIn();
            eth.Open();
            if (!eth.CableConnected)
            {
                eth.Close();
                var wifi = new WiFiRS9110(SPI.SPI_module.SPI1, G400.PD13, G400.PD12, G400.PD15);
                _netif = wifi;
                _netif.Open();
                wifi.Join("XXX", "XXX");
            }
            else
            {
                _netif = eth;
            }
            if (!_netif.IsDhcpEnabled)
                _netif.EnableDhcp();
            if (!_netif.IsDynamicDnsEnabled)
                _netif.EnableDynamicDns();

            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
        }
        public static void initWiFi(WiFiRS9110 wifi, String ssid, String passphrase)
        {
            if (!wifi.IsOpen)
                wifi.Open();
            wifi.NetworkInterface.EnableDhcp();
            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi);

            /*
            wifi.WirelessConnectivityChanged +=
                new WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
            wifi.NetworkAddressChanged +=
               new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
            */

            // Scan for networks and connect if found
            WiFiNetworkInfo[] ScanResp = wifi.Scan();
            int i = 0;
            foreach (WiFiNetworkInfo info in ScanResp)
            {
                Debug.Print("Found WLAN: " + i + ", " + info.SSID);
                if (info.SSID.ToString().Equals(ssid))
                {
                    wifi.Join(ScanResp[i], passphrase);
                    break;
                }
                i++;
            }
        }
Пример #3
0
        private bool Join(WiFiNetworkInfo ni)
        {
            if (wifi.IsLinkConnected)
            {
                return(true);
            }

            try
            {
                Debug.Print("Connecting to " + ni.SSID + "...");
                //blocker.Reset();
                wifi.Join(ni, password);

                while (wifi.NetworkInterface.IPAddress == "0.0.0.0")
                {
                    Debug.Print("Waiting for IPAddress");
                    Thread.Sleep(250);
                }
            }
            catch (NetworkInterfaceExtensionException e)
            {
                switch (e.errorCode)
                {
                case NetworkInterfaceExtensionException.ErrorCode.AuthenticationFailed: Debug.Print("AuthenticationFailed"); break;

                //case NetworkInterfaceExtensionException.ErrorCode.AlreadyActivated: break;
                default: Debug.Print(e.errorCode.ToString()); break;
                }
                //Debug.Print("Error Message: " + e.ErrorMsg);
                //if (e.errorCode != NetworkInterfaceExtensionException.ErrorCode.AlreadyActivated)
                return(false);
            }
            catch (Exception e)
            {
                Debug.Print("Error Message: " + e.Message);
                return(false);
            }

            Debug.Print("Done connecting...\n");
            //blocker.WaitOne();
            Debug.Print("We got NetworkAvailable event. WiFi link is ready!\n");

            return(true);
        }
Пример #4
0
 public bool Connect(string ssid, string passphrase)
 {
     WiFiNetworkInfo[] ScanResults = wifi.Scan();
     foreach (WiFiNetworkInfo info in ScanResults)
     {
         Debug.Print("Found WLAN: " + info.SSID);
         if (info.SSID.ToString().Equals(ssid))
         {
             wifi.Join(info, passphrase);
             Debug.Print("spinning");
             while (!wifi.IsLinkConnected)
             {
                 ;
             }
             Debug.Print("no longer spinning");
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
        private Program()
        {
            var eth = new EthernetBuiltIn();
            eth.Open();
            if (!eth.CableConnected)
            {
                eth.Close();
                var wifi = new WiFiRS9110(SPI.SPI_module.SPI2, G120E.Gpio.P3_30, G120E.Gpio.P2_30, G120E.Gpio.P4_31);
                _netif = wifi;
                _netif.Open();
                wifi.Join("XXX", "XXX");
            }
            else
            {
                _netif = eth;
            }
            if (!_netif.IsDhcpEnabled)
                _netif.EnableDhcp();
            if (!_netif.IsDynamicDnsEnabled)
                _netif.EnableDynamicDns();

            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
        }