المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : SOS Something strange with memory



C# Programming
11-19-2011, 07:52 PM
I’m writing one program (C# .Net 3.5) for temperature values reception from some device through COM port. The program (for convenient postprocessing of temperature values) divides received data on (figure 1):
MEASURE – continuous sequence of temperature values.
SET – consecutive set of several MEASUREs. Each SET is separated from another SET by a certain interval of time. For example, 15 minutes. After this time limit the program closes current SET and opens a new SET.
DAY – set of SETs received during a day.
The program seems to work as it supposed. But sometimes there is an overlapping of MEASUREs of different SETs of a DAY. For example, a MEASURE of one SET could be an absolute copy of a MEASURE of some another following SET (figure 2). Or any SET besides of its own MEASUREs can contain all MEASUREs of all following SETs. As a result some SET has MEASURE(s) which do not belong to it.
I have an idea that List M (see the code) of a SET sometimes during a day can refer on itself and on List M of the previous SET. It is incredible, because only one (current) SET and its (current) MEASURE could be active; the rest should be closed and not active.
What is wrong? What recommendations you will advise to reveal this bug?

figure 1 (http://s017.radikal.ru/i416/1111/2a/93abd3b46b5e.jpg)

figure 2 (http://s017.radikal.ru/i434/1111/0f/c7222740d208.png)


using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; namespace WindowsFormsApplication1 { class MyPoint { public double x; public double y; } class Measurement { List points = new List(); public void Add(MyPoint p) { points.Add(p); } } class Set { public Measurement CurrentM = null; List M = new List(); public Measurement GetNewM() { Measurement m = new Measurement(); /* * m.Field1 = ...; * m.Field2 = ...; * ... * m.FieldN = ...; */ return m; } public void CreateMesurement() { CurrentM = GetNewM(); M.Add(CurrentM); } } class Day { public Set CurrentS = null; List S = new List(); public void OnSetCreation() { CurrentS = new Set(); S.Add(CurrentS); } public void OnMeasureCreation() { CurrentS.CreateMesurement(); } public void WriteData() { // saving all data to disk } } static class DaysConteiner { static public Day Active; static double Temperature; static bool IfThereIsAGapBetweenTempuratureValues = false; static bool IfThereIsSetTimeLimitElapsed = false; static bool IfNewDay = false; static void OnStartNewDay() { if (IfNewDay) { Active.WriteData(); Active = new Day(); } } static internal void OnDataFromCOMPortReceived() { /* * data processing * Temperature = ...; * IfThereIsAGapBetweenTempuratureValues = ...; * IfThereIsSetTimeLimitElapsed = ...; */ /* * Sending data to Form by means of Invoke and so on */ if (IfThereIsSetTimeLimitElapsed) Active.OnSetCreation(); if (IfThereIsAGapBetweenTempuratureValues) Active.OnMeasureCreation(); MyPoint p = new MyPoint(); p.x = DateTime.Now.ToOADate(); p.y = Temperature; Active.CurrentS.CurrentM.Add(p); /* */ } } }