Hallo everyone,
Always problems with SD Card.
This is my text file on my SD:
  | |||||||||||||||||||||||||||
3 replies to this topic
#1Posted 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 .....
#2Posted 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 [...] #3Posted 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 #4Posted 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; } Also tagged with one or more of these keywords: SD Card
0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | |||||||||||||||||||||||||||