simple serial reading ascii with ethernet but still wrong reading

Hello,
I am trying to run a web server onto an arduinoUno that when polled performs simple ascii STRING reading from a serial device.
It is basically the ethernet webserver example with some minor changes.
Here Is the code I wrote

#include <Ethernet.h>
#include <SPI.h>//needed for ethernet shield
char incomingByte=-1; // for incoming serial data
char data[30];
int ledr=0;
boolean led=true;
//setup ethernet
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

// (port 80 is default for HTTP):
EthernetServer server(80);

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

void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
Serial.print("s");//put here command to send to the device
int i=0;
while (Serial.available() > 0) {
if(i<30){
data*=(char)Serial.read();*

  • i++;*
    _ data*='\0';_
    _
    }_
    _
    }_
    _
    // send a standard http response header*_
    * client.println("HTTP/1.1 200 OK");*
    * client.println("Content-Type: text/html");*
    * client.println("Connnection: close");*
    * client.println();*
    * client.println("");*
    * client.println("");*
    * // add a meta refresh tag, so the browser pulls again every 5 seconds:*
    * client.println("<meta http-equiv="refresh" content="5">");*
    * client.println("data_Received");
    _
    client.println(data);_
    _
    client.println("_
    _
    ");_
    _
    //end if \n e current line blank. _
    _
    client.println("");_
    _
    ledr=~ledr;_
    _
    break; _
    _
    }_
    _
    if (c == '\n') {_
    _
    // you're starting a new line*_
    * currentLineIsBlank = true;*
    * }*
    * else if (c != '\r') {*
    * / you've gotten a character on the current line*
    * currentLineIsBlank = false;*
    * }*
    * }*
    * }*
    * // give the web browser time to receive the data*
    * delay(1);*
    * // close the connection:*
    * client.stop();*
    * Serial.println("client disonnected");*
    * }*
    }
    [/quote]
    Now, the respone I Should have is exactly the string ""done \n", and with pc-serial port it works fine.
    Anyway, the running web server response is "ÿßßþÿÙÖü", that's quite different from what was expecting.
    I suppose there should be logical errors in my routine, but I can't figure out where.
    Any hint would be appreciated.
     Serial.print("s");//put here command to send to the device
          int i=0;
          while (Serial.available() > 0) {
          if(i<30){
                  data=(char)Serial.read();
                  i++;
                  data='\0';
              }
          }

Do something, and report back within the next 62.5 nanoseconds. Does that seem like a reasonable duration to wait for the response?

Without the ethernet shield/code in the way, do you get valid data from the device?

How are you managing to talk to the device AND the serial port at the same time?

Finally, what kind of device is it? The data you are seeing looks like the device is NOT a TTL device.

I tohugth that the serial.write() would write to the device and then release the serial port.
In the same way, I used to think that Serial.available() is function that continuosly performs a polling on the rx channel only if there is any valid data.
I was thinking of perform a check for the serial port, a change in the statement like this.

while (Serial.available() < 1);
while (Serial.available() > 0) {
if(i<30){
data=(char)Serial.read();
i++;
data='\0';
}
[\quote]

Anyway, I didn't try to perform a simple read without the shield code. But how can I see the read result, if my serial is wired to the other device?

I'll try right now.

EDIT:
I didn't notice the other question.
The device is TI launchpad - with a 2553 onboard.

I tohugth that the serial.write() would write to the device and then release the serial port.

No. The port is activated when you use Serial.begin().

In the same way, I used to think that Serial.available() is function that continuosly performs a polling on the rx channel only if there is any valid data.

No. The Serial instance is handling the arrival of data, but the available() method only checks, when you call it, whether there is buffered data to be read. It does not do any kind of waiting for a reply.

Waiting for one byte to be available would help, if the reply was one byte.

You really need a different approach. The serial communication needs to be considered asynchronous, like posting a question on this forum. You don't know how long it will take to get a response. So, the Arduino should periodically ask the device for data, and return the most recent reply it got when the client asks for it.