Netduino home hardware projects downloads community

Jump to content

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

Serial port stop reading

Serial Port SD Card

  • Please log in to reply
1 reply to this topic

#1 newPudong


    New Member

  • Members
  • Pip
  • 2 posts

Posted 19 September 2014 - 02:53 AM



I have a ND+2 with the firmware 4.3.0. A multithreaded application was written with C#, to read data from a serial port(COM2, baudrate=115200), and write them to a text file on SD card(2GB, FAT32 formatted).:-( but the application can't run too long time...


In an separated thread beside the main thread, the data was read from serial port and written to SD card, and after running several hours(2 or 3), it stopped reading.


Below are the sources:

SerialPort _serialPort = new SerialPort("COM2", 115200, Parity.None, 8, 1);
_serialPort.ReadTimeout = 20;
_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived);

... ...

private Boolean DataReceived(SerialPort reader)
	Boolean bResult = true;
	byte[] buffer = null;
		if (reader.BytesToRead > 0)
			buffer = ner byte[reader.BytesToRead];
			reader.Read(buffer, 0, buffer.Length);
			FileStream _fileStream = new FileStream("SD\\Log.txt", FileMode.Append, FileAccess.Write, FileShare.None);
			if (_fileStream != null)
				if (_fileStream.CanWrite == true)
					_fileStream.Write(buffer, 0, buffer.Length);
				_fileStream = null;
	catch (Exception exp)
		bResult = false;
	return bResult;

I need it running for months, to track data from COM port. but it can only run hours.


I am wondering, does it have any chance to create a dead lock when the COM port and the MOSI/SD apply to control the bus at the same time ?


And I also doubts, if the COM port keep receiving data without any reading operation, how does the ND+2 handle the datas?  Stop reading ? or abandon the following data?


Appreciate for any suggestions. Thanks a lot.



#2 Joshk


    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 27 October 2014 - 10:09 PM

Me too!  I just made a topic for the same thing.  Anywhere between 30 minutes and 3 hours, then it just stops!  It is not my code, and there is no debugging message!

Also tagged with one or more of these keywords: Serial Port, SD Card

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.