public MainWindow()
        {
            InitializeComponent();
            _measurements = new Measurements();

            mainChart.Series = _measurements.Items;
            measurementSelect.SelectionChanged += MeasurementSelect_SelectionChanged;
        }
Esempio n. 2
0
        private static bool AnalyzeArchive(Measurements m)
        {
            int meansureIndex = 1; //< Meansurement index

            if(m.ArchVersion == 0x0001)
                meansureIndex = 10;
            else if(m.ArchVersion == 0x0002)
                meansureIndex = 11;
            else
                meansureIndex = 12;

            DateTime currRecordDate = m.ArchCreateDate;

            Stream stream = File.OpenRead(m.ArchPath);
            int startByte = 64;
            using (BinaryReader br = new BinaryReader(stream))
            {
                br.BaseStream.Position = startByte;
                while (br.BaseStream.Position <= br.BaseStream.Length - 24)
                {

                    short[] rec = new short [meansureIndex];
                    for (int i = 0; i < 12; i++)
                    {
                        rec[i] = br.ReadInt16();
                        short temp = rec[i];
                        
                        if (temp != -30584)
                         //   temp = 0;
                        m.Measurement[i].Add((double)temp / 10);
                    }
                        

                    m.SecondAxisDate.Add(currRecordDate.ToShortTimeString());
                    currRecordDate = currRecordDate.AddSeconds(m.RegisterTime);
                }
                //m.UpdateItems();
                return true;
            }
        }
Esempio n. 3
0
        public static bool ImportFromFileTo(Measurements m)
        {
            OpenFileDialog opfd = new OpenFileDialog();

            opfd.Filter = "eSterownik archive(*.dat)|*.dat|All files(*.*)|*.*";

            if (opfd.ShowDialog() == true)
            {
                m.ArchPath = Path.GetFullPath(opfd.FileName);

                Stream stream = File.OpenRead(Path.GetFullPath(opfd.FileName));

                using (BinaryReader br = new BinaryReader(stream))
                {
                    // Filetype check
                    byte fileType = br.ReadByte();
                    if (fileType != 0x0001)
                    {
                        MessageBox.Show("Zły plik!", "Wrong file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }

                    // Version check
                    byte[] ver = br.ReadBytes(2);
                    short version = ToShort(ver[0], ver[1]);
                    m.ArchVersion = version;

                    // Date check
                    byte[] fileDate = br.ReadBytes(3);
                    m.ArchCreateDate = new DateTime(2000 + fileDate[0], fileDate[1], fileDate[2], 0, 0, 0);

                    // AppVersion check
                    byte[] appVer = br.ReadBytes(16);
                    string appVerStr = "";
                    foreach (var c in appVer)
                    {
                        if (c != 0x0000)
                            appVerStr += (char)c;
                    }
                    m.AppVersion = appVerStr;

                    // AppName ( eSterownik / eCoal)
                    byte[] app = br.ReadBytes(16);
                    string appNameStr = "";
                    foreach (var c in app)
                    {
                        if (c != 0x0000)
                            appNameStr += (char)c;
                    }
                    m.AppName = appNameStr;

                    // Time intervals
                    if (m.ArchVersion == 0x0004)
                        m.RegisterTime = br.ReadByte();
                    else
                        m.RegisterTime = 60;
                }

                // Archive version check
                if (m.ArchVersion < 0x0001 && m.ArchVersion > 0x0004)
                {
                    MessageBox.Show("Niestety twoja wersja archiwum nie jest jeszcze obsługiwana.", "Błąd!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
                AnalyzeArchive(m);
                    return true;
            }
            else
                return false;
        }