Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Sd Card read issues

SD Card

  • Please log in to reply
3 replies to this topic

#1 claudio.serio

claudio.serio

    Member

  • Members
  • PipPip
  • 25 posts

Posted 24 June 2015 - 02:53 PM

Hallo everyone,

 

Always problems with SD Card.

 

This is my text file on my SD:

 

[NET]
192.168.1.33
8080
255.255.255.0
192.168.1.1
193.206.115.20
[RS]
9600
8
0
1
0
[ACQ]
2
1
1
1
[LOG]
0
24
 
This is my code to read the file:
 
        Dim GetSet As New FileStream("\SD\Conf2.txt", FileMode.Open, FileAccess.Read)
 
        Dim sr As New StreamReader(GetSet)
 
        While Not sr.Peek <= 0
            Dim s As String = sr.ReadLine
            Debug.Print(s)
        End While
        Debug.Print("Exited from While Loop")
        While True
            Thread.Sleep(Timeout.Infinite)
 
        End While
 
.... and this is my output:
 
[NET]
192.168.1.33
8080
255.255.255.0
192.168.1.1
193.206.115.20
[RS]
9600
8
0
1
0
[ACQ]
2
1
1
1
[LOG]
0
24
 
... i don't understand why it remains in the first while loop.
 
Somebody could help me, please ?
 
I spent my last 2 hours for this, it should be simple, but .....

 



#2 HSven1611

HSven1611

    Member

  • Members
  • PipPip
  • 14 posts

Posted 25 June 2015 - 05:46 AM

As far as I know StreamReader.Peek "Returns the next available character but does not consume it." That is what MSDN sais.

 

You might want to use the EndOfStream Property. MSDN: "Gets a value that indicates whether the current stream position is at the end of the stream."

 

This should work (btw. I'm not really into VB so please excuse if I did not get the syntax correct)

While Not sr.EndOfStream
[...]


#3 claudio.serio

claudio.serio

    Member

  • Members
  • PipPip
  • 25 posts

Posted 25 June 2015 - 10:40 AM

No, it doesnt work.

 

The sr.enfofstream is true in the moment i create the stream.

 

This code

 

        Dim GetSet As New FileStream("\SD\Conf.txt", FileMode.Open, FileAccess.Read)
        Dim sr As New StreamReader("\SD\Conf.txt")
        Debug.Print(sr.EndOfStream.ToString)
 

give this output

 

TRUE

 

 

Thank you



#4 cSharper

cSharper

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationOrlando, FL

Posted 31 July 2015 - 06:49 PM

This is how I read from my SD card:
 

        public string GetFileFromSD(string FilePath) {
            var line = "";
            using (FileStream fs2 = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.None)) {
                using (StreamReader sr = new StreamReader(fs2)) {

                    Debug.Print(line);
                    line = sr.ReadToEnd();
                }
            }
            return line;
        }






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.