I modified the WIFI example for FEZ Portal to work with FEZ Duino but get an exception when routine networkController.Enable() is called. Don’t know how to proceed.
An unhandled exception of type ‘System.ArgumentException’ occurred in GHIElectronics.TinyCLR.Devices.Network.dll
// my code
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Pins;
using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
namespace WIFI_Example
{
class Program
{
static void Main()
{
var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8);
enablePin.SetDriveMode(GpioPinDriveMode.Output);
enablePin.Write(GpioPinValue.High);
SpiNetworkCommunicationInterfaceSettings netInterfaceSettings =
new SpiNetworkCommunicationInterfaceSettings();
var cs = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD15);
var settings = new SpiConnectionSettings()
{
ChipSelectLine = cs,
ClockFrequency = 4000000,
Mode = SpiMode.Mode0,
ChipSelectType = SpiChipSelectType.Gpio,
ChipSelectHoldTime = TimeSpan.FromTicks(10),
ChipSelectSetupTime = TimeSpan.FromTicks(10)
};
netInterfaceSettings.SpiApiName = SC20100.SpiBus.Spi3;
netInterfaceSettings.GpioApiName = SC20100.GpioPin.Id;
netInterfaceSettings.SpiSettings = settings;
netInterfaceSettings.InterruptPin = GpioController.GetDefault().
OpenPin(SC20100.GpioPin.PB12);
netInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge;
netInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
netInterfaceSettings.ResetPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB13);
netInterfaceSettings.ResetActiveState = GpioPinValue.Low;
var networkController = NetworkController.FromName
("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");
WiFiNetworkInterfaceSettings wifiSettings = new WiFiNetworkInterfaceSettings()
{
Ssid = "WIRE802",
Password = "7187946977",
};
wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 1, 122 });
wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
{ 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };
wifiSettings.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
wifiSettings.DhcpEnable = true;
wifiSettings.DynamicDnsEnable = true;
networkController.SetInterfaceSettings(wifiSettings);
networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
networkController.SetAsDefaultController();
networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
networkController.NetworkLinkConnectedChanged +=
NetworkController_NetworkLinkConnectedChanged;
networkController.Enable();
// Network is ready to use
Thread.Sleep(Timeout.Infinite);
}
private static void NetworkController_NetworkLinkConnectedChanged
(NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
{
// Raise event connect/disconnect
}
private static void NetworkController_NetworkAddressChanged
(NetworkController sender, NetworkAddressChangedEventArgs e)
{
var ipProperties = sender.GetIPProperties();
var address = ipProperties.Address.GetAddressBytes();
Debug.WriteLine("IP: " + address[0] + "." + address[1] + "." + address[2] +
"." + address[3]);
}
}
}