after almost 2 weeks waiting my netduino+ had arrived.
After the led examples I wanted to implement a Wake on LAN (WOL) so I could remotely boot my PC at home.
after connecting the n+ to the network, enabled DHCP (got an ip). I tried to execute to the following method:
public static void WakeUp(byte[] mac) { using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { // IP 255.255.255.255 //IPEndPoint endPoint = new IPEndPoint(new IPAddress(4294967295), 40000); IPEndPoint endPoint = new IPEndPoint(new IPAddress(0xffffffffL), 40000); socket.Connect(endPoint); byte[] packet = new byte[17 * 6]; for (int i = 0; i < 6; i++) packet[i] = 0xFF; for (int i = 1; i <= 16; i++) { for (int j = 0; j < 6; j++) { packet[i * 6 + j] = mac[j]; } } var r = socket.Send(packet, packet.Length,System.Net.Sockets.SocketFlags.Broadcast); } }
I'm converting my MAC-address from string to byte[] via the ToBytes() method in the following class :
public class MacAddress { private readonly string _address; private readonly string[] _macDigits; public MacAddress(string address) { _address = address; if (_address.IndexOf("-") > -1) { _macDigits = _address.Split('-'); } else { _macDigits = _address.Split(':'); } if (_macDigits.Length != 6) { throw new ArgumentException("Incorrect MAC address supplied!"); } } public override string ToString() { return _address; } public byte[] ToBytes() { var datagram = new byte[96]; for (int i = 0; i <= 5; i++) { datagram[i] = 0xff; } int start = 0; for (int i = 0; i < 16; i++) { for (int x = 0; x < 6; x++) { datagram[start + i * 6 + x] = (byte)Convert.ToInt32(_macDigits[x], 16); } } int k = Encoding.UTF8.GetBytes(_address).Length; return datagram; } }
for some reason it doesn't work. The error happends at the following line:
var r = socket.Send(packet, packet.Length,System.Net.Sockets.SocketFlags.Broadcast);
Error produced:
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (3) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.Socket::Send [IP: 0008] ####
#### WOLService.WakeOnLan::WakeUp [IP: 0087] ####
#### WOLService.WakeOnLan::WakeUp [IP: 000d] ####
#### WOLService.Program::button_OnInterrupt [IP: 0014] ####
#### SocketException ErrorCode = 10022
#### SocketException ErrorCode = 10022
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10022
#### SocketException ErrorCode = 10022
I have no idea what is going wrong and can't find any info about error 'CLR_E_FAIL (3)' or error code 'ErrorCode = 10022'
Could somebody tell me what's wrong with my code or tell me where I can find more info about these error codes..
tnx!
michel