Exemplo n.º 1
0
        public static void SaveConfig(PolyConfig cfg)
        {
            StreamWriter   sw         = new StreamWriter(PolyConstants.ConfigFileName);
            JsonWriter     writer     = new JsonTextWriter(sw);
            JsonSerializer serializer = new JsonSerializer();

            serializer.Serialize(writer, cfg);
            writer.Close();
            sw.Close();
        }
Exemplo n.º 2
0
        public FormConfig(PolyConfig cfgarg)
        {
            InitializeComponent();
            cfg = cfgarg;

            numUDRecLen.Value         = cfg.RecordLength;
            numUDStartDelay.Value     = cfg.StartDelay;
            CB_Filter.Checked         = cfg.FilterOn;
            CB_PressureRelief.Checked = cfg.PressureRelief;
        }
Exemplo n.º 3
0
        private void butSettings_Click(object sender, EventArgs e)
        {
            var fc = new FormConfig(Cfg);

            if (fc.ShowDialog() == DialogResult.OK)
            {
                Cfg = fc.GetDialogData();
                PolyConfig.SaveConfig(Cfg);
                UpdateGraphics();
            }
            fc.Dispose();
        }
Exemplo n.º 4
0
 private void butNewRecord_Click(object sender, EventArgs e)
 {
     saveFileDialog1.FileName         = "";
     saveFileDialog1.InitialDirectory = Cfg.DataDir.ToString();
     saveFileDialog1.Filter           = "Text files | *.txt|All files | *.*";
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         Cfg.DataDir = Path.GetDirectoryName(saveFileDialog1.FileName) + @"\";
         PolyConfig.SaveConfig(Cfg);
         CurrentFile      = Path.GetFileName(saveFileDialog1.FileName);
         labFileName.Text = "File: " + CurrentFile;
     }
 }
Exemplo n.º 5
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (decomposer != null)
     {
         if (Connected & decomposer.DeviceTurnedOn)
         {
             USBPort.WriteByte(PolyConstants.cmStopPump1);
             USBPort.WriteByte(PolyConstants.cmStopPump2);
         }
     }
     Cfg.Maximized    = WindowState == FormWindowState.Maximized;
     Cfg.WindowWidth  = Width;
     Cfg.WindowHeight = Height;
     PolyConfig.SaveConfig(Cfg);
 }
Exemplo n.º 6
0
        private void butOpenFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName         = "";
            openFileDialog1.InitialDirectory = Cfg.DataDir.ToString();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(openFileDialog1.FileName))
                {
                    Cfg.DataDir = Path.GetDirectoryName(openFileDialog1.FileName) + @"\";
                    PolyConfig.SaveConfig(Cfg);
                    ViewMode          = true;
                    ViewShift         = 0;
                    timerRead.Enabled = false;

                    CurrentFile = Path.GetFileName(openFileDialog1.FileName);
                    ReadFile(Cfg.DataDir + CurrentFile);
                }
            }
        }
Exemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();
            GInfoArr       = new GraphicsInfo[PolyConstants.NumOfChannels];
            AmpBarArr      = new TrackBar[4];
            AmpBarVals     = new int[4];
            ChannelsScaleY = new double[4];
            for (int i = 0; i < 4; i++)
            {
                ChannelsScaleY[i] = 1;
                AmpBarVals[i]     = 0;
            }
            USBPort = new USBserialPort(this, 115200);
            USBPort.ConnectionFailure += onConnectionFailure;
            USBPort.Connect();

            Cfg = PolyConfig.GetConfig();

            numUDplevel1.Value = Cfg.PressLevel1;
            numUDplevel2.Value = Cfg.PressLevel2;

            InitArraysForFlow();
            CheckDataDir();

            if (Cfg.Maximized)
            {
                WindowState = FormWindowState.Maximized;
            }
            else
            {
                WindowState = FormWindowState.Normal;
                Width       = Cfg.WindowWidth;
                Height      = Cfg.WindowHeight;
            }

            for (int i = 0; i < PolyConstants.NumOfChannels; i++)
            {
                GInfoArr[i].Visible = Cfg.VisibleGraphs[i];
            }
            UpdateGraphics();
        }
Exemplo n.º 8
0
        public static PolyConfig GetConfig()
        {
            PolyConfig     ac;
            JsonSerializer serializer = new JsonSerializer();

            try
            {
                using (StreamReader sr = new StreamReader(PolyConstants.ConfigFileName))
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        ac = (PolyConfig)serializer.Deserialize(reader, typeof(PolyConfig));
                        return(ac);
                    }
            }
            catch (Exception)
            {
                ac = new PolyConfig();
                SaveConfig(ac);
                return(ac);
            }
        }
Exemplo n.º 9
0
 private void butStopRecord_Click(object sender, EventArgs e)
 {
     StopRecord();
     Cfg.DataFileNum++;
     PolyConfig.SaveConfig(Cfg);
 }
Exemplo n.º 10
0
        public int Decompos(USBserialPort usbport, Stream saveFileStream, StreamWriter txtFileStream, PolyConfig cfg)
        {
            int bytes = usbport.BytesRead;

            if (bytes == 0)
            {
                _noDataCounter++;
                if (_noDataCounter > _maxNoDataCounter)
                {
                    DeviceTurnedOn = false;
                }
                return(0);
            }
            DeviceTurnedOn = true;
            if (saveFileStream != null & RecordStarted)
            {
                try
                {
                    saveFileStream.Write(usbport.PortBuf, 0, bytes);
                    TotalBytes += bytes;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Save file stream error. " + ex.Message);
                    Debug.WriteLine(ex.Message);
                }
            }
            for (int i = 0; i < bytes; i++)
            {
                switch (_byteNum)
                {
                case 0:    // Marker
                    if (usbport.PortBuf[i] == _marker1)
                    {
                        _byteNum = 1;
                    }
                    break;

                case 1:    // ECG1_0
                    _ecg1Tmp = (int)usbport.PortBuf[i];
                    _byteNum = 2;
                    break;

                case 2:    // ECG1_1
                    _ecg1Tmp += 0x100 * (int)usbport.PortBuf[i];
                    _byteNum  = 3;
                    break;

                case 3:    // ECG1_2
                    _ecg1Tmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_ecg1Tmp & 0x800000) != 0)
                    {
                        _ecg1Tmp -= 0x1000000;
                    }

                    Data.ECG1Array[MainIndex] = _ecg1Tmp;

                    _nextECG1 = _ecg1Tmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextECG1 = Filter.FilterForRun(Filter.coeff50, Data.ECG1Array, MainIndex);
                        }
                    }
                    _detrendECG1 = FilterRecursDetrend(filterCoeff, _nextECG1, _detrendECG1, _prevECG1);
                    Data.ECG1ViewArray[MainIndex] = (int)Math.Round(_detrendECG1);

                    _prevECG1 = _nextECG1;
                    _byteNum  = 4;
                    break;

                case 4:    // ECG2_0
                    _ecg2Tmp = (int)usbport.PortBuf[i];
                    _byteNum = 5;
                    break;

                case 5:    // ECG2_1
                    _ecg2Tmp += 0x100 * (int)usbport.PortBuf[i];
                    _byteNum  = 6;
                    break;

                case 6:    // ECG2_2
                    _ecg2Tmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_ecg2Tmp & 0x800000) != 0)
                    {
                        _ecg2Tmp -= 0x1000000;
                    }

                    Data.ECG2Array[MainIndex] = _ecg2Tmp;

                    _nextECG2 = _ecg2Tmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextECG2 = Filter.FilterForRun(Filter.coeff50, Data.ECG2Array, MainIndex);
                        }
                    }
                    _detrendECG2 = FilterRecursDetrend(filterCoeff, _nextECG2, _detrendECG2, _prevECG2);
                    Data.ECG2ViewArray[MainIndex] = (int)Math.Round(_detrendECG2);

                    _prevECG2 = _nextECG2;
                    _byteNum  = 7;
                    break;

                case 7:    // Reo_0
                    _reoTmp  = (int)usbport.PortBuf[i];
                    _byteNum = 8;
                    break;

                case 8:    // Reo_1
                    _reoTmp += 0x100 * (int)usbport.PortBuf[i];
                    _byteNum = 9;
                    break;

                case 9:    // Reo_2
                    _reoTmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_reoTmp & 0x800000) != 0)
                    {
                        _reoTmp -= 0x1000000;
                    }
                    if (_reoTmp > PolyConstants.ReoMaxVal)
                    {
                        _reoTmp = PolyConstants.ReoMaxVal;
                    }
                    Data.ReoArray[MainIndex] = -_reoTmp;

                    _nextReo = _reoTmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextReo = Filter.FilterForRun(Filter.coeff14, Data.ReoArray, MainIndex);
                        }
                    }

                    _detrendReo = FilterRecursDetrend(filterCoeffReo, _nextReo, _detrendReo, _prevReo);
                    Data.ReoViewArray[MainIndex] = (int)Math.Round(_detrendReo);

                    _prevReo = _nextReo;
                    _byteNum = 10;
                    break;

                case 10:    // Sphigmo1_0
                    _sphigmo1Tmp = (byte)usbport.PortBuf[i];
                    _byteNum     = 11;
                    break;

                case 11:    // Sphigmo1_1
                    _sphigmo1Tmp += 0x100 * (int)usbport.PortBuf[i];
                    _byteNum      = 12;
                    break;

                case 12:    // Sphigmo1_2
                    _sphigmo1Tmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_sphigmo1Tmp & 0x800000) != 0)
                    {
                        _sphigmo1Tmp = _sphigmo1Tmp - 0x1000000;
                    }

                    Data.Sphigmo1Array[MainIndex] = _sphigmo1Tmp;

                    _nextSphigmo1 = _sphigmo1Tmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextSphigmo1 = Filter.FilterForRun(Filter.coeff14, Data.Sphigmo1Array, MainIndex);
                        }
                    }

                    _detrendSphigmo1 = FilterRecursDetrend(filterCoeff, _nextSphigmo1, _detrendSphigmo1, _prevSphigmo1);
                    Data.Sphigmo1ViewArray[MainIndex] = (int)Math.Round(_detrendSphigmo1);
                    _prevSphigmo1 = _nextSphigmo1;
                    _byteNum      = 13;
                    break;

                case 13:    // Sphigmo2_0
                    _sphigmo2Tmp = (byte)usbport.PortBuf[i];
                    _byteNum     = 14;
                    break;

                case 14:    // Sphigmo2_1
                    _sphigmo2Tmp += 0x100 * (int)usbport.PortBuf[i];
                    _byteNum      = 15;
                    break;

                case 15:    // Sphigmo2_2
                    _sphigmo2Tmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_sphigmo2Tmp & 0x800000) != 0)
                    {
                        _sphigmo2Tmp = _sphigmo2Tmp - 0x1000000;
                    }

                    Data.Sphigmo2Array[MainIndex] = _sphigmo2Tmp;

                    _nextSphigmo2 = _sphigmo2Tmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextSphigmo2 = Filter.FilterForRun(Filter.coeff14, Data.Sphigmo2Array, MainIndex);
                        }
                    }

                    _detrendSphigmo2 = FilterRecursDetrend(filterCoeff, _nextSphigmo2, _detrendSphigmo2, _prevSphigmo2);
                    Data.Sphigmo2ViewArray[MainIndex] = (int)Math.Round(_detrendSphigmo2);
                    _prevSphigmo2 = _nextSphigmo2;
                    _byteNum      = 16;
                    break;

                case 16:     //Apex 0
                    _apexTmp = (int)usbport.PortBuf[i];
                    _byteNum = 17;
                    break;

                case 17:     //Apex 1
                    _apexTmp += 0x100 * (int)(usbport.PortBuf[i]);
                    _byteNum  = 18;
                    break;

                case 18:     //Apex 2
                    _apexTmp += 0x10000 * (int)usbport.PortBuf[i];
                    if ((_apexTmp & 0x800000) != 0)
                    {
                        _apexTmp = _apexTmp - 0x1000000;
                    }

                    Data.ApexArray[MainIndex] = _apexTmp;

                    _nextApex = _apexTmp;
                    if (cfg != null)
                    {
                        if (cfg.FilterOn)
                        {
                            _nextApex = Filter.FilterForRun(Filter.coeff14, Data.ApexArray, MainIndex);
                        }
                    }

                    _detrendApex = FilterRecursDetrend(filterCoeff, _nextApex, _detrendApex, _prevApex);
                    Data.ApexViewArray[MainIndex] = (int)Math.Round(_detrendApex);
                    _prevApex = _nextApex;

                    _byteNum = 19;
                    break;

                case 19:     //Status
                    Status = usbport.PortBuf[i];

                    if (Pump1Started & (Status & pump1progress) != 0)
                    {
                        _pump1RealyStarted = true;
                    }
                    if (_pump1RealyStarted)
                    {
//                                detrendSphigmo1 = 0;
                        Data.Sphigmo1ViewArray[MainIndex] = 0;    // (int)Math.Round(detrendSphigmo1);
                    }
                    if (_pump1RealyStarted & (Status & pump1progress) == 0)
                    {
                        _delayCounter1++;
                        if (_delayCounter1 > MaxDelayCounter)
                        {
                            Pump1Started       = false;
                            _pump1RealyStarted = false;
                            _detrendSphigmo1   = 0;
                            _delayCounter1     = 0;
                        }
                    }

                    if (Pump2Started & (Status & pump2progress) != 0)
                    {
                        _pump2RealyStarted = true;
                    }
                    if (_pump2RealyStarted)
                    {
                        _detrendSphigmo2 = 0;
                        Data.Sphigmo2ViewArray[MainIndex] = (int)Math.Round(_detrendSphigmo2);
                    }
                    if (_pump2RealyStarted & (Status & pump2progress) == 0)
                    {
                        _delayCounter2++;
                        if (_delayCounter2 > MaxDelayCounter)
                        {
                            Pump2Started       = false;
                            _pump2RealyStarted = false;
                            _detrendSphigmo2   = 0;
                            _delayCounter1     = 0;
                        }
                    }

                    _byteNum = 0;

                    if (RecordStarted)
                    {
                        txtFileStream.WriteLine(Data.GetDataString(MainIndex));
                    }
                    OnDecomposeLineEvent();
                    LineCounter++;
                    MainIndex++;
                    MainIndex &= (DataArrSize - 1);
                    break;
                }
            }
            usbport.BytesRead = 0;
            return(bytes);
        }