Electronic – arduino serial library

arduino

I have very simple loop to read serial port and write to client

// telnet defaults to port 23
Server server(23);

void setup() {
    Serial.begin(9600);// opens serial port, sets data rate to 9600 bps

    // initialize the ethernet device
    Ethernet.begin(mac, ip, gateway, subnet);

    // start listening for clients
    server.begin();
}

void loop() {
    if (Serial.available() > 0) {
        char byte = Serial.read();
        server.write(byte);
    }
}

problem happens if serial port is open (on computer side) after ethernet connection is established, no data is transmitted

What gives?
thank you

Best Answer

Maybe this is simplistic, but if you open the serial port on the computer, doesn't that make Serial.available() == 0?

You could light the LED on the board if that's true. Hope this helps.