Example #1
0
        public void InitializeNetwork()
        {
            var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ENC28J60.NetworkController");

            var networkInterfaceSetting = new EthernetNetworkInterfaceSettings();

            var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings();

            var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = chipSelectPin,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiApiName  = SpiAPI;
            networkCommunicationInterfaceSettings.GpioApiName = SC20100.GpioPin.Id;
            networkCommunicationInterfaceSettings.SpiSettings = settings;

            networkCommunicationInterfaceSettings.InterruptPin       = ethInterruptPin;
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;

            networkCommunicationInterfaceSettings.ResetPin         = ethResetPin;
            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            networkInterfaceSetting.Address        = new IPAddress(StringToIP(IP));
            networkInterfaceSetting.SubnetMask     = new IPAddress(StringToIP(SubnetMask));
            networkInterfaceSetting.GatewayAddress = new IPAddress(StringToIP(Gateway));
            networkInterfaceSetting.DnsAddresses   = new IPAddress[] { new IPAddress(StringToIP(DNS)) };

            networkInterfaceSetting.MacAddress    = MacAddress;
            networkInterfaceSetting.IsDhcpEnabled = false;

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;

            networkController.Enable();

            //Wait until we get a link
            while (!HasLink)
            {
                Debug.WriteLine("Waiting for network link...");
                Thread.Sleep(1000);
            }

            Debug.WriteLine("Network link achieved!");
        }
Example #2
0
        private void ConnectWifi()
        {
            var enablePin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA8);

            enablePin.SetDriveMode(GpioPinDriveMode.Output);
            enablePin.Write(GpioPinValue.High);

            var networkCommunicationInterfaceSettings =
                new SpiNetworkCommunicationInterfaceSettings();

            var cs = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                     OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PA6);

            var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = cs,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiApiName         = SC20260.SpiBus.Spi3;
            networkCommunicationInterfaceSettings.GpioApiName        = SC20260.GpioPin.Id;
            networkCommunicationInterfaceSettings.SpiSettings        = settings;
            networkCommunicationInterfaceSettings.InterruptPin       = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PF10);
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
            networkCommunicationInterfaceSettings.ResetPin           = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PF8);
            networkCommunicationInterfaceSettings.ResetActiveState   = GpioPinValue.Low;

            var networkController = NetworkController.FromName
                                        ("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");

            var networkInterfaceSetting = new WiFiNetworkInterfaceSettings()
            {
                Ssid     = this.ssidTextBox.Text,
                Password = this.passwordTextBox.Text,
            };

            networkInterfaceSetting.Address             = new IPAddress(new byte[] { 192, 168, 1, 122 });
            networkInterfaceSetting.SubnetMask          = new IPAddress(new byte[] { 255, 255, 255, 0 });
            networkInterfaceSetting.GatewayAddress      = new IPAddress(new byte[] { 192, 168, 1, 1 });
            networkInterfaceSetting.DnsAddresses        = new IPAddress[] { new IPAddress(new byte[] { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };
            networkInterfaceSetting.MacAddress          = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
            networkInterfaceSetting.IsDhcpEnabled       = true;
            networkInterfaceSetting.IsDynamicDnsEnabled = true;
            networkInterfaceSetting.TlsEntropy          = new byte[] { 0, 1, 2, 3 };
            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);
            networkController.SetAsDefaultController();
            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;
            networkController.Enable();
        }
        static void initializeNetwork()
        {
            networkController       = GHIElectronics.TinyCLR.Devices.Network.NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ENC28J60.NetworkController");
            networkInterfaceSetting = new GHIElectronics.TinyCLR.Devices.Network.EthernetNetworkInterfaceSettings();
            networkCommunicationInterfaceSettings = new GHIElectronics.TinyCLR.Devices.Network.SpiNetworkCommunicationInterfaceSettings();
            cs       = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PD3);
            settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = cs,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };
            networkCommunicationInterfaceSettings.SpiApiName  = GHIElectronics.TinyCLR.Pins.SC20100.SpiBus.Spi3;
            networkCommunicationInterfaceSettings.GpioApiName = GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.Id;

            networkCommunicationInterfaceSettings.SpiSettings  = settings;
            networkCommunicationInterfaceSettings.InterruptPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().OpenPin
                                                                     (GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PC5);
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;

            networkCommunicationInterfaceSettings.ResetPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().OpenPin
                                                                 (GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PD4);
            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            //networkInterfaceSetting.Address = new System.Net.IPAddress(new byte[] { 10, 1, 1, 1 });
            networkInterfaceSetting.Address = new System.Net.IPAddress(new byte[] { 192, 168, 1, 32 });

            networkInterfaceSetting.SubnetMask = new System.Net.IPAddress(new byte[] { 255, 255, 255, 0 });
            // networkInterfaceSetting.GatewayAddress = new System.Net.IPAddress(new byte[] { 10, 1, 1, 1 });
            // networkInterfaceSetting.DnsAddresses = new System.Net.IPAddress[] { new System.Net.IPAddress(new byte[]
            // { 75, 75, 75, 75 }), new System.Net.IPAddress(new byte[] { 75, 75, 75, 76 }) };

            networkInterfaceSetting.MacAddress          = new byte[] { 0xEC, 0xAD, 0xB8, 0x74, 0xF1, 0x7C };
            networkInterfaceSetting.IsDhcpEnabled       = false;
            networkInterfaceSetting.IsDynamicDnsEnabled = false;

            networkInterfaceSetting.TlsEntropy = new byte[] { 0, 1, 2, 3 };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;

            networkController.Enable();
            System.Diagnostics.Debug.WriteLine("Network is ready to use:   ");

            Thread.Sleep(100);
        }
Example #4
0
        public static void SetupEthernet()
        {
            // SC20100 development board using ETH Click in slot 1

            var networkController = NetworkController.FromName
                                        ("GHIElectronics.TinyCLR.NativeApis.ENC28J60.NetworkController");

            var networkInterfaceSetting = new EthernetNetworkInterfaceSettings();
            var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings();

            var settings = new SpiConnectionSettings()
            {
                ChipSelectLine      = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD3),
                ClockFrequency      = 4000000,
                Mode                = SpiMode.Mode0,
                ChipSelectType      = SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiApiName   = SC20100.SpiBus.Spi3;
            networkCommunicationInterfaceSettings.GpioApiName  = SC20100.GpioPin.Id;
            networkCommunicationInterfaceSettings.SpiSettings  = settings;
            networkCommunicationInterfaceSettings.InterruptPin =
                GpioController.GetDefault().OpenPin(SC20100.GpioPin.PC5);

            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
            networkCommunicationInterfaceSettings.ResetPin           =
                GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD4);

            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            networkInterfaceSetting.MacAddress = new byte[] { 0x3E, 0x4B, 0x27, 0x21, 0x61, 0x57 };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);
            networkController.SetAsDefaultController();
            networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
            networkController.Enable();

            while (linkReady == false)
            {
                ;
            }

            Debug.WriteLine("Network is Ready");
        }
Example #5
0
        private static EthClickDevice SC20100Slot1Device()
        {
            // Create GPIO reset pin
            var resetPin = HardwareProvider.Gpio.OpenPin(SC20100.GpioPin.PD4);

            resetPin.SetDriveMode(GpioPinDriveMode.Output);

            // Create spi settings
            var spiSettings = new SpiConnectionSettings()
            {
                ChipSelectLine      = HardwareProvider.Gpio.OpenPin(SC20100.GpioPin.PD3),
                ClockFrequency      = 4000000,
                Mode                = SpiMode.Mode0,
                ChipSelectType      = SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            var spiNetworkSettings = new SpiNetworkCommunicationInterfaceSettings()
            {
                SpiApiName         = SC20100.SpiBus.Spi3,
                GpioApiName        = SC20100.GpioPin.Id,
                InterruptPin       = HardwareProvider.Gpio.OpenPin(SC20100.GpioPin.PC5),
                InterruptEdge      = GpioPinEdge.FallingEdge,
                InterruptDriveMode = GpioPinDriveMode.InputPullUp,
                ResetPin           = resetPin,
                ResetActiveState   = GpioPinValue.Low,
                SpiSettings        = spiSettings
            };

            // Create network controller
            var controller = NetworkController.FromName(SC20100.NetworkController.Enc28j60);

            controller.SetCommunicationInterfaceSettings(spiNetworkSettings);

            return(new EthClickDevice(controller, resetPin));;
        }
Example #6
0
        static void SetupWiFi7Click_SC20100_MicroBus1()
        {
            var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8);

            enablePin.SetDriveMode(GpioPinDriveMode.Output);
            enablePin.Write(GpioPinValue.High);

            SpiNetworkCommunicationInterfaceSettings networkCommunicationInterfaceSettings =
                new SpiNetworkCommunicationInterfaceSettings();


            var cs = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                     OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PD15);


            var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = cs,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiApiName =
                GHIElectronics.TinyCLR.Pins.SC20100.SpiBus.Spi3;

            networkCommunicationInterfaceSettings.GpioApiName =
                GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.Id;

            networkCommunicationInterfaceSettings.SpiSettings  = settings;
            networkCommunicationInterfaceSettings.InterruptPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                                                                 OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PB12);
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
            networkCommunicationInterfaceSettings.ResetPin           = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                                                                       OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PB13);
            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            networkController = NetworkController.FromName
                                    ("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");

            WiFiNetworkInterfaceSettings networkInterfaceSetting = new WiFiNetworkInterfaceSettings()
            {
                Ssid     = wiFiSSID_1,
                Password = wiFiKey_1,
            };

            networkInterfaceSetting.Address        = new IPAddress(new byte[] { 192, 168, 1, 122 });
            networkInterfaceSetting.SubnetMask     = new IPAddress(new byte[] { 255, 255, 255, 0 });
            networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });

            // networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
            // { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

            //networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
            networkInterfaceSetting.MacAddress = new byte[] { 0x4A, 0x28, 0x05, 0x2A, 0xA4, 0x0F };

            networkInterfaceSetting.DhcpEnable = true;

            networkInterfaceSetting.TlsEntropy = new byte[] { 1, 2, 3, 4 };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings
                (networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged +=
                NetworkController_NetworkLinkConnectedChanged;


            networkController.Enable();


            while (linkReady == false)
            {
                ;
            }

            // Network is ready to used
        }
Example #7
0
        public static void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_lock)
            {
                if (_initialized)
                {
                    return;
                }

                var _dhcpEvent = new AutoResetEvent(false);

                // Create GPIO reset pin
                var resetPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB13);
                resetPin.SetDriveMode(GpioPinDriveMode.Output);

                // Toggle reset pin and wait for reset completion
                resetPin.Write(GpioPinValue.Low);
                Thread.Sleep(100);
                resetPin.Write(GpioPinValue.High);
                Thread.Sleep(100);

                // Create spi settings
                var spiSettings = new SpiConnectionSettings()
                {
                    ChipSelectLine      = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD15),
                    ClockFrequency      = 4000000,
                    Mode                = SpiMode.Mode0,
                    ChipSelectType      = SpiChipSelectType.Gpio,
                    ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                    ChipSelectSetupTime = TimeSpan.FromTicks(10)
                };

                // Create network settngs
                var spiNetworkSettings = new SpiNetworkCommunicationInterfaceSettings()
                {
                    SpiApiName         = SC20100.SpiBus.Spi3,
                    GpioApiName        = SC20100.GpioPin.Id,
                    InterruptPin       = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB12),
                    InterruptEdge      = GpioPinEdge.FallingEdge,
                    InterruptDriveMode = GpioPinDriveMode.InputPullUp,
                    ResetPin           = resetPin,
                    ResetActiveState   = GpioPinValue.Low,
                    SpiSettings        = spiSettings
                };

                // Create WiFi settings
                var wifiNetworkSettings = new WiFiNetworkInterfaceSettings()
                {
                    Ssid     = "crytek",
                    Password = "******",
                };

                // Create network controller
                Controller = NetworkController.FromName(SC20100.NetworkController.ATWinc15x0);
                Controller.SetCommunicationInterfaceSettings(spiNetworkSettings);
                Controller.SetInterfaceSettings(wifiNetworkSettings);
                Controller.SetAsDefaultController();
                Controller.NetworkLinkConnectedChanged += NetworkLinkConnectedChanged;
                Controller.NetworkAddressChanged       += NetworkAddressChanged;

                // Create GPIO enable pin
                var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8);
                enablePin.SetDriveMode(GpioPinDriveMode.Output);
                enablePin.Write(GpioPinValue.High);

                Controller.Enable();

                _initialized = true;
            }
        }
Example #8
0
 private extern void SetCommunicationInterfaceSettings(SpiNetworkCommunicationInterfaceSettings settings);
Example #9
0
        private bool DoTestWifi()
        {
            this.UpdateStatusText("Checking wifi firmware...", true);

            if (this.doTestWifiPassed)
            {
                return(true);
            }

            var gpioController = GpioController.GetDefault();

            var resetPin = gpioController.OpenPin(SC20260.GpioPin.PC3);
            var csPin    = gpioController.OpenPin(SC20260.GpioPin.PA6);
            var intPin   = gpioController.OpenPin(SC20260.GpioPin.PF10);
            var enPin    = gpioController.OpenPin(SC20260.GpioPin.PA8);

            enPin.SetDriveMode(GpioPinDriveMode.Output);
            resetPin.SetDriveMode(GpioPinDriveMode.Output);

            enPin.Write(GpioPinValue.Low);
            resetPin.Write(GpioPinValue.Low);
            Thread.Sleep(100);

            enPin.Write(GpioPinValue.High);
            resetPin.Write(GpioPinValue.High);

            var result = false;

            var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = csPin,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings {
                SpiApiName         = SC20260.SpiBus.Spi3,
                GpioApiName        = "GHIElectronics.TinyCLR.NativeApis.STM32H7.GpioController\\0",
                SpiSettings        = settings,
                InterruptPin       = intPin,
                InterruptEdge      = GpioPinEdge.FallingEdge,
                InterruptDriveMode = GpioPinDriveMode.InputPullUp,
                ResetPin           = resetPin,
                ResetActiveState   = GpioPinValue.Low
            };

            var networkInterfaceSetting = new WiFiNetworkInterfaceSettings()
            {
                Ssid     = " ",
                Password = "******",
            };

            networkInterfaceSetting.Address        = new IPAddress(new byte[] { 192, 168, 1, 122 });
            networkInterfaceSetting.SubnetMask     = new IPAddress(new byte[] { 255, 255, 255, 0 });
            networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
            networkInterfaceSetting.DnsAddresses   = new IPAddress[] { new IPAddress(new byte[] { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

            //networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 };
            networkInterfaceSetting.IsDhcpEnabled       = true;
            networkInterfaceSetting.IsDynamicDnsEnabled = true;

            var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);
            networkController.SetAsDefaultController();
            var firmware = Winc15x0Interface.GetFirmwareVersion();

            if (firmware.IndexOf("19.5.") == 0 || (firmware.IndexOf("19.6.") == 0))
            {
                result = true;
            }

            resetPin.Dispose();
            csPin.Dispose();
            intPin.Dispose();
            enPin.Dispose();

            this.doTestWifiPassed = result;

            return(result);
        }
Example #10
0
        public WifiWindow(Bitmap icon, string text, int width, int height) : base(icon, text, width, height)
        {
            this.networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings();

            this.font = Resources.GetFont(Resources.FontResources.droid_reg12);

            this.ipAddressLable = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, this.ipAddress)
            {
                ForeColor = Colors.White,
            };

            this.gatewayLabel = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, this.gateway)
            {
                ForeColor = Colors.White,
            };

            this.subnetmaskLabel = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, this.subnetmask)
            {
                ForeColor = Colors.White,
            };

            this.dnsLable1 = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, this.dns1)
            {
                ForeColor = Colors.White,
            };

            this.dnsLable2 = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, this.dns2)
            {
                ForeColor = Colors.White,
            };

            this.selectMikroBus = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, "Connect wifi click to MikroBus 1")
            {
                ForeColor = Colors.White,
            };

            this.status = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, " ")
            {
                ForeColor = Colors.White,
            };

            this.ssidLabel = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, "SSID:")
            {
                ForeColor = Colors.White,
                Width     = 80,
            };

            this.passwordLable = new GHIElectronics.TinyCLR.UI.Controls.Text(this.font, "Password:"******"Connect")
                {
                    ForeColor           = Colors.Black,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                },
                Width  = 100,
                Height = 30,
            };

            this.connectButton.Click += this.ConnectButton_Click;

            OnScreenKeyboard.Font = this.font;

            this.networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");

            //this.isWifiConnected = false;

            this.isRunning = false;
        }
Example #11
0
        private static void SetupEnc28_SC20260D_MicroBus1()
        {
            networkController = NetworkController.FromName
                                    ("GHIElectronics.TinyCLR.NativeApis.ENC28J60.NetworkController");

            var networkInterfaceSetting = new EthernetNetworkInterfaceSettings();

            var networkCommunicationInterfaceSettings = new
                                                        SpiNetworkCommunicationInterfaceSettings();

            var cs = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                     OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PG12);

            var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings()
            {
                ChipSelectLine      = cs,
                ClockFrequency      = 4000000,
                Mode                = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0,
                ChipSelectType      = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiApiName =
                GHIElectronics.TinyCLR.Pins.SC20260.SpiBus.Spi3;

            networkCommunicationInterfaceSettings.GpioApiName =
                GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.Id;

            networkCommunicationInterfaceSettings.SpiSettings  = settings;
            networkCommunicationInterfaceSettings.InterruptPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                                                                 OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PG6);
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
            networkCommunicationInterfaceSettings.ResetPin           = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault().
                                                                       OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PI8);
            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            networkInterfaceSetting.Address        = new IPAddress(new byte[] { 192, 168, 1, 122 });
            networkInterfaceSetting.SubnetMask     = new IPAddress(new byte[] { 255, 255, 255, 0 });
            networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
            networkInterfaceSetting.DnsAddresses   = new IPAddress[] { new IPAddress(new byte[]
                                                                                     { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

            networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
            networkInterfaceSetting.DhcpEnable = true;
            networkInterfaceSetting.DhcpEnable = true;

            networkInterfaceSetting.TlsEntropy = new byte[] { 0, 1, 2, 3 };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings
                (networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged +=
                NetworkController_NetworkLinkConnectedChanged;

            networkController.Enable();

            while (linkReady == false)
            {
                ;
            }

            System.Diagnostics.Debug.WriteLine("Network is ready to use");
        }
        //ETHERNET SETUP
        static void SetupEnc28_MicroBus(string _SpiApiName, int _cs, int _intPin, int _rst, string _GpioApiName)
        {
            networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ENC28J60.NetworkController");

            var networkInterfaceSetting = new EthernetNetworkInterfaceSettings();
            var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings();

            networkCommunicationInterfaceSettings.SpiApiName  = _SpiApiName;
            networkCommunicationInterfaceSettings.GpioApiName = _GpioApiName;

            var cs = GpioController.GetDefault().OpenPin(_cs);

            var settings = new SpiConnectionSettings()
            {
                ChipSelectLine      = cs,
                ClockFrequency      = 4000000,
                Mode                = SpiMode.Mode0,
                ChipSelectType      = SpiChipSelectType.Gpio,
                ChipSelectHoldTime  = TimeSpan.FromTicks(10),
                ChipSelectSetupTime = TimeSpan.FromTicks(10)
            };

            networkCommunicationInterfaceSettings.SpiSettings = settings;

            networkCommunicationInterfaceSettings.InterruptPin       = GpioController.GetDefault().OpenPin(_intPin);
            networkCommunicationInterfaceSettings.InterruptEdge      = GpioPinEdge.FallingEdge;
            networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;

            networkCommunicationInterfaceSettings.ResetPin         = GpioController.GetDefault().OpenPin(_rst);
            networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low;

            networkInterfaceSetting.Address        = new IPAddress(new byte[] { 192, 168, 2, 122 });
            networkInterfaceSetting.SubnetMask     = new IPAddress(new byte[] { 255, 255, 255, 0 });
            networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 2, 1 });
            networkInterfaceSetting.DnsAddresses   = new IPAddress[] { new IPAddress(new byte[] { 8, 8, 8, 8 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

            networkInterfaceSetting.MacAddress          = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
            networkInterfaceSetting.IsDhcpEnabled       = true;
            networkInterfaceSetting.IsDynamicDnsEnabled = true;

            networkInterfaceSetting.TlsEntropy = new byte[] { 0, 1, 2, 3 };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged       += NetworkController_NetworkAddressChanged;;
            networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;;

            networkController.Enable();

            while (linkReady == false)
            {
                ;
            }
            Debug.WriteLine("===================================");
            Debug.WriteLine("Network is ready to use:");
            Debug.WriteLine("===================================");
            Debug.WriteLine(networkController.GetIPProperties().Address.ToString());
            Debug.WriteLine(networkController.GetIPProperties().SubnetMask.ToString());
            Debug.WriteLine(networkController.GetIPProperties().GatewayAddress.ToString());
            Debug.WriteLine(networkController.GetIPProperties().DnsAddresses[1].ToString());
            Debug.WriteLine(UTF8Encoding.UTF8.GetString(networkController.GetInterfaceProperties().MacAddress));
            Debug.WriteLine("===================================");
        }