USB memory
Dependencies: mbed FatFileSystemCpp
Diff: main.cpp
- Revision:
- 4:85a07ebe0933
- Parent:
- 0:e294af8d0e07
diff -r 95e55809ecdb -r 85a07ebe0933 main.cpp --- a/main.cpp Mon Jul 30 13:49:56 2012 +0000 +++ b/main.cpp Wed Mar 11 11:43:26 2020 +0000 @@ -1,69 +1,25 @@ #include "mbed.h" #include "MSCFileSystem.h" -//#include <stat.h> - -#define FSNAME "msc" -MSCFileSystem msc(FSNAME); - + +MSCFileSystem msc("usb"); // Mount flash drive under the name "msc" +Serial pc(USBTX, USBRX); + +//Timer timer; //書き込み時間を計測するタイマ int main() { - DIR *d; - struct dirent *p; - //struct stat st; - //char path[PATH_MAX]; - - printf("\n\n================================\n"); - printf("USB Mass storage demo program for mbed LPC1768\n"); - printf("================================\n\n"); - - d = opendir("/" FSNAME); - - printf("\nList of files on the flash drive:\n"); - if ( d != NULL ) - { - while ( (p = readdir(d)) != NULL ) - { - printf(" - %s\n", p->d_name); - /* no <stat.h> on mbed, it seems :/ - sprintf(path, "/"FSNAME"/%s", p->d_name); - if ( stat(path, &st) == 0 ) - { - if ( S_ISDIR(st.st_mode) ) - printf(" <directory>\n"); - else - printf(" %d\n", st.st_size); - } - else - { - printf(" ???\n"); - }*/ - } - } - else - { - error("Could not open directory!"); - } - printf("\nTesting file write:\n"); - FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); +// pc.printf("USB file open!\r\n"); + FILE *fp = fopen( "/usb/test.csv", "w"); //ファイルを開く "W"は新規作成して書き込みっていう命令? + pc.printf("USB fileopen0!\r\n"); if ( fp == NULL ) { - error("Could not open file for write\n"); + pc.printf("USB fileopen!\r\n"); + exit(1); } - fprintf(fp, "Hello mass storage!"); - fclose(fp); - printf("\n - OK\n"); - - printf("\nTesting file read:\n"); - fp = fopen( "/" FSNAME "/msctest.txt", "r"); - if ( fp == NULL ) - { - error("Could not open file for read\n"); - } - char buf[256]; - if ( NULL == fgets(buf, sizeof(buf), fp) ) - { - error("Error reading from file\n"); - } - fclose(fp); - printf("\n - OK, read string: '%s'\n\n", buf); + pc.printf("USB file write!\r\n"); +// timer.start(); //書き込み時間測定開始 + fprintf(fp,"Hello world! oookkk\n"); //ファイル書き込み +// timer.stop(); //書き込み時間測定終了 + fclose(fp); //ファイルを閉じる + pc.printf("USB file close!\n"); +// pc.printf("write time :%f\n\n\n",timer.read()); }