private void CreateEthernet() { this.resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); this.resetPin.Write(GpioPinValue.High); Thread.Sleep(100); this.networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.STM32H7.EthernetEmacController\\0"); var networkInterfaceSetting = new EthernetNetworkInterfaceSettings(); var networkCommunicationInterfaceSettings = new BuiltInNetworkCommunicationInterfaceSettings(); 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(networkCommunicationInterfaceSettings); this.networkController.SetAsDefaultController(); this.networkController.NetworkAddressChanged += this.NetworkController_NetworkAddressChanged; this.networkController.NetworkLinkConnectedChanged += this.NetworkController_NetworkLinkConnectedChanged; }
private bool DoTestEthernet() { var gpioController = GpioController.GetDefault(); var resetPin = gpioController.OpenPin(SC20260.GpioPin.PG3); resetPin.SetDriveMode(GpioPinDriveMode.Output); resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); resetPin.Write(GpioPinValue.High); Thread.Sleep(100); var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.STM32H7.EthernetEmacController\\0"); var networkInterfaceSetting = new EthernetNetworkInterfaceSettings(); var networkCommunicationInterfaceSettings = new BuiltInNetworkCommunicationInterfaceSettings(); 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; networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings); networkController.SetAsDefaultController(); networkController.NetworkAddressChanged += this.NetworkController_NetworkAddressChanged; networkController.NetworkLinkConnectedChanged += this.NetworkController_NetworkLinkConnectedChanged; var start = DateTime.Now; networkController.Enable(); while (this.ethernetConnect == false && this.isRunning) { var end = DateTime.Now - start; this.UpdateStatusText("Testing ethernet. If the connecting take more than 10 seconds, the test is failed.", true); this.UpdateStatusText(" ", false); this.UpdateStatusText(" - If the connecting takes more than 10 seconds, need to check the cable.", false); this.UpdateStatusText(" ", false); this.UpdateStatusText("Please wait for connnecting.... " + (int)(end.TotalSeconds), false); Thread.Sleep(1000); } networkController.Disable(); networkController.Dispose(); resetPin.Dispose(); return(this.ethernetConnect); }
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!"); }
public EthClickDevice(NetworkController networkController, GpioPin resetPin) : base(networkController, resetPin) { Settings = new EthernetNetworkInterfaceSettings { Address = new IPAddress(new byte[] { 192, 168, 1, 100 }), SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }), GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }), MacAddress = new byte[] { 0x3E, 0x4B, 0x27, 0x21, 0x61, 0x57 } }; networkController.SetInterfaceSettings(Settings); Reset(); }
/// <summary> /// Initialize SC20260D development board onboard ethernet. /// </summary> internal static void InitializeEthernet() { var networkController = NetworkController.FromName(SC20260.NetworkController.EthernetEmac); var networkInterfaceSetting = new EthernetNetworkInterfaceSettings { MacAddress = new byte[] { 0x00, 0x8D, 0xB4, 0x49, 0xAD, 0xBD } }; networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.NetworkAddressChanged += NetworkAddressChanged; networkController.SetAsDefaultController(); networkController.Enable(); }
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"); }
private static void InitializeEthernet() { var networkController = NetworkController.FromName(SC20260.NetworkController.EthernetEmac); var networkInterfaceSetting = new EthernetNetworkInterfaceSettings { MacAddress = new byte[] { 0x00, 0x8D, 0xA4, 0x49, 0xCD, 0xBD }, IsDhcpEnabled = true, IsDynamicDnsEnabled = true }; networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.SetAsDefaultController(); networkController.Enable(); }
private extern void SetInterfaceSettings(EthernetNetworkInterfaceSettings settings);
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("==================================="); }