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