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.