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.

newPudong

Member Since 22 Aug 2014
Offline Last Active Sep 30 2014 08:18 AM
-----

Topics I've Started

Serial port stop reading

19 September 2014 - 02:53 AM

Hi,

 

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.Open();
_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived);

... ...


private Boolean DataReceived(SerialPort reader)
{
	Boolean bResult = true;
	byte[] buffer = null;
	try
	{
		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.Flush();
				}
				_fileStream.Close();
				_fileStream.Dispose();
				_fileStream = null;
			}
			reader.DiscardInBuffer();
		}
	}
	catch (Exception exp)
	{
		bResult = false;
		Debug.Print(exp.Message);
	}
	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.

 

 


Deploy Application to NP2

22 August 2014 - 02:59 AM

Hi everyone,

 

I'm a green hand to Netduino :)

I got a Netduino Plus 2 board, and I upgrade the firmware to V4.3, I made an application with Visual Studio 2012 Express, it worked well.

Now I want to know: whether I can deploy my application with .NET Micro Framework Deployment Tool(Version 4.3.1.0)? and How do I?

 

THKs.


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.