SdFat Stream To Client Rather Than Serial

I have been trying to redirect the output of SdFat calls to an object other than "Serial" for quite some time to no avail. I have read through all the streaming library that comes with SdFat and tried changing all the parts which have the (&Serial) to (&client) and this doesn't work, I have read a lot and tried a lot of other stuff and I am now really stumped as to how I can solve this.

Mark.

I have read a lot and tried a lot of other stuff and I am now really stumped as to how I can solve this.

What does the code you now have look like? What does the code actually do, now?

Hi, with the below code I have tried to use the out stream to send the output of the function call "sd.ls(LS_SIZE | LS_DATE)" to a connected client. I can't see what I'm doing wrong here.

#include <SPI.h>
#include <Ethernet.h>
#include <SdFat.h>
#include <SdFile.h>

#define SS 53
#define SD_CS 4
#define W5100_CS 10
uint16_t l = 0;
char serInString[250];
uint16_t  serInIndx  = 0;
uint16_t  serOutIndx = 0;
byte mac[]     = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[]      = {192, 168, 3, 8 };
byte gateway[] = {192, 168, 3, 3 };
SdFat    sd;
SdFile   file;
EthernetServer server = EthernetServer(23);
EthernetClient client = 0;

ArduinoOutStream cout(client);

void setup()
{
  pinMode(SS, OUTPUT);
  pinMode(W5100_CS, OUTPUT);
  digitalWrite(W5100_CS, HIGH);
  digitalWrite(SD_CS, LOW);
  Serial.begin(57600);
  Ethernet.begin(mac, ip, gateway, 23);
  server.begin();
  if(!sd.init(SPI_FULL_SPEED, SD_CS))
  {
    Serial.print("SD Card Initialization Failed");
    Serial.println();
  }
}

void printSerialString() {
  if(serInIndx>0)
  {
    for(serOutIndx=0;serOutIndx<serInIndx;serOutIndx++)
    {
      Serial.print(serInString[serOutIndx]);
    }
    serOutIndx = 0;
  }
}

void readSerialString ()
{
  int sb;
  if(Serial.available()) {
    sb = Serial.read();
    if(sb == '@')
    {
      while(Serial.available())
      {
        sb = Serial.read();
        serInString[serInIndx] = sb;
        serInIndx++;
      }
      printSerialString();
    }
  }
}

bool parseCmd()
{
  if(serInString[0] == 'l' && serInString[1] == 's')
  {
  if(!sd.init(SPI_FULL_SPEED, SD_CS))
  {
    Serial.print("SD Card Initialization Failed");
    Serial.println();
  }
  sd.ls(LS_SIZE | LS_DATE);
  for(l=0;l<serInIndx;l++)
  {
    serInString[l] = NULL;
  }
  serInIndx = 0;
  return(true);
  }
  else return(false);
}

void loop()
{
  readSerialString();
  if(serInIndx>0)
  {
    parseCmd();
  }
  delay(1000);
}

Mark.

We'd need to see what changes you made to the library files, too.

Hi, with the below code I have tried to use the out stream to send the output of the function call "sd.ls(LS_SIZE | LS_DATE)" to a connected client. I can't see what I'm doing wrong here.

We can't see where the output is (still) going, either.