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.

grimbouk

Member Since 09 May 2011
Offline Last Active Jul 12 2011 08:02 AM
-----

Posts I've Made

In Topic: Netduino Firmware v4.2.0 BETA 1

05 July 2011 - 07:44 AM

Hmm. Thanks for the details. Very interesting.

Two questions:
1. Does ColinR's sample work as a workaround?
2. Does your example work with files on Windows (i.e. is the behavior inconsistent between .NET and .NET MF)?

Chris


Very interesting. I wonder if that has become the recommended way to check for EndOfStream? If you search you'll find that a lot of people give examples they way I use EndOfStream. I managed to find one official example as well: http://msdn.microsof...y/ee461504.aspx (step 9).

Answers:-
2. This design pattern does work in the standard framework as I use it quite often.

1. Interesting, this pattern manages to read all the lines, but doesn't stop trying to read lines when the EndOfStream is hit:-

Debug.Print(File.Exists(filename) ? "File Found" : "File Not Found!");

using (StreamReader sr = new StreamReader(filename))
    {   
        Debug.Print("Initial EOS:" + sr.EndOfStream.ToString());

        String line;    
        // Read and display lines from the file until the end of    
        // the file is reached.    
        while ((line = sr.ReadLine()) != null)    
        {
            Debug.Print("LINE:" + line + " - EOS:" + sr.EndOfStream.ToString());
        }
}

This gived me the following output...

File Found
Initial EOS:True
LINE:TestLine0 - EOS:False
LINE:TestLine1 - EOS:False
LINE:TestLine2 - EOS:False
LINE:TestLine3 - EOS:False
LINE:TestLine4 - EOS:True
LINE: - EOS:True
LINE: - EOS:True
LINE: - EOS:True
...

So it looks like EndOfStream isn't set until the first line is read.

If I step over the code, "line" is never set to null, if there's no data available it seems to be set to empty string. I wouldn't be happy to use this to determin the end of file.

It looks like I can get what I want by using a mix of this approach and adding a check for EndOfStream within the loop, like this:-

using (StreamReader sr = new StreamReader(filename))
{
    Debug.Print("Initial EOS:" + sr.EndOfStream.ToString());
    String line;    
    // Read and display lines from the file until the end of    
    // the file is reached.    
    while ((line = sr.ReadLine()) != null)    
    {
        Debug.Print("LINE:" + line + " - EOS:" + sr.EndOfStream.ToString());
        if (sr.EndOfStream) break;
    }
}

Tim

In Topic: Netduino Firmware v4.2.0 BETA 1

04 July 2011 - 06:33 PM

Hi Chris,

Hi Tim,

Could you please attach the file? [Also, silly question...is the file empty?]

Chris


sure. I'm actually writing the file in a previous session using streamwriter. The file looks fine, I can open it by taking the SD card and putting it in an addapter on my PC. I haven't checked yet if the lines are terminated correctly though.

Here's some sample code:-

            string filename = "SD\\test.txt";
            StreamWriter sw = new StreamWriter(filename);
            for (int i = 0; i < 5; i++ )
            {
                sw.WriteLine("TestLine" + i.ToString());
            }
            sw.Flush();
            sw.Close();

            Debug.Print(File.Exists(filename) ? "File Found" : "File Not Found!");

            StreamReader sr = new StreamReader(filename);
            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                Debug.Print(line);
            }
            sr.Close();

When I run the code I get the "FileFound" output, but nothing is returned for reading the lines. Any ideas what I'm doing wrong?

I've attached the file that's created as well.

thanks
Tim

Update: If I skip the check for !sr.EndOfStream, and just do a ReadLine, I do just get the first line of data. At least this proves that reading data works and that each line of data seems terminated correctly. It does just seem that EndOfStream is not working... or I'm misusing it ;-)

In Topic: OneWire ALPHA

04 July 2011 - 06:14 PM

Hi Guys, Do you have an update as to when we can expect the OneWire functionality to be rolled into the core platform? From what I've seen it works great... But I am only using it with a couple of DS18B20s. Thanks Tim

In Topic: Netduino Firmware v4.2.0 BETA 1

04 July 2011 - 06:03 PM

hi guys,

should "EndOfStream" for StreamReader be working at the momment?

The following code always returns "True" and never drops into the loop to read data

StreamReader sr = new StreamReader("SD\\Filename.txt");
while (!sr.EndOfStream)
{
    string line = sr.ReadLine();
}
sr.Close()

any ideas?

thanks
Tim

In Topic: OneWire ALPHA

02 June 2011 - 03:15 PM

Hi guys, this is great work! Is it possible to provide the same beta firmware for the NetduinoMini? Or have I missed something somewhere? thanks Tim

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.