• AVR Freaks

AnsweredHot!How to read the contents of an sd card with harmony v2?

Author
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
2019/07/20 13:08:26 (permalink)
0

How to read the contents of an sd card with harmony v2?

I've been running the code in the example sdcard_fat_single_disk, local in the folder "C:\microchip\harmony\v2_06\apps\fs"
So after the mounting is successful, i implement the following code that we can see on the SYS_FS_DirRead definition from sys_fs.h:
 

 
 
 
SYS_FS_HANDLE dirHandle;
SYS_FS_FSTAT stat;
char longFileName[300];
uintptr_t longFileSize;
 
 
 
dirHandle = SYS_FS_DirOpen("/mnt/myDrive/Dir1");
 
 
 
if(dirHandle != SYS_FS_HANDLE_INVALID)
{
// Directory open is successful
}
 
 
 
// If long file name is used, the following elements of the "stat"
// structure needs to be initialized with address of proper buffer.
stat.lfname = longFileName;
stat.lfsize = 300;
 
 
 
if(SYS_FS_DirRead(dirHandle, &stat) == SYS_FS_RES_FAILURE)
{
// Directory read failed.
}
else
{
// Directory read succeeded.
if ((stat.lfname[0] == '\0') && (stat.fname[0] == '\0'))
{
// reached the end of the directory.
}
else
{
// continue reading the directory.
 
 
 
//TODO: I want to read the files here
 
 
 
printf("file: %s", stat.lfname) //It says "FILE SYSTEM INFORMATION" (or something similar)
}
 
 
 
}
 
 
 

 
I have a file and directory inside, still it doesn't say the name of it.
What is wrong on the code?
 
using:
-PIC32MX470F512L
post edited by Nmaster88 - 2019/07/22 08:49:13
#1
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/20 16:25:53 (permalink)
0
Did you check Harmony help file?

You want to read file name or
contents of the file?
#2
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/20 17:34:00 (permalink)
0
I want the name of the file. I will do a counting of how many files I have inside the root of SD card
#3
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/20 23:20:25 (permalink) ☼ Best Answerby Nmaster88 2019/07/23 08:44:42
0
Hi,


Please Check below link:

https://www.microchip.com...aspx?m=1093276&p=1


and print file name in directly
without %d.


You should find the solution..n update here.


--TS9
post edited by TS9 - 2019/07/20 23:24:03
#4
ric
Super Member
  • Total Posts : 23859
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to read the contents of an sd card with harmony v2? 2019/07/21 02:46:35 (permalink)
0
As TS9 mentioned, this
//TODO: I want to read the files here
printf("file: %d", stat.lfname) //It says "FILE SYSTEM INFORMATION" (or something similar)

should be
//TODO: I want to read the files here
printf("file: %s", stat.lfname);






I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/22 03:33:12 (permalink)
0
ric
As TS9 mentioned, this
//TODO: I want to read the files here
printf("file: %d", stat.lfname) //It says "FILE SYSTEM INFORMATION" (or something similar)

should be
//TODO: I want to read the files here
printf("file: %s", stat.lfname);







Yes, that was because of a bad copy paste. Still the information i got is: 
"System Volume Information"
 
I think the problem is related to
dirHandle = SYS_FS_DirOpen("/mnt/myDrive/");
even if i put
dirHandle = SYS_FS_DirOpen("/");
it doesn't seem to go to the root directory.
 
I have there 2 .txt files.
 
Why?
post edited by Nmaster88 - 2019/07/22 03:43:53
#6
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/22 06:23:20 (permalink)
0
Did you check that link?
That I have shared with you.
#7
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 02:42:18 (permalink)
0
TS9
Did you check that link?
That I have shared with you.

Thanks a lot for the provided code. Still using it what i get printed is:
 
File Name = 0 SYSTEM~1
 
But i have inside 2 .txt files.
#8
ric
Super Member
  • Total Posts : 23859
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 02:54:58 (permalink)
0
That might be a volume label. Have you tried keeping on calling it?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#9
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 03:55:55 (permalink)
0
ric
That might be a volume label. Have you tried keeping on calling it?
 


This is for 
dirHandle = SYS_FS_DirOpen("/mnt/myDrive/");
the root directory.
 
Yes i've run 2 or 3 times, the result was always the same.
#10
ric
Super Member
  • Total Posts : 23859
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 04:00:44 (permalink) ☄ Helpfulby Nmaster88 2019/07/23 08:44:33
5 (1)
After calling SYS_FS_DirOpen, you have to loop around calling SYS_FS_DirRead() over and over to fetch each name.
Are you doing that?

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#11
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 04:36:25 (permalink)
0
Delete / after myDrive then try again.
#12
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 04:48:40 (permalink)
4 (1)
ric
After calling SYS_FS_DirOpen, you have to loop around calling SYS_FS_DirRead() over and over to fetch each name.
Are you doing that?


God, i've missed the while part. It works perfectly now! Thanks!
 
Output:
[00]trying to open directory
directory open successful
File Name = 0 System Volume Information
File Name = 1 test_file.txt
File Name = 2 test3.txt
file end
 
#13
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 08:30:33 (permalink)
0
Nmaster88
ricAfter calling SYS_FS_DirOpen, you have to loop around calling SYS_FS_DirRead() over and over to fetch each name.Are you doing that?

God, i've missed the while part. It works perfectly now! Thanks! Output:[00]trying to open directory
directory open successful
File Name = 0 System Volume InformationFile Name = 1 test_file.txtFile Name = 2 test3.txtfile end 


Good .. But
I think you don't see link carefully...
#14
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 08:51:33 (permalink)
0
TS9
Nmaster88
ricAfter calling SYS_FS_DirOpen, you have to loop around calling SYS_FS_DirRead() over and over to fetch each name.Are you doing that?

God, i've missed the while part. It works perfectly now! Thanks! Output:[00]trying to open directory
directory open successful
File Name = 0 System Volume InformationFile Name = 1 test_file.txtFile Name = 2 test3.txtfile end 


Good .. But
I think you don't see link carefully...

Yes, i was using 
SYS_FS_DirRead()
and like we have on the link you provided we need to use:
if(SYS_FS_DirSearch(dirHandle, "*.txt", SYS_FS_ATTR_ARC, &stat) == SYS_FS_RES_FAILURE)

This way the search on the dir gets filtered, and i only get what i want. Thanks!
 
But it doesn't get here 
if ((stat.lfname[0] == '\0') && (stat.fname[0] == '\0'))
{
// reached the end of the directory.
printf("file end %s \n",stat.lfname);
ReachEndOfCount = 1 ; // Break While
// reached the end of the directory.
break;
}

 
[00]trying to open directory
directory open successful
File Name = 0 test_file.txt
File Name = 1 test3.txt
 
I should get a file end too.
 
 
post edited by Nmaster88 - 2019/07/23 09:35:59
#15
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 10:18:51 (permalink)
0
Hi,

Please refer the code which is given in Msg#4 in above link.


The code will work in such a way that you can read both short file names and long file names above 8 characters.

--
TS9
#16
Nmaster88
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: offline
Re: How to read the contents of an sd card with harmony v2? 2019/07/23 13:40:10 (permalink)
0
TS9
Hi,

Please refer the code which is given in Msg#4 in above link.


The code will work in such a way that you can read both short file names and long file names above 8 characters.

--
TS9

Yes, what i mean is that it isn't entering on that if condition, i need it, because its that that we break out of the while and set the 
ReachEndOfCount = 1
#17
Jump to:
© 2019 APG vNext Commercial Version 4.5