remove TIME column on datalogger

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
charlyprouteau
Posts: 33
Joined: Wed Jan 23, 2013 2:01 am

remove TIME column on datalogger

Post by charlyprouteau »

HI!
Is it possible to remove the "Time" column on a Datalogger?

My need is to have a first column with date (like YYYYMMMDD), and a second column with time (like mmss). I succeeded this.

But when I export the Datalogger to a CSV file to an USB stick for example.
Could you give me a mean to remove the exported TIME column on the CSV file directly by Scripting or a way to have two columns?

Thanks for your reply.

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: remove TIME column on datalogger

Post by Edmund »

Well, there is no easy clean solution for this.

But there is a couple of dirty ones :D

You could create your own export routine and handle the remove there.

e.g. I Have a Datalogger called DataLogger1 with the following content

Id;Time;M123_Ref;M132_Ref;VVX125_Temp_1
1;"2013-11-21 03:59:09";95;92;56,36574
2;"2013-11-21 04:00:09";95;92;55,03472
3;"2013-11-21 04:01:10";95;92;57,72569
4;"2013-11-21 04:02:09";95;92;57,55208
5;"2013-11-21 04:03:09";95;92;55,23727
6;"2013-11-21 04:04:09";95;92;57,14699
7;"2013-11-21 04:05:09";95;92;58,04398
8;"2013-11-21 04:06:09";95;92;57,11806
9;"2013-11-21 04:07:09";95;92;58,24653
10;"2013-11-21 04:08:09";95;92;56,85764


If i run my little test project and export the datalogger to a USB stick, I get the following result

Id;Time;M123_Ref;M132_Ref;VVX125_Temp_1
1;"2013-11-21";95;92;56,36574
2;"2013-11-21";95;92;55,03472
3;"2013-11-21";95;92;57,72569
4;"2013-11-21";95;92;57,55208
5;"2013-11-21";95;92;55,23727
6;"2013-11-21";95;92;57,14699
7;"2013-11-21";95;92;58,04398
8;"2013-11-21";95;92;57,11806
9;"2013-11-21";95;92;58,24653
10;"2013-11-21";95;92;56,85764


NOTE! This is not any good complete solution with correct error handling.

Code: Select all


void Button3_Click(System.Object sender, System.EventArgs e)
		{
			Globals.DataLoggerExport.Export("DataLogger1");
		}

Code: Select all

//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
	using System.IO;
	using System.Reflection;
  
    public partial class DataLoggerExport
    {
		public void Export(string datalogger)
		{
			// Source datalogger
			var source = @"Project Files\DatabaseExport\"+ datalogger +".csv";
			
			// In a panel with Windows CE the USB stick is mounted into @"\Hard Disk\"
			var target = @"d:\"+ datalogger +".csv";

			try
			{
				StreamReader sR = new StreamReader(source);
				StreamWriter sW = new StreamWriter(target);
				
				// Skip first line (header)
				string row = sR.ReadLine();
				sW.WriteLine(row); 
				
				while (sR.Peek() != -1) // stops when it reachs the end of the file
				{
					row = sR.ReadLine();
					
					// Modify the row
					string[] rowArray = row.Split(';');
					
					// DateTime is in colum 2 (index 1)
					// Remove the time part
					rowArray[1] = rowArray[1].Substring(0,11)+"\"";
					
					// Rejoin the row
					row = String.Join(";",rowArray);
					
					// Write to your custum file
					sW.WriteLine(row); 
				}
				
				sR.Close();
				sW.Close();

				MessageBox.Show("Export OK");
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}				
		}	
		
		
		/// <summary>
		/// Get the path from where the project is executing.
		/// </summary>
		public string GetExcecutingPath
		{
			get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); }
		}
    }
}


Or if you want to seperate the Date and Time parts

Code: Select all

public void Export(string datalogger)
		{
			// Source datalogger
			var source = @"Project Files\DatabaseExport\"+ datalogger +".csv";
			
			// In a panel with Windows CE the USB stick is mounted into @"\Hard Disk\"
			var target = @"d:\"+ datalogger +".csv";

			try
			{
				StreamReader sR = new StreamReader(source);
				StreamWriter sW = new StreamWriter(target);
				
				// Skip first line (header)
				string row = sR.ReadLine().Replace("Time;", "Date;Time;");
				sW.WriteLine(row); 
				
				while (sR.Peek() != -1) // stops when it reachs the end of the file
				{
					row = sR.ReadLine();
					
					// Modify the row
					string[] rowArray = row.Split(';');
					
					// DateTime is in colum 2 (index 1)
					var dateTime = rowArray[1].Split(' ');
					rowArray[1] = dateTime[0]+"\";\""+ dateTime[1];
					
					// Rejoin the row
					row = String.Join(";",rowArray);
					
					// Write to your custum file
					sW.WriteLine(row); 
				}
				
				sR.Close();
				sW.Close();

				MessageBox.Show("Export OK");
			}
			catch (Exception ex)
			{
				MessageBox.Show("Export Failed (Reason: " + ex.Message + ")");
			}				
		}	

Id;Date;Time;M123_Ref;M132_Ref;VVX125_Temp_1
1;"2013-11-21";"03:59:09";95;92;56,36574
2;"2013-11-21";"04:00:09";95;92;55,03472
3;"2013-11-21";"04:01:10";95;92;57,72569
4;"2013-11-21";"04:02:09";95;92;57,55208
5;"2013-11-21";"04:03:09";95;92;55,23727
6;"2013-11-21";"04:04:09";95;92;57,14699
7;"2013-11-21";"04:05:09";95;92;58,04398
8;"2013-11-21";"04:06:09";95;92;57,11806
9;"2013-11-21";"04:07:09";95;92;58,24653
10;"2013-11-21";"04:08:09";95;92;56,85764


Maby this can be something you can get started from...


Best Regards
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

Post Reply