Enhance TemperatureDatalogger project -- add RTC capabilities so that data is logged along with the current time and date. Make logging interval configurable, set by a C# PC host application.

This commit is contained in:
Dean Camera 2010-01-24 11:13:23 +00:00
parent 03ee87b35a
commit dd995683ea
24 changed files with 1147 additions and 83 deletions

View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TempLoggerHostApp", "TempLoggerHostApp\TempLoggerHostApp.csproj", "{A2D66069-8CF9-4104-828C-49A73D7DB5D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A2D66069-8CF9-4104-828C-49A73D7DB5D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2D66069-8CF9-4104-828C-49A73D7DB5D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2D66069-8CF9-4104-828C-49A73D7DB5D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2D66069-8CF9-4104-828C-49A73D7DB5D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,181 @@
namespace Project1HostApp
{
partial class frmDataloggerSettings
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSetValues = new System.Windows.Forms.Button();
this.dtpTime = new System.Windows.Forms.DateTimePicker();
this.lblTime = new System.Windows.Forms.Label();
this.lblLoggingInterval = new System.Windows.Forms.Label();
this.nudLogInterval = new System.Windows.Forms.NumericUpDown();
this.lblSeconds = new System.Windows.Forms.Label();
this.btnGetValues = new System.Windows.Forms.Button();
this.lblDate = new System.Windows.Forms.Label();
this.dtpDate = new System.Windows.Forms.DateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.nudLogInterval)).BeginInit();
this.SuspendLayout();
//
// btnSetValues
//
this.btnSetValues.Location = new System.Drawing.Point(168, 136);
this.btnSetValues.Name = "btnSetValues";
this.btnSetValues.Size = new System.Drawing.Size(90, 35);
this.btnSetValues.TabIndex = 0;
this.btnSetValues.Text = "Set Values";
this.btnSetValues.UseVisualStyleBackColor = true;
this.btnSetValues.Click += new System.EventHandler(this.btnSetValues_Click);
//
// dtpTime
//
this.dtpTime.CustomFormat = "";
this.dtpTime.Format = System.Windows.Forms.DateTimePickerFormat.Time;
this.dtpTime.Location = new System.Drawing.Point(148, 61);
this.dtpTime.Name = "dtpTime";
this.dtpTime.ShowUpDown = true;
this.dtpTime.Size = new System.Drawing.Size(110, 20);
this.dtpTime.TabIndex = 1;
//
// lblTime
//
this.lblTime.AutoSize = true;
this.lblTime.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTime.Location = new System.Drawing.Point(51, 67);
this.lblTime.Name = "lblTime";
this.lblTime.Size = new System.Drawing.Size(82, 13);
this.lblTime.TabIndex = 2;
this.lblTime.Text = "Device Time:";
//
// lblLoggingInterval
//
this.lblLoggingInterval.AutoSize = true;
this.lblLoggingInterval.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblLoggingInterval.Location = new System.Drawing.Point(30, 101);
this.lblLoggingInterval.Name = "lblLoggingInterval";
this.lblLoggingInterval.Size = new System.Drawing.Size(103, 13);
this.lblLoggingInterval.TabIndex = 3;
this.lblLoggingInterval.Text = "Logging Interval:";
//
// nudLogInterval
//
this.nudLogInterval.Location = new System.Drawing.Point(148, 94);
this.nudLogInterval.Maximum = new decimal(new int[] {
60,
0,
0,
0});
this.nudLogInterval.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nudLogInterval.Name = "nudLogInterval";
this.nudLogInterval.Size = new System.Drawing.Size(51, 20);
this.nudLogInterval.TabIndex = 5;
this.nudLogInterval.Value = new decimal(new int[] {
5,
0,
0,
0});
//
// lblSeconds
//
this.lblSeconds.AutoSize = true;
this.lblSeconds.Location = new System.Drawing.Point(209, 101);
this.lblSeconds.Name = "lblSeconds";
this.lblSeconds.Size = new System.Drawing.Size(49, 13);
this.lblSeconds.TabIndex = 6;
this.lblSeconds.Text = "Seconds";
//
// btnGetValues
//
this.btnGetValues.Location = new System.Drawing.Point(30, 136);
this.btnGetValues.Name = "btnGetValues";
this.btnGetValues.Size = new System.Drawing.Size(90, 35);
this.btnGetValues.TabIndex = 7;
this.btnGetValues.Text = "Get Values";
this.btnGetValues.UseVisualStyleBackColor = true;
this.btnGetValues.Click += new System.EventHandler(this.btnGetValues_Click);
//
// lblDate
//
this.lblDate.AutoSize = true;
this.lblDate.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblDate.Location = new System.Drawing.Point(51, 33);
this.lblDate.Name = "lblDate";
this.lblDate.Size = new System.Drawing.Size(82, 13);
this.lblDate.TabIndex = 8;
this.lblDate.Text = "Device Date:";
//
// dtpDate
//
this.dtpDate.CustomFormat = "dd/MM/yyyy";
this.dtpDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpDate.Location = new System.Drawing.Point(148, 27);
this.dtpDate.Name = "dtpDate";
this.dtpDate.Size = new System.Drawing.Size(110, 20);
this.dtpDate.TabIndex = 9;
//
// frmDataloggerSettings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(300, 197);
this.Controls.Add(this.dtpDate);
this.Controls.Add(this.lblDate);
this.Controls.Add(this.btnGetValues);
this.Controls.Add(this.lblSeconds);
this.Controls.Add(this.nudLogInterval);
this.Controls.Add(this.lblLoggingInterval);
this.Controls.Add(this.lblTime);
this.Controls.Add(this.dtpTime);
this.Controls.Add(this.btnSetValues);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmDataloggerSettings";
this.Text = "DataLogger";
this.Load += new System.EventHandler(this.frmDataloggerSettings_Load);
((System.ComponentModel.ISupportInitialize)(this.nudLogInterval)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnSetValues;
private System.Windows.Forms.DateTimePicker dtpTime;
private System.Windows.Forms.Label lblTime;
private System.Windows.Forms.Label lblLoggingInterval;
private System.Windows.Forms.NumericUpDown nudLogInterval;
private System.Windows.Forms.Label lblSeconds;
private System.Windows.Forms.Button btnGetValues;
private System.Windows.Forms.Label lblDate;
private System.Windows.Forms.DateTimePicker dtpDate;
}
}

View file

@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Hid;
namespace Project1HostApp
{
public partial class frmDataloggerSettings : Form
{
private const int DEVICE_VID = 0x03EB;
private const int DEVICE_PID = 0xFAFA;
private struct Device_Report_t
{
public Byte Day;
public Byte Month;
public Byte Year;
public Byte Hour;
public Byte Minute;
public Byte Second;
public Byte LogInterval500MS;
public Byte[] ToReport()
{
Byte[] Report = new Byte[7];
Report[0] = this.Day;
Report[1] = this.Month;
Report[2] = this.Year;
Report[3] = this.Hour;
Report[4] = this.Minute;
Report[5] = this.Second;
Report[6] = this.LogInterval500MS;
return Report;
}
public void FromReport(Byte[] Report)
{
this.Day = Report[0];
this.Month = Report[1];
this.Year = Report[2];
this.Hour = Report[3];
this.Minute = Report[4];
this.Second = Report[5];
this.LogInterval500MS = Report[6];
}
};
private IDevice GetDeviceConnection()
{
IDevice[] ConnectedDevices = DeviceFactory.Enumerate(DEVICE_VID, DEVICE_PID);
IDevice ConnectionHandle = null;
if (ConnectedDevices.Count() > 0)
ConnectionHandle = ConnectedDevices[0];
else
return null;
// Fix report handle under Windows
if (ConnectionHandle is Hid.Win32.Win32DeviceSet)
{
((Hid.Win32.Win32DeviceSet)ConnectionHandle).AddDevice(0x00,
((Hid.Win32.Win32DeviceSet)ConnectionHandle).UnallocatedDevices[0]);
}
return ConnectionHandle;
}
public frmDataloggerSettings()
{
InitializeComponent();
}
private void btnSetValues_Click(object sender, EventArgs e)
{
IDevice ConnectionHandle = GetDeviceConnection();
if (ConnectionHandle == null)
{
MessageBox.Show("Error: Cannot connect to DataLogger device.");
return;
}
Device_Report_t DeviceReport = new Device_Report_t();
DeviceReport.Day = (byte)dtpDate.Value.Day;
DeviceReport.Month = (byte)dtpDate.Value.Month;
DeviceReport.Year = (byte)((dtpDate.Value.Year < 2000) ? 0 : (dtpDate.Value.Year - 2000));
DeviceReport.Hour = (byte)dtpTime.Value.Hour;
DeviceReport.Minute = (byte)dtpTime.Value.Minute;
DeviceReport.Second = (byte)dtpTime.Value.Second;
DeviceReport.LogInterval500MS = (byte)(nudLogInterval.Value * 2);
try
{
ConnectionHandle.Write(0x00, DeviceReport.ToReport());
MessageBox.Show("Device parameters updated sucessfully.");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void btnGetValues_Click(object sender, EventArgs e)
{
IDevice ConnectionHandle = GetDeviceConnection();
if (ConnectionHandle == null)
{
MessageBox.Show("Error: Cannot connect to DataLogger device.");
return;
}
Device_Report_t DeviceReport = new Device_Report_t();
try
{
Byte[] Report = new Byte[7];
ConnectionHandle.Read(0x00, Report);
DeviceReport.FromReport(Report);
try
{
dtpDate.Value = new DateTime(
(2000 + DeviceReport.Year),
DeviceReport.Month,
DeviceReport.Day);
dtpTime.Value = new DateTime(
DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
DeviceReport.Hour,
DeviceReport.Minute,
DeviceReport.Second);
}
catch (Exception ex)
{
dtpDate.Value = DateTime.Now;
dtpTime.Value = DateTime.Now;
}
try
{
nudLogInterval.Value = (DeviceReport.LogInterval500MS / 2);
}
catch (Exception ex)
{
nudLogInterval.Value = nudLogInterval.Minimum;
}
MessageBox.Show("Device parameters retrieved sucessfully.");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void frmDataloggerSettings_Load(object sender, EventArgs e)
{
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Project1HostApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmDataloggerSettings());
}
}
}

View file

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A2D66069-8CF9-4104-828C-49A73D7DB5D1}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TemperatureLoggerHostApp</RootNamespace>
<AssemblyName>TemperatureLoggerHostApp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hid.Net, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Hid.Net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataLoggerSettings.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="DataLoggerSettings.Designer.cs">
<DependentUpon>DataLoggerSettings.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="DataLoggerSettings.resx">
<DependentUpon>DataLoggerSettings.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>