2 using System.Collections.Generic;
 
   3 using System.ComponentModel;
 
   8 using System.Windows.Forms;
 
  11 namespace Project1HostApp
 
  13     public partial class frmDataloggerSettings : Form
 
  15         private const int DEVICE_VID = 0x03EB;
 
  16         private const int DEVICE_PID = 0x2063;
 
  18         private struct Device_Report_t
 
  28             public Byte LogInterval500MS;
 
  30             public Byte[] ToReport()
 
  32                 Byte[] Report = new Byte[7];
 
  35                 Report[1] = this.Month;
 
  36                 Report[2] = this.Year;
 
  37                 Report[3] = this.Hour;
 
  38                 Report[4] = this.Minute;
 
  39                 Report[5] = this.Second;
 
  40                 Report[6] = this.LogInterval500MS;
 
  45             public void FromReport(Byte[] Report)
 
  48                 this.Month = Report[1];
 
  49                 this.Year = Report[2];
 
  50                 this.Hour = Report[3];
 
  51                 this.Minute = Report[4];
 
  52                 this.Second = Report[5];
 
  53                 this.LogInterval500MS = Report[6];
 
  57         private IDevice GetDeviceConnection()
 
  59             IDevice[] ConnectedDevices = DeviceFactory.Enumerate(DEVICE_VID, DEVICE_PID);
 
  60             IDevice ConnectionHandle = null;
 
  62             if (ConnectedDevices.Count() > 0)
 
  63                 ConnectionHandle = ConnectedDevices[0];
 
  67             // Fix report handle under Windows
 
  68             if (ConnectionHandle is Hid.Win32.Win32DeviceSet)
 
  70                 ((Hid.Win32.Win32DeviceSet)ConnectionHandle).AddDevice(0x00,
 
  71                     ((Hid.Win32.Win32DeviceSet)ConnectionHandle).UnallocatedDevices[0]);
 
  74             return ConnectionHandle;
 
  77         public frmDataloggerSettings()
 
  79             InitializeComponent();
 
  82         private void btnSetValues_Click(object sender, EventArgs e)
 
  84             IDevice ConnectionHandle = GetDeviceConnection();
 
  86             if (ConnectionHandle == null)
 
  88                 MessageBox.Show("Error: Cannot connect to Datalogger device.");
 
  92             Device_Report_t DeviceReport = new Device_Report_t();
 
  93             DeviceReport.Day = (byte)dtpDate.Value.Day;
 
  94             DeviceReport.Month = (byte)dtpDate.Value.Month;
 
  95             DeviceReport.Year = (byte)((dtpDate.Value.Year < 2000) ? 0 : (dtpDate.Value.Year - 2000));
 
  96             DeviceReport.Hour = (byte)dtpTime.Value.Hour;
 
  97             DeviceReport.Minute = (byte)dtpTime.Value.Minute;
 
  98             DeviceReport.Second = (byte)dtpTime.Value.Second;
 
  99             DeviceReport.LogInterval500MS = (byte)(nudLogInterval.Value * 2);
 
 103                 ConnectionHandle.Write(0x00, DeviceReport.ToReport());
 
 104                 MessageBox.Show("Device parameters updated successfully.");
 
 108                 MessageBox.Show("Error: " + ex.Message);
 
 112         private void btnGetValues_Click(object sender, EventArgs e)
 
 114             IDevice ConnectionHandle = GetDeviceConnection();
 
 116             if (ConnectionHandle == null)
 
 118                 MessageBox.Show("Error: Cannot connect to Datalogger device.");
 
 122             Device_Report_t DeviceReport = new Device_Report_t();
 
 126                 Byte[] Report = new Byte[7];
 
 128                 ConnectionHandle.Read(0x00, Report);
 
 129                 DeviceReport.FromReport(Report);
 
 133                     dtpDate.Value = new DateTime(
 
 134                         (2000 + DeviceReport.Year),
 
 138                     dtpTime.Value = new DateTime(
 
 139                         DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
 
 142                         DeviceReport.Second);
 
 146                     dtpDate.Value = DateTime.Now;
 
 147                     dtpTime.Value = DateTime.Now;
 
 152                     nudLogInterval.Value = (DeviceReport.LogInterval500MS / 2);
 
 156                     nudLogInterval.Value = nudLogInterval.Minimum;
 
 159                 MessageBox.Show("Device parameters retrieved successfully.");
 
 163                 MessageBox.Show("Error: " + ex.Message);
 
 167         private void frmDataloggerSettings_Load(object sender, EventArgs e)