ClearCore Library
ClearCore Ethernet

Overview

ClearCore provides fully-featured Ethernet functionality at 10 Mbps and 100 Mbps with a 10Base-T/100Base-TX Ethernet port. The ClearCore package implements LwIP's TCP/IP protocol suite and
provides a user-friendly API for TCP and UDP capabilities.

Wiring and Initialization

Ethernet TCP

The TCP functionality of the ClearCore provides a Client-Server interface, allowing the ClearCore to act as either a client or a server. TCP is connection-oriented and provides built-in error
checking, guaranteed packet delivery, and delivery of packets in order. TCP is best suited for an application where reliability is more valuable than speed.

TCP Client

From the Client-Server perspective, the client of a TCP connection is the device who initiates the connection.

TCP Server

From the Client-Server perspective, the server of a TCP connection is the device that listens for and accepts incoming connection requests. The EthernetTcpServer interface provides two distinct options for managing connected clients. Choose one or the other, but do not mix usage of EthernetTcpServer::Available() and EthernetTcpServer::Accept().

Automatic Client Management (recommended)

    - To obtain a reference to a connected client while leaving management of that client up to the server, use EthernetTcpServer::Available()
  - Each client reference is an EthernetTcpClient object. 
    - Incoming TCP packets from an individual client are automatically buffered within the client. To process received data, the client's buffer can be read-from directly at any time by

calling EthernetTcpClient::Read().

// Initialize the ClearCore as a server listening for incoming client connections
EthernetTcpServer server = EthernetTcpServer(8888);
// Start listening for TCP connections on port 8888.
server.Begin();
// Obtain a reference to a connected client with incoming data available.
EthernetTcpClient client = server.Available();
if (client.Connected()) {
// The server has returned a connected client with incoming data available.
while (client.BytesAvailable() > 0) {
// Send the data received from the client over a serial port.
ConnectorCOM0.Send(client.Read());
}
}

Manual Client Management

// The server will no longer keep track of connected clients returned by Accept().
EthernetTcpClient clients[4];
clients[0] = server.Accept();
if (clients[0].Connected()) {
// Send a TCP packet to the client with a payload containing the string.
clients[0].Send("Hello World");
}

Ethernet UDP

UDP communications are connectionless and do not provide error checking or guaranteed delivery. The EthernetUdp interface manages a local UDP session and provides methods for sending and receiving
UDP datagrams. UDP is best suited for an application that performs its own error checking and appropriately handles packet loss or an application that requires efficiency and speed.