Netduino home hardware projects downloads community

Jump to content


Photo

Sample (or Pointer/URL) needed to read file from SD Card (VB.NET & Netduino) - Many Thanks In Advance


  • Please log in to reply
2 replies to this topic

#1 datamig

datamig

    New Member

  • Members
  • Pip
  • 2 posts
  • LocationUKand SPAIN

Posted 23 May 2014 - 11:26 PM

Hi All,

 

My first post

 

I simply need a VB.NET sample to read and write to the SDCard of the Netduino 2 Plus

 

I did google but not as easy as Iwas expecting

 

So asking here . . .

 

(Many Thanks In Advance for replies / pointers)

 

Regards

DataMig


(Many Thanks In Advance)

 

Regards

DataMig

 


#2 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 26 May 2014 - 08:58 PM

Here is a class for SD file operations written in VB. It is not production quality code by any means and there may be bugs (probably) and needs more error checking, but it should get you started. The last time I used this code was over two years ago. It was a first cut and needs more work. It runs on a Netduino Plus or Plus 2 running firmware 4.2.1

https://www.dropbox....eOperations.zip

 

The code maintains a list of folders/files on the SD card with provision to create and delete folders and read/write/delete files.

 

Usage:

Using SD As SDcard = New SDcard()

Debug.Print(SD.volumeInfo)
Debug.Print(SD.files) 

Dim flag as Boolean = SD.createDir("\SD\ABC")
If(flag) Then
     Debug.Print( "Directory created successfully") 
 Else
     Debug.Print( "That directory already exists")
 End If
'
'Etc
'
End Using 'SD card

Always use the full path as a string like this for addressing a file or folder,

"\SD\ABC" --> access or create folder ABC under the root, \SD\
and,
"\SD\ABC\x" --> access or create a sub-folder x under ABC

 

To save text to a text file named, "My_textfile" in folder, x with content, "some content", using the saveTextFile method, 

call: saveTextFile("some content","\SD\ABC\x\My_textfile").

 

There is an optional argument to saveTextFile, true or false. The default is false which overwrites an existing file. True appends to an existing file. Most of the file operations with the SD card are pretty much like regular Vb.NET.



#3 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 27 May 2014 - 01:54 PM

In shorthand....
'Writing
If Directory.Exists("\sd\") Then

Using sw As StreamWriter = New StreamWriter("\sd\ThisFile.txt", False)

sw.Write("this is a string")
sw.Flush()
End Using
EndIf

'reading
If Directory.Exists("\sd\") AndAlso File.Exists("\sd\ThisFile.txt") Then

Using sr As StreamReader = New StreamReader("\sd\ThisFile.txt")
tmpStr = sr.ReadToEnd
End Using

End If

debug.print(tmpStr)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.