Main Site Documentation

Ethernet Shield sample


#1

Hi,

when will we see an ethernet sample based on the wiznet shield you are selling for the domino?

A simple server application and client application would be enough in the first step.

thx

Holger


#2

We have simple implementation done but what we actually want it to try integrate the standard NETMF socket support into FEZ. If could do that then you can almost use any .NET C# example and it will work. I am guessing we will not have anything available for few weeks.



If you want to use it now (can’t wait) then you can use the beta driver and the W5100 datasheet to get started but I do not recommend that since we will have a much better support in near future.


#3

thx for the answer. I will try using the beta lib for now but we’re looking forward for all the nice features in the future: CAN, NETMF sockets…



Are there any plans on supporting LCD TFT directly on the domino by a shield in the future for direct WPF NETMF programming?



Sincerely

Holger


#4

We have many plans! Stay tuned and they will come in time


#5

Here’s some sample code to begin using the Ethernet shield based on the beta driver provided by TinyCLR:

A client connecting to port 21 and sending a request:

using System;
using Microsoft.SPOT;
using System.Text;
using System.Threading;

using GHIElectronics.NETMF.FEZ;

namespace ethernettest
{
    public class Program
    {
        public static string bytesToString(byte[] bytes)
        {
            string s = "";
            for (int i = 0; i < bytes.Length; ++i)
                s+= (char)bytes[i];
            return s;
        }

        public static void Main()
        {
            byte[] ip = { 192,168,0,2 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192.168.0.1 };
            byte[] mac = { 43, 185, 44, 2, 206, 127 };

            FEZ_Shields.Ethernet.Initialize(ip, subnet, gateway, mac);
            FEZ_Shields.Ethernet.uSocket socket = new FEZ_Shields.Ethernet.uSocket(FEZ_Shields.Ethernet.uSocket.Protocol.TCP, 21);
                       socket.Connect(remoteServer, 21);

            string request = "stringtosend";

            int bytes = socket.AvilableBytes;
            socket.Send(GetBytes(request), request.Length);

            Thread.Sleep(1000);
            bytes = socket.AvilableBytes;
        }

    }
}

I recommend testing the code using the netcat tool (http://netcat.sourceforge.net/) which is also available for Windows (http://joncraton.org/files/nc111nt.zip).

This should work as a start until we get a sample by GHI or an implementation of real .NET MF sockets.

have fun
Holger


#6

A server listening on port 21 with output of all incoming requests:

using System;
using Microsoft.SPOT;
using System.Text;
using System.Threading;

using GHIElectronics.NETMF.FEZ;

namespace ethernettest
{
    public class Program
    {
      
        public static void Main()
        {
            byte[] ip = { 192,168,0,2 };
byte[] subnet = { 255, 255, 255, 0 };
byte[] gateway = { 192.168.0.1 };
byte[] mac = { 43, 185, 44, 2, 206, 127 };


            FEZ_Shields.Ethernet.Initialize(ip, subnet, gateway, mac);
            FEZ_Shields.Ethernet.uSocket socket = new FEZ_Shields.Ethernet.uSocket(FEZ_Shields.Ethernet.uSocket.Protocol.TCP, 21);
            while (!socket.Listen()) ;
            
            do
            {
                if (socket.AvilableBytes > 0)
                {
                    byte[] recv = new byte[socket.AvilableBytes];
                    int rec = socket.Receive(recv, recv.Length);
                    if (rec > 0)
                        Debug.Print(bytesToString(recv));
                }
                Thread.Sleep(10);
            }
            while (true);
        }

    }
}

use bytestoString function from above!
Holger


#7

I see you were able to figure it out on your own. Good job


#8

Hi!

I tried to implement the example described, but on the method “socket.Connect” stands stuck forever.
What may be going wrong?


#9

The driver we provide is beta and has many issues that need fixing. You will need to wait till we move the support so it is built into FEZ (will be few week till we get to it) or you need to debug the code and use the Wiznet user manual…this requires a lot of experience.

See my first response to this thread


#10

Im having the exact same thing… It seems that in the Connect method at

while (W5100.RegisterRead(s, W5100.SocketRegisters.SR) != (byte)SR_val.SOCK_ESTABLISHED) ;

Its never getting a “SOCK_ESTABLISHED” byte…


#11

My student (EDUARDO GADOTTI) said that implemented timeout in the ETHERNET SHIELD…
Here the source code.
(link removed)
Miguel