/// <summary> /// Determine and create the directory where the raw data is saved in 1-hour chunks. /// </summary> private void DetermineFilePath() { if (isActive) { if (presentHour != DateTime.Now.Hour) { if (bwPLFormat != null) bwPLFormat.CloseFile(); presentHour = DateTime.Now.Hour; // Need to create a new directory and switch the file name dayPath = DirectoryStructure.DayDirectoryToUse(aRootPathName); // Make sure hour directory exists currentDataFile = dayPath + "\\" + presentHour + "\\"; if (!System.IO.Directory.Exists(currentDataFile)) System.IO.Directory.CreateDirectory(currentDataFile); currentDataFile = currentDataFile + FILE_TYPE_MONIKER + "." + DirectoryStructure.GetDate() + "." + COMP_ID + "." + FILE_EXT; bwPLFormat = new ByteWriter(currentDataFile, true); bwPLFormat.OpenFile(); // Ensure that the first data point in the new file will start // with the full, rather than differential, timecode info. isForceTimestampSave = true; } } }
/// <summary> /// Save the file in case of power loss. Allow for appending afterwards. /// </summary> public void FlushBytes() { // Only run if file setup previously if (bwPLFormat != null) { bwPLFormat.Flush(); bwPLFormat.CloseFile(); bwPLFormat = new ByteWriter(currentDataFile, false); bwPLFormat.OpenFile(false); } }
private void SetupFiles(String byteFileName, String logFileName) { isSetup = true; DateTime dt = DateTime.Now; int tc = Environment.TickCount; fnData = byteFileName + "." + dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second + "-" + dt.Millisecond + ".b"; fnDataPLFormat = byteFileName + "." + dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second + "-" + dt.Millisecond + ".PLFormat"; logData = logFileName + "." + dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second + "-" + dt.Millisecond + ".log"; fw = new FileWriter(logData,false); WriteLogComment("TickCount at file creation: " + tc); bw = new ByteWriter(fnData,true); bw.OpenFile(); bwPLFormat = new ByteWriter(fnDataPLFormat,true); bwPLFormat.OpenFile(); }
/// <summary> /// Save the file in case of power loss. Allow for appending afterwards. /// </summary> public void FlushBytes() { // Only run if file setup previously if (isSetup && isActive) { bw.Flush(); bw.CloseFile(); bw = new ByteWriter(fnData,false); bw.OpenFile (false); bwPLFormat.Flush(); bwPLFormat.CloseFile(); bwPLFormat = new ByteWriter(fnDataPLFormat,false); bwPLFormat.OpenFile (false); } }
private void WriteTimeStampPLFormat(double unixTime, ByteWriter byteWriter) { if (isActive) { UnixTime.GetUnixTimeBytes(unixTime, retBytes); byteWriter.WriteBytes(retBytes, 6); } }
private void WriteTimeStamp(int time, ByteWriter byteWriter) { if (isActive) byteWriter.WriteInt(time); }
/// <summary> /// Test method /// </summary> static void Main() { String outFile = "\\My Documents\\testBytes.txt"; Console.WriteLine("Outfile: " + outFile); ByteWriter bw = new ByteWriter(outFile,true); bw.OpenFile(); for (int i = 0; i < 30; i++) { bw.WriteInt(i); Console.WriteLine("Wrote value: " + i); } bw.CloseFile(); }