Sending an Image out Serial

24 Sep 2012

I am fairly new to this so bare with me..

Ok, so I want to be able to have my MBED LPC1768 read Images that are stored on the flash drive and write them out Serial. I have been reading up on the File system and I believe that is how I should go about implementing this?

I will then use a statement to write out the serial port?

Thanks for the help!

John

25 Sep 2012

Hi John,

Well it depends on the receiving part in what format you have to send the images: plain binary or some other format (do you need to decode the images first ?). But basically it is just opening the file on the flashdrive for reading with fopen(), open the serial port for writing and then read a byte from the file and output it to the serial port..

25 Sep 2012

Or buffer it into a char array with an fread: many file systems perform better with freads. http://www.cplusplus.com/reference/clibrary/cstdio/fread/ is a good place to start, as well as the printf and fopen/fclose stuff on that site.

25 Sep 2012

Gert van der Knokke wrote:

Hi John,

Well it depends on the receiving part in what format you have to send the images: plain binary or some other format (do you need to decode the images first ?). But basically it is just opening the file on the flashdrive for reading with fopen(), open the serial port for writing and then read a byte from the file and output it to the serial port..

No decoding needed, I just am reading the Image and then Writing through a loop. I have been working with the File System code example and also the serial example, but I am confused on how to implement them together.

20 Nov 2012

i want ro read images from Pc. please tell me how to do it? i want to read the images through mbed . the images will be on a specified path in the pc.

20 Nov 2012

sanwal muneer wrote:

i want ro read images from Pc. please tell me how to do it? i want to read the images through mbed . the images will be on a specified path in the pc.

You need to compile something like a 'samba' client for the mbed but since there is no memory to store an image this is not feasible.

20 Nov 2012

my image woulb be of very low resolution and size would be around 18kb. would it still not possible?

20 Nov 2012

cant i read images through local file system?

27 Nov 2012

Hi,

You just want to dump a file to serial right?

How about this:

#include "mbed.h"
 
LocalFileSystem local("local");
Serial pc(USBTX, USBRX);

void loopForever() {
   DigitalOut led(LED1);
   while(1) {
      led = !led;
      wait(1.0);
   }
}
 
int main() {
    // start serial comms
    pc.baud(115200);
    pc.printf("HELLO\r\n");
    
    // buffer for file
    char buf[1024];
    
    // open file
    FILE *f = NULL;
    f = fopen("/local/hello.txt", "r");
    
    // make some noise if this goes wrong
    if(f==NULL) {
       pc.printf("Problem opening file for reading\r\n");
       loopForever();
    }
    // read the file and dump it as hex
    size_t br;
    while((br=fread(buf,1,1024,f))!=0) {
       pc.printf("Read %d bytes\r\n",br);
       for(size_t i=0; i<br; i++) {
          pc.printf("%x",buf[i]);
       }
    }
    // determine whether we reached EOF or not
    if(!feof(f)&&ferror(f)) {
       pc.printf("Did not complete reading file, file error\r\n");
    } else {
       pc.printf("File read successfully\r\n");
    }

    // close the file    
    fclose(f);
}

Works for me. I dumped as hex. You probably want to dump directly to some external handle to the serial stream I suppose?

http://mbed.org/handbook/LocalFileSystem

Ashley