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); }
private void CreateEthernet() { this.isRunning = true; // MikroBus 1 var gpioController = GpioController.GetDefault(); var start = DateTime.Now; try { Thread.Sleep(100); this.resetPin = gpioController.OpenPin(SC20260.GpioPin.PC3); this.csPin = gpioController.OpenPin(SC20260.GpioPin.PA6); this.intPin = gpioController.OpenPin(SC20260.GpioPin.PF10); this.enPin = gpioController.OpenPin(SC20260.GpioPin.PA8); this.enPin.SetDriveMode(GpioPinDriveMode.Output); this.resetPin.SetDriveMode(GpioPinDriveMode.Output); this.enPin.Write(GpioPinValue.Low); this.resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); this.enPin.Write(GpioPinValue.High); this.resetPin.Write(GpioPinValue.High); var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings() { ChipSelectLine = this.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) }; this.networkCommunicationInterfaceSettings.SpiApiName = SC20260.SpiBus.Spi3; this.networkCommunicationInterfaceSettings.GpioApiName = "GHIElectronics.TinyCLR.NativeApis.STM32H7.GpioController\\0"; this.networkCommunicationInterfaceSettings.SpiSettings = settings; this.networkCommunicationInterfaceSettings.InterruptPin = this.intPin; this.networkCommunicationInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge; this.networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp; this.networkCommunicationInterfaceSettings.ResetPin = this.resetPin; this.networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low; var networkInterfaceSetting = new WiFiNetworkInterfaceSettings() { Ssid = this.ssid.Text, Password = this.password.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, 0x04, 0x00, 0x00, 0x00, 0x00 }; networkInterfaceSetting.IsDhcpEnabled = true; networkInterfaceSetting.IsDynamicDnsEnabled = true; this.networkController.SetInterfaceSettings(networkInterfaceSetting); this.networkController.SetCommunicationInterfaceSettings(this.networkCommunicationInterfaceSettings); this.networkController.SetAsDefaultController(); this.networkController.NetworkAddressChanged += this.NetworkController_NetworkAddressChanged; this.networkController.NetworkLinkConnectedChanged += this.NetworkController_NetworkLinkConnectedChanged; var firmware = Winc15x0Interface.GetFirmwareVersion(); if (firmware.IndexOf("255.255.255.65535") == 0) { this.resetPin.Dispose(); this.csPin.Dispose(); this.intPin.Dispose(); this.enPin.Dispose(); Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.canvas.Children.Remove(this.status); Canvas.SetLeft(this.status, this.Width / 2 - this.Width / 4 - this.Width / 8 - this.Width / 16); Canvas.SetTop(this.status, this.Height - 40); this.canvas.Children.Add(this.status); this.status.TextContent = "Please reset application and type ssid, password correctly!"; this.status.Invalidate(); return(null); }, null); goto _return; } this.networkController.Enable(); } catch { } while ((DateTime.Now - start).TotalSeconds < 20) { if (this.isWifiConnected) { break; } Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.status.TextContent = "Please wait..." + (int)((DateTime.Now - start).TotalSeconds) + " / 20"; this.status.Invalidate(); return(null); }, null); Thread.Sleep(1000); } if (this.isWifiConnected == false) { Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.status.TextContent = "Wifi connection failed."; this.status.Invalidate(); return(null); }, null); this.resetPin.Dispose(); this.csPin.Dispose(); this.intPin.Dispose(); this.enPin.Dispose(); //var gpioControllerApi = new GpioControllerApiWrapper(NativeApi.Find(NativeApi.GetDefaultName(NativeApiType.GpioController), NativeApiType.GpioController)); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB3); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB4); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB5); //gpioController.Dispose(); } _return: this.isRunning = false; }