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

Frequent writing into SD card caused lost data in reading from serial port

SD card Serial Port FileStream StreamWriter COM1 Lost Data Threads I/O Buffer Data Stream

  • Please log in to reply
3 replies to this topic

#1 Afshin

Afshin

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationCanada

Posted 09 June 2014 - 10:14 PM

Hello,

 

I am experiencing a confusing problem with reading data from the serial port (COM1), and writing some data into a text file on SD card.

 

In my scenario, a serial RF transceiver is connected to COM1. The received data is in the form of few messages per second with the length of 40-50 bytes each. Some processes are done on the received data, and processing results are written into the disk. However, application specification results in a higher amount of data to be written into the disk, compared to the amount of data received and delivered by the RF transceiver, about 100 bytes per 10-20 milliseconds, like a data stream.

 

Having said that, I've made two different threads except the main thread, one to only read data without any processing from the port and store them into a buffer (a byte array), and the other to process the stored data and write the results into the disk (using FileStream and StreamWriter methods).

 

Everything works fine, when the writing into the disk is disabled (using some flags in my code), and all data can be processed properly as I can validate it from the debug display. However, when the writing is active, data are not received completely from the serial port, and some part of messages are lost. This does not happens all the time, but happens frequently enough to degrade the total processing performance. 

 

Considering that I have used two different threads, and given a higher priority to the "serial port reader" thread and a lower priority to a the "Disk Writer" thread, is it possible that a kind of shared buffer in a lower level is used commonly between that Disk I/O and Serial Port I/O that causes overriding somewhere. 

 

any advice is appreciated. Thanks.



#2 SocalSam

SocalSam

    New Member

  • Members
  • Pip
  • 1 posts

Posted 11 June 2014 - 08:07 PM

This may seem an odd question, but is this a new SD card?  The average SD card has a set number of read writes specified (10,000,000 or so, but that is de-rated so the manufacturers don't get sued, so it is higher).  This random read/write could be caused by this.

 

The reason for this, or so I have read,  is that the edge capacitors wear out over time.  Not sure what the physics of that is, but without seeing the code, that is my first thought. 



#3 liqdfire

liqdfire

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 13 June 2014 - 02:46 PM

I have this problem as well, thought I am using two serial ports, at the same time as the SD card.

 

I have read on the forums, it may be caused by the SD card turning interrupts off on the microcontroller when it is doing writes, and the serial port misses putting the data on the buffer.



#4 Afshin

Afshin

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationCanada

Posted 14 July 2014 - 06:57 PM

Thanks SocialSam and liqdfire for the answers, and sorry for the delay in following up with my question, I was away for awhile. 

 

I have read on the forums, it may be caused by the SD card turning interrupts off on the microcontroller when it is doing writes, and the serial port misses putting the data on the buffer.

 

Yes lidfire, it makes sense then, since what I see in those cases are original data with some missed bytes, and the rest is untouched!

I will search more to see if will be able to find a reference for this. Thanks.







Also tagged with one or more of these keywords: SD card, Serial Port, FileStream, StreamWriter, COM1, Lost Data, Threads, I/O, Buffer, Data Stream

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.