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

NP2 SD IO strange problem, bug ??

SD CardNP2 read error bug?

  • Please log in to reply
3 replies to this topic

#1 kerk-akker

kerk-akker

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationNetherlands

Posted 29 April 2014 - 12:59 PM

Hi,

 

I am using the SD card to store settings for my climate control program. During testing I sometimes get a System.IndexOutOfRangeExemption in System.IO.dll. It seems the program can not read the next line and generates and exemption.

 

After a lot of testing it seems that this error depends on the data that I write. For example if my file contains lines with test data: 0,3,1,0,222,22.12 I get the above error. If I take out the "." and store 0,3,1,0,222,2212 I do not get the error. In this example the behavior is consistent, a few debug runs give the same result. So, depending on the contents of the lines in the file it crashes or not ??

 

The error happens somewhere during the reading; i.e. a large number of lines are read correctly and then suddenly the above error appears.

 

I am not an experienced programmer so maybe I am doing something wrong.

 

I am quite desperate as this data logging is fundamental for my project........

 

Please help,

 

Arno 

 

 



#2 knut.tveitane

knut.tveitane

    Member

  • Members
  • PipPip
  • 18 posts

Posted 29 April 2014 - 01:31 PM

Hi Arno,

Difficult to tell without seeing the code where the exception happens. Are you trying to read your numbers as integers?(The value 22.12 is not an int but a real... 2212 however is int)

 

-knut



#3 kerk-akker

kerk-akker

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationNetherlands

Posted 29 April 2014 - 01:48 PM

Hi Knut,

 

Thanks for fast response. I am reading the data as text and later convert to int or float. I have attached the code below.

 

Looking forward to your feedback,

 

Br,

 

Arno

 

 

Attached Files



#4 kerk-akker

kerk-akker

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationNetherlands

Posted 29 April 2014 - 06:30 PM

Hi,

 

I have made a workaround, I read the file from SD at once with r.ReadToEnd() and then I split the file in lines and extract the data from each line. This is working. If I use r.ReadLine() I still get strange errors like described in my previous post. I suspect something with the StreamReader buffers as in some traces I have seen that I get a problem when the reading is crossing the bufferlevel. I mean when a line is e.g. from position 500 to 525 and the buffer is set on 512. I have tried to increase the buffer in StreamReader but in the traces I could not see that it changed. It stayed on 512 bytes.

 

I am still open for any tips what I might have done wrong and why I can not use s.ReadLine() to read my datafile on the SD.

 

I have attached the updated code.

 

Arno

Attached Files






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.