2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Can you give a bit more information about what Arduino shields you're using and what you're trying to achieve? \$\endgroup\$ – Toby Jaffey Aug 15 '10 at 12:41
  • \$\begingroup\$ How do conditions differ when it works, and what does it do? \$\endgroup\$ – Clinton Blackmore Aug 15 '10 at 16:16
  • \$\begingroup\$ @Joby @Clint sorry for delay. ethernet is Wiznet module. condition where it fails is such: connection is established (serial port is closed on PC), serial port is opened on PC and written to. however, telnet connection does not receive written bytes. other combinations, first serial connection, then telnet connection work \$\endgroup\$ – aaa Aug 17 '10 at 21:16
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

I haven't really used processing but I have used C and I don't understand how you're getting away with having thatchar byte = Serial.read(); in the middle of the function. All variables should be defined at the start of the function and then used.

\$\endgroup\$
  • 3
    \$\begingroup\$ The Arduino language is C++ with automated headers and footers. In C++ (and C99) declaring variables mid code block is valid. \$\endgroup\$ – Toby Jaffey Aug 16 '10 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.