KG1
January 9, 2013, 3:22pm
1
With reference to: http://www.tinyclr.com/forum/topic?id=9473&page=7#msg100691 and my work on WiFi RS21 Module with UEXT Connector and EMX Development System:
using version 4.2, it appears that no matter which security mode I use the application enters a black hole (see output listed in 100691).
Page 36 EMX User Manual states: “Interrupts can be activated on rising or falling edges with an optional glitch filter.” However Redpine Signals RS9110-N-11-21 Datasheet states: “Active high, level triggered.” If one tries to use a parameter of InterruptEdgeLevelHigh or InterruptEdgeLevelLow one receives an Argument Exception. SPI needs interrupts. If I use InterruptEdgeBoth, InterruptEdgeHigh or InterruptEdgeLow with many variations of parameters and code I am unable to detect an interrupt.
If RedPine are limited to “level triggered” should I be able to detect their interrupts with Edge triggered using my EMX?
KG1
January 24, 2013, 7:51pm
2
Making progress with version 4.2. The following code runs very well:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using GHI.Premium.Net;
using GHI.Premium.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace WiFiEMX
{
public class Program
{
//static WiFiRS9110 wifiBoard = new WiFiRS9110(SPI.SPI_module.SPI1, EMX.Pin.IO2, EMX.Pin.IO26, EMX.Pin.IO3);
static WiFiRS9110 wifiBoard = new WiFiRS9110(SPI.SPI_module.SPI1, (Cpu.Pin)2, (Cpu.Pin)26, (Cpu.Pin)3);
static byte[] outBuffer = new byte[16];
//static string myIP = "192.168.1.6";
static public string myWiFiNetworkSSID = "KGNETGEAR";
//static ushort myPort = 5051;
//static Socket clientSocket;
public static void Main()
{
wifiBoard.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler
(wifiBoard_WirelessConnectivityChanged);
wifiBoard.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler
(wifiBoard_NetworkAddressChanged);
for (int count1 = 0; count1 < 3; count1++)
{
if (wifiBoard.IsActivated)
{
wifiBoard.Close();
wifiBoard = new WiFiRS9110(SPI.SPI_module.SPI1, (Cpu.Pin)2, (Cpu.Pin)26, (Cpu.Pin)3);
}
// Set the object up
if (!wifiBoard.IsOpen)
wifiBoard.Open();
if (!wifiBoard.NetworkInterface.IsDhcpEnabled)
wifiBoard.NetworkInterface.EnableDhcp();
else
wifiBoard.NetworkInterface.RenewDhcpLease();
// Set this as the current interface
NetworkInterfaceExtension.AssignNetworkingStackTo(wifiBoard);
// Scan for networks
WiFiNetworkInfo[] ScanResp = wifiBoard.Scan();
if (ScanResp != null)
{
Debug.Print("Total Available Networks are " + ScanResp.Length.ToString());
foreach (WiFiNetworkInfo x in ScanResp)
{
Debug.Print(WiFiNetworkInfoToString(x));
Debug.Print("-----------------------------------------------------");
}
}
// Check if myWiFiNetworkSSID one of the found networks.
int i = 0;
for (i = 0; i < ScanResp.Length; i++)
{
if (string.Compare(ScanResp[i].SSID, myWiFiNetworkSSID) == 0)
{
break;
}
}
if (i >= ScanResp.Length)
{
Debug.Print("The netwrok you are looking for is not there");
throw new Exception();
}
else
{
for (int count2 = 0; count2 < 3; count2++)
{
Debug.Print("Connecting to " + ScanResp[i].SSID);
try
{
string passPhrase = Resources.GetString(Resources.StringResources.sPassPhrase);
wifiBoard.Join(ScanResp[i], passPhrase);
}
catch (Exception e)
{
Debug.Print("Error Message: " + e.Message);
throw;
}
Debug.Print("Successfully Joined WiFi Network listed below:");
try
{
if (wifiBoard != null && wifiBoard.IsLinkConnected)
{
Debug.Print("Network settings for: Count1 = " + (count1 + 1).ToString() + " Count2 = " + (count2 +
1).ToString());
Debug.Print("IP Address: " + wifiBoard.NetworkInterface.IPAddress);
Debug.Print("Subnet Mask: " + wifiBoard.NetworkInterface.SubnetMask);
Debug.Print("Default Getway: " + wifiBoard.NetworkInterface.GatewayAddress);
for (int j = 0; j < wifiBoard.NetworkInterface.DnsAddresses.Length; j++)
{
Debug.Print("DNS Server: " + wifiBoard.NetworkInterface.DnsAddresses[j]);
}
}
else
{
Debug.Print("The WiFi link is not connected!");
}
}
catch (SocketException e)
{
Debug.Print("DHCP Failed");
if (e.ErrorCode == 11003)
Debug.Print("Re-Enable the module.");
throw;
}
Debug.Print("Test DNS");
try
{
string hostName = "www.ghielectronics.com";
IPHostEntry myIP = Dns.GetHostEntry(hostName);
if (myIP != null)
{
Debug.Print(hostName + ": " + myIP.AddressList[0].ToString());
}
}
catch (SocketException e)
{
Debug.Print("Failed to Get the host entry of the FQN from DNS server!");
if (e.ErrorCode == 11003)
Debug.Print("Re-Enable the module.");
throw;
}
Debug.Print("Disconnect WiFi link.");
wifiBoard.Disconnect();
Thread.Sleep(1000);
}
Debug.Print("Disable WiFi interface");
wifiBoard.Close();
Thread.Sleep(10000);
}
} //for loop
// Join your network
wifiBoard.Dispose();
}
static void wifiBoard_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
{
if (wifiBoard != null && !wifiBoard.IsActivated && !wifiBoard.IsOpen && !wifiBoard.IsLinkConnected && !e.IsConnected)
{
Debug.Print("WiFi is Disconnected! -> event: Wirless Connectivity Changed.");
}
else
{
Debug.Print("Wireless Connectivity Changed event.");
WiFiNetworkInfo infoNetwork = e.NetworkInformation;
if (infoNetwork != null)
{
string str1 = WiFiNetworkInfoToString(infoNetwork);
Debug.Print(str1);
}
Debug.Print("Is DhCp enabled: " + wifiBoard.NetworkInterface.IsDhcpEnabled);
Debug.Print("Is DynamicDnsEnabled enabled: " + wifiBoard.NetworkInterface.IsDynamicDnsEnabled);
Debug.Print("NetworkInterfaceType " + wifiBoard.NetworkInterface.NetworkInterfaceType);
Debug.Print("Network settings:");
Debug.Print("IP Address: " + wifiBoard.NetworkInterface.IPAddress);
Debug.Print("Subnet Mask: " + wifiBoard.NetworkInterface.SubnetMask);
Debug.Print("Default Getway: " + wifiBoard.NetworkInterface.GatewayAddress);
Debug.Print("Number of DNS servers:" + wifiBoard.NetworkInterface.DnsAddresses.Length);
for (int i = 0; i < wifiBoard.NetworkInterface.DnsAddresses.Length; i++)
Debug.Print("DNS Server " + i.ToString() + ":" + wifiBoard.NetworkInterface.DnsAddresses[i]);
Debug.Print("------------------------------------------------------");
}
}
static void wifiBoard_NetworkAddressChanged(object sender, EventArgs e)
{
if (wifiBoard != null && !wifiBoard.IsLinkConnected)
{
Debug.Print("WiFi is Disconnected! -> event: Network Address Changed.");
}
else
{
Debug.Print("Network Address Changed event.");
Debug.Print("Is DhCp enabled: " + wifiBoard.NetworkInterface.IsDhcpEnabled);
Debug.Print("Is DynamicDnsEnabled enabled: " + wifiBoard.NetworkInterface.IsDynamicDnsEnabled);
Debug.Print("NetworkInterfaceType " + wifiBoard.NetworkInterface.NetworkInterfaceType);
Debug.Print("Network settings:");
Debug.Print("IP Address: " + wifiBoard.NetworkInterface.IPAddress);
Debug.Print("Subnet Mask: " + wifiBoard.NetworkInterface.SubnetMask);
Debug.Print("Default Getway: " + wifiBoard.NetworkInterface.GatewayAddress);
Debug.Print("Number of DNS servers:" + wifiBoard.NetworkInterface.DnsAddresses.Length);
for (int i = 0; i < wifiBoard.NetworkInterface.DnsAddresses.Length; i++)
Debug.Print("DNS Server " + i.ToString() + ":" + wifiBoard.NetworkInterface.DnsAddresses[i]);
Debug.Print("------------------------------------------------------");
}
}
static string WiFiNetworkInfoToString(WiFiNetworkInfo info)
{
string str;
str = "SSID: " + info.SSID + "\n";
str += "Channel Number: " + info.ChannelNumber + "\n";
str += "RSSI: -" + info.RSSI + "dB" + "\n";
str += "Security Mode: ";
switch (info.SecMode)
{
case SecurityMode.Open:
str += "Open";
break;
case SecurityMode.WEP:
str += "WEP";
break;
case SecurityMode.WPA:
str += "WPA";
break;
case SecurityMode.WPA2:
str += "WPA2";
break;
}
str += "\n";
str += "Network Type: ";
switch (info.networkType)
{
case NetworkType.AccessPoint:
str += "Access Point";
break;
case NetworkType.AdHoc:
str += "AdHoc";
break;
}
str += "\n";
str += "BS MAC: " + ByteToHex(info.PhysicalAddress[0]) + "-"
+ ByteToHex(info.PhysicalAddress[1]) + "-"
+ ByteToHex(info.PhysicalAddress[2]) + "-"
+ ByteToHex(info.PhysicalAddress[3]) + "-"
+ ByteToHex(info.PhysicalAddress[4]) + "-"
+ ByteToHex(info.PhysicalAddress[5]) + "\n";
return str;
}
public static string ByteToHex(byte number)
{
string hex = "0123456789ABCDEF";
return new string(new char[] { hex[(number & 0xF0) >> 4], hex[number & 0x0F] });
}
}
}
This code runs very well but may have Network Interface Extension Exceptions which are difficult to catch. This exception seems to
be associated with a time-out relating to “static public ManualResetEvent wait = new ManualResetEvent(false);” which is an event "under
the hood".
Is it possible to reset this time-out and continue execution? Please provide example code. Many thanks.