Example #1
0
        /// <summary>
        /// センサーデータ書き込みスレッド
        /// </summary>
        private void writeSensorData()
        {
            // UTF-8(BOMなし)エンコード未指定でもOK。
            Encoding enc = new UTF8Encoding(false);
            // UTF-8(BOMあり)
            //Encoding enc = new UTF8Encoding(true);

            FileStream   fs = new FileStream(this.saveFilePath, FileMode.CreateNew);
            StreamWriter sw = new StreamWriter(fs, enc);

            sw.WriteLine(string.Format("{0}{1}", Constants.FILE_HEADER_DATA_MODE, this.changeMeasureMode(this.measureMode)));
            sw.WriteLine(string.Format("{0}{1}", Constants.FILE_HEADER_TRANSMISSION_SPEED, this.changeTransmissionSpeed(this.measureTransmissionSpeed)));
            sw.WriteLine(string.Format("{0}{1}", Constants.FILE_HEADER_ACC_RANGE, this.changeMeasureAccRange(this.measureAccRange)));
            sw.WriteLine(string.Format("{0}{1}", Constants.FILE_HEADER_GYRO_RANGE, this.changeMeasureGyroRange(this.measureGyroRange)));
            sw.WriteLine(Constants.FILE_HEADER_COMMENT);

            if (this.dataHeader.Equals(string.Empty) == false)
            {
                sw.WriteLine(string.Format("{0}{1}", Constants.FILE_HEADER_COMMENT, this.dataHeader));
            }

            DateTime utcNow   = DateTime.UtcNow;
            DateTime utcAdd   = utcNow;
            string   yData    = string.Empty;
            string   lineData = string.Empty;

            try
            {
                while (this.fileWriteThreadLoop)
                {
                    List <MeasureBean> sensorDataList = this.getSensorData();
                    if (sensorDataList == null)
                    {
                        Thread.Sleep(10);
                        continue;
                    }
                    lineData = string.Empty;
                    for (int index = 0; index < sensorDataList.Count; index++)
                    {
                        MeasureBean bean = sensorDataList[index];

                        utcAdd    = utcNow.AddMilliseconds(bean.X);
                        lineData += string.Format("{0},{1},{2},{3}", bean.Marking == true ? "X" : "",
                                                  bean.SerialNumber,
                                                  utcAdd.ToString(this.dateTimeFormat),
                                                  bean.Y[0]);
                        for (int yIndex = 1; yIndex < bean.Y.Length; yIndex++)
                        {
                            lineData += string.Format(",{0}", bean.Y[yIndex]);
                        }
                        lineData += "\r\n";
                    }
                    sw.Write(lineData);
                    this.tcpServer.SetSendData(lineData);
                }
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
Example #2
0
        /// <summary>
        /// ファイルデータ取得
        /// </summary>
        /// <returns></returns>
        public List <MeasureBean> GetFileData()
        {
            List <MeasureBean> result = new List <MeasureBean>();

            if (this.replayPause)
            {
                return(result);
            }

            try
            {
                // 排他する
                measureDataMutex.WaitOne();

                if (this.PlotData == false)
                {
                    // 経過時間算出
                    TimeSpan timeSpan = DateTime.Now - this.fileReadStartTime;
                    long     milliSec = Convert.ToUInt32(timeSpan.TotalMilliseconds * this.replaySpeed);

                    // 経過時間を過ぎたデータを通知する
                    int listCount = this.fileDataList.Count;
                    if (listCount > 0)
                    {
                        for (int index = this.notificationCount; index < listCount; index++)
                        {
                            MeasureBean bean = this.fileDataList[index];
                            if (bean.X > milliSec)
                            {
                                break;
                            }
                            result.Add(bean);
                            this.notificationCount++;
                        }
                    }
                }
                else
                {
                    this.notificationCount = this.fileDataList.Count;
                }
            }
            catch (Exception ex)
            {
                Tracer.WriteException(ex);
            }
            finally
            {
                // Mutexロック解放
                measureDataMutex.ReleaseMutex();

                if ((this.fileReadEnd) && (this.fileDataList.Count == this.notificationCount))
                {
                    this.fileReadEnd = false;
                    // 再生終了イベントを通知
                    if (this.EndFileDataEvent != null)
                    {
                        this.EndFileDataEvent();
                    }
                }
            }
            return(result);
        }