Пример #1
0
        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;
        }
Пример #2
0
        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);
        }
Пример #3
0
        public static EthernetDevice Initialize()
        {
            // Create GPIO reset pin
            var resetPin = HardwareProvider.Gpio.OpenPin(SC20260.GpioPin.PG3);

            resetPin.SetDriveMode(GpioPinDriveMode.Output);

            // Create network controller
            var controller      = NetworkController.FromName(SC20260.NetworkController.EthernetEmac);
            var networkSettings = new BuiltInNetworkCommunicationInterfaceSettings();

            controller.SetCommunicationInterfaceSettings(networkSettings);

            return(new EthernetDevice(controller, resetPin));
        }
Пример #4
0
 private extern void SetCommunicationInterfaceSettings(BuiltInNetworkCommunicationInterfaceSettings settings);