Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Ethernet <-> UART bug?


  • Please log in to reply
3 replies to this topic

#1 Casper

Casper

    New Member

  • Members
  • Pip
  • 6 posts

Posted 28 May 2011 - 09:43 AM

I'm running up against an issue with ethernet and UART. To test a shield I use the code below to passthrough all data from ethernet to UART and vice versa. No problem when the shield sends just a bit, but when there's a lot of data sent by UART Socket.Send throws constantly exceptions.

I've found a way to reproduce the problem without a shield. Just connect PIND0 with PIND1 (RX and TX) with a wire and use terminal software (Tera Term, Telnet, Putty) to connect to Netduino. When you send some keystrokes it should be echoed. But when you send large bunches of data in a small amount of time, the problem occurs. On higher baud rates the problem occurs even more often.

With some trial and error, I've found a temporary solution with Thread.Sleep(). When you uncomment those in the code below the problems occurs less often, but it makes data transmission much slower. Any ideas for a better solution?

Casper.

public static void Main()
{
    for (; ; )
    {
        try
        {
            LusDoor();
        }
        catch (Exception ex)
        {
            Debug.Print(ex.Message);
        }
    }
}

public static void LusDoor()
{
    Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    s.Bind(new IPEndPoint(IPAddress.Any, 22));
    s.Listen(1);

    Socket clientSocket = s.Accept();

    SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
    serialPort.Open();

    byte[] buffer;

    for (; ; )
    {
        if (serialPort.BytesToRead > 0)
        {
            buffer = new byte[serialPort.BytesToRead];
            serialPort.Read(buffer, 0, buffer.Length);
            clientSocket.Send(buffer,0, buffer.Length, SocketFlags.None);
            //Thread.Sleep(100);
        }

        if (clientSocket.Available > 0)
        {
            buffer = new byte[clientSocket.Available];
            clientSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
            serialPort.Write(buffer, 0, buffer.Length);
            //Thread.Sleep(100);
        }
    }
}

    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
    #### System.Net.Sockets.Socket::Send [IP: 0018] ####
    #### DoorlusEthernetUART.Program::LusDoor [IP: 0064] ####
    #### DoorlusEthernetUART.Program::Main [IP: 0008] ####
    #### SocketException ErrorCode = 10055


#2 pcamargo

pcamargo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 22 April 2013 - 10:25 PM

We are also experiencing uart/ethernet problems. We have an application that downloads frames from a ttl camera and it works fine if the ethernet port is not connected. As soon as a ethernet cable is connected the application starts failing becasue the data is received incomplete in the uarts.

 

At this point we are not even using any ethetnet library. 

 

We need to transfer the frames to a tcp client but until the uart / ethernet bug is fixed we cannot continue.

 

Please HELP!!!!



#3 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 23 April 2013 - 09:24 PM

pcamargo:

 

I refer to this post, where 'mbinelo' had a similar problem and resolved his, he believed, with some threading legerdemain:

http://forums.netdui...roblem/?p=46750

 

I can attest that I am successfully using 3 uarts, and Ethernet, on the NP2, so its at least doable in some particular configuration.



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 23 April 2013 - 09:32 PM

the bug/problem is totally in your code.

 

you only accept the socket once and never close it.

 

also, uart is a streaming protocol, so its not sure all the data arrived allready when you send it.

 

if (serialPort.BytesToRead > 0)  will happen even after 1 byte is arrived,

but that doesent say how many is left.

also, serial is quite slow (at 115200), 9600 is very slow -

you cant send a lot of data this way.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.