コード例 #1
0
        private bool OutputRawData(string path,MeasureData src,int idx) {
            //string rawDat = MakeRawDataStringFormat(MakeRawDataList(src._raw_R));
            List<string> rawData = new List<string>();
            rawData.Add(MakeRawDataColumnFormat());
            rawData.AddRange(MakeRawDataList(src._raw_samplingResult, src._raw_gamma, src._raw_bsl));

            //List<string> mvAvg_rawData = new List<string>();
            //mvAvg_rawData.Add("\r\n\r\n***以下移動平均後の生データ***\r\n\r\n");
            //mvAvg_rawData.Add(MakeRawDataColumnFormat());
            //mvAvg_rawData.AddRange(MakeRawDataList(src._mvAvg_samplingResult, src._mvAvg_gamma, src._mvAvg_bsl));
            string fileName = path + "_" + (idx+1).ToString() + ".csv";
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, false, System.Text.Encoding.GetEncoding("shift_jis"))) {
                try {
                    for (int i = 0; i < rawData.Count; i++) {
                        sw.WriteLine(rawData[i]);
                    }
                } catch (Exception) {
                    return false;
                }
            }
            return true;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: lvojp/bloodSugarLevelMeter
		private bool getMeasure(int samplingCount,bool forStability) {
			bool result = false;

			if (_continuousSamplingCount == 0) {
				InitializeSamplingDatas();

				//データ件数表示の初期化
				samplingCount_lbl.Text = _continuousSamplingCount.ToString();
				samplingCount_lbl.Refresh();
			} 

			//タイムアウト用タイマースタート
			System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
			sw.Start();
					   
            //List<int> sampParam =  new List<int>{int.Parse(_settings._data._measureDataCount),int.Parse(_settings._data._waitTime)};
            List<int> sampParam =  new List<int>{1000,int.Parse(_settings._data._waitTime)};
			//サンプリング開始
            if (_machine.StartSampling(sampParam)) {
			} else {
				result = false;
			}

            long time = 0;

			 //装置の応答待ち
			if (_machine.GetStatus() != true) {
				while (_machine._sampStatus != Machine.SamplingStatus.FINISH) {
					_machine.GetStatus();
					if (sw.ElapsedMilliseconds > 10000) {
                        result = true;
					}
				}
			}
            
            time = sw.ElapsedMilliseconds;

			//データの取得
			//if (_machine.GetSamplingData(0, samplingCount -1)) {
			if (_machine.GetSamplingData(0, 1000 -1)) {
				
				//sigref計算
				_dp = new DataProcessor(_machine, _settings);
				_dp.Main();

				//生データを入れる
                List<List<SamplingResult>> allSamplingResult = _dp._allSamplingResult;
                List<List<double>> allGammaList = _dp._allGammaList;
                List<double> allBslList = _dp._allBslList;

                //それぞれの平均結果を取得
                _md = new MeasureData(_settings);
                _md.GetSamplingResult(allSamplingResult,samplingCount);
                _md.GetGammaResult(allGammaList,samplingCount);
                //GetBslResult() -> BSLは平均されたガンマデータを元に作成するので、引数は必要ないけど、生データはほしい
                _md.GetBslResult(allBslList);

                //測定の付随データの整理
                //現在の温度情報
                _md.SetTemp(GetTempDisplay());


                ////最終フォーマットのデータ生成
                //ProductDataFormat pdf = new ProductDataFormat(_settings, _temp_tbx);
                //pdf.SetDatas(_dp._avgSamplingList, _dp._avgGammaList, estimateData);
                //_pdfList.Add(pdf);

				result = true;

			} else {
				result = false;
			}

            //飽和チェック
            string overflowMessage = CheckOverFlow(45000, 55000);
            if (overflowMessage.IndexOf("飽和") != -1) {
                log_tbx.Text = "入力が飽和したため、測定は正しく終了しませんでした。";
                log_tbx.Refresh();
                MessageBox.Show(overflowMessage);
                result = false;
            }


			//データの取得が問題なければ、かつ安定性測定でなければ
			if (result == true) {
				if (!forStability) {
                    //_continuousSamplingCount++;
                    //samplingCount_lbl.Text = (_continuousSamplingCount).ToString();

                    //ファイル出力
                    CsvMaker csv = new CsvMaker();
                    //string filename = OpenFileSetDialog("MeasureData.csv");

                    if (csv.MakeMeasureDataFile(_md, _user._fileDirectory, _user.GetMeasureDataCount()) == false) {
                        MessageBox.Show("結果をファイルに書き込む事ができませんでした。\r\nファイルが開かれていないか確認してください。");
                    }
                }
			}
			return result;
		}
コード例 #3
0
        public bool MakeMeasureDataFile(MeasureData src, string path, int idx) {
            DateTime date = DateTime.Now;

            string fileName = path + "\\data.csv";
            string rawFileDirectory = path + "\\RAW\\";
            string file = "";

            if (idx == 0) {
                file += MakeMeasureDataColumns();
            }


            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, true, System.Text.Encoding.GetEncoding("shift_jis"))) {
                file += "\r\n";
                //カウント
                file += (idx + 1).ToString() + ",";

                //測定日時
                file += date.ToString("yy/MM/dd/hh:mm:ss") + ",";

                //ボックスの温度
                file += src._tempData[0] + ",";

                //LD温度
                for (int i = 1; i < src._tempData.Count; i++) {
                    file += src._tempData[i] + ",";
                }

                //駆動電流
                for (int i = 0; i < src._settings._data._ldDrive.Count; i++) {
                    file += src._settings._data._ldDrive[i] + ",";
                }

                //バイアス電流
                for (int i = 0; i < src._settings._data._ldBias.Count; i++) {
                    file += src._settings._data._ldBias[i] + ",";
                }

                //安定待ち時間
                file += src._settings._data._interval._time + ",";

                //ゲイン
                file += src._settings._data._gain._sig + ",";
                file += src._settings._data._gain._ref + ",";

                //オフセット
                file += src._settings._data._offset._sig + ",";
                file += src._settings._data._offset._ref + ",";

                //校正係数
                for (int i = 0; i < src._settings._data._ldCalib.Count; i++) {
                    file += src._settings._data._ldCalib[i] + ",";
                }

                //LD-λ変換表

                for (int i = 0; i < src._settings._data._lambdaCorrespTable.Count; i++) {
                    file += src._settings._data._lambdaCorrespTable[i].Replace("λ", "") + ",";
                }

                //平均サンプル数
                file += src._settings._data._measureDataCount + ",";

                //オフセット
                file += src._avg_samplingResult[0]._sigDat.ToString() + ",";
                file += src._avg_samplingResult[0]._refDat.ToString() + ",";

                //サンプリングデータ
                for (int i = 1; i < src._avg_samplingResult.Count; i++) {
                    file += src._avg_samplingResult[i]._sigDat.ToString() + ",";
                    file += src._avg_samplingResult[i]._refDat.ToString() + ",";
                    file += src._avg_samplingResult[i]._sigrefDivDat.ToString() + ",";
                }

                //ガンマ
                for (int i = 0; i < src._avg_gamma.Count; i++) {
                    file += src._avg_gamma[i].ToString() + ",";
                }

                //推定値係数
                for (int i = 0; i < src._settings._data._estimate.Count; i++) {
                    file += src._settings._data._estimate[i] + ",";
                }

                //BSL
                file += src._bsl.ToString();


                try {
                    sw.Write(file);
                    
                    if (OutputRawData(rawFileDirectory, src,idx) != true) {
                        return false;
                    }

                } catch (Exception) {
                    return false;
                }
            }

            return true;
        }