40#define MAX_PACKET_LENGTH 100
42unsigned char packetReceived[MAX_PACKET_LENGTH];
49 ConnectorUsb.
Mode(Connector::USB_CDC);
50 ConnectorUsb.
Speed(9600);
52 uint32_t timeout = 5000;
54 while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
61 ConnectorIO0.
Mode(Connector::OUTPUT_DIGITAL);
65 ConnectorUsb.
SendLine(
"The Ethernet cable is unplugged...");
74 bool dhcpSuccess = EthernetMgr.
DhcpBegin();
76 ConnectorUsb.
Send(
"DHCP successfully assigned an IP address: ");
80 ConnectorUsb.
SendLine(
"DHCP configuration was unsuccessful!");
90 IpAddress ip = IpAddress(192, 168, 0, 109);
92 ConnectorUsb.
Send(
"Assigned manual IP address: ");
106 EthernetTcpServer server = EthernetTcpServer(PORT_NUM);
111 EthernetTcpClient client;
116 ConnectorUsb.
SendLine(
"Server now listening for client connections...");
123 client = server.Available();
126 if (client.Connected() || client.BytesAvailable() > 0) {
128 ConnectorIO0.
State(
true);
135 ConnectorUsb.
Send(
"Read the following from the client: ");
136 while (client.BytesAvailable() > 0) {
138 client.Read(packetReceived, MAX_PACKET_LENGTH);
139 ConnectorUsb.
Send((
char *)packetReceived);
142 for(
int i=0; i<MAX_PACKET_LENGTH; i++){
143 packetReceived[i]= NULL;
149 if (client.Send(
"Hello client ")>0){
150 ConnectorUsb.
SendLine(
"Sent 'Hello Client' response");
153 ConnectorUsb.
SendLine(
"Unable to send reply");
157 ConnectorIO0.
State(
false);
158 if(client.ConnectionState()->state == CLOSING){
164 ConnectorUsb.
SendLine(
"The Ethernet cable is unplugged...");
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
int16_t State() override
Get connector's last sampled digital value.
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutAnalogOut.h:70
volatile const bool & PhyLinkActive()
Check the link status from the PHY.
Definition EthernetManager.h:136
IpAddress LocalIp()
Get the local IP address.
void Refresh()
Perform any necessary periodic Ethernet and LwIP updates.
bool DhcpBegin()
Set up DHCP connection to retrieve local IP.
void Setup()
Setup LwIP with the local network interface.
bool SendLine()
Send carriage return and newline characters.
Definition ISerial.h:162
virtual bool Speed(uint32_t bitsPerSecond)=0
Change the baud rate for the port.
bool Send(const char *buffer, size_t bufferSize)
Send the array of characters out the port.
Definition ISerial.h:173
char * StringValue()
Returns a string representation of the IP Address.
Definition IpAddress.h:96
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition SerialUsb.h:210