' ================================================================================================ ' This Logger translates sensor values to UV-Index, Temperatures, Volts and Millivolts ' Supported sensors are: ' - UV module 7300-UVM-30A ' - Modulo UV ML8511 ' - Temperature LM35 ' - Temperature TSIC501 ' ================================================================================================ ' ================================================================================================ ' CONFIGURATION START - CHANGE THIS AREA TO PERSONALIZE THE LOG ' ================================================================================================ Dim FileName As String = "LOG.csv" ' File Name (can be a txt or csv file) Dim TimerSeconds As Single = 0.1 ' Log interval (for example 0.1 means 10 times per second) ' The number of channels is equal to the number of SensorSlot written inside parenthesis ' SensorSlots, SensorTypes e SensorTrims must be the same number ' now they are six, but can be increased or reduced, even to a single channel. ' Il numero di Slot può essere lo stesso anche per più canali ' So it is possiblre to record different columns for the same sensor ' also in different formats, for example both Temperature and Millivolt Dim SensorSlot() As Int32 = {1, 2, 3, 4, 5, 6} ' The SensorTypes can be: "UV", "LM35", "TSIC501", "Volt" or Millivolts ' A SensorType = "" means To log 0..1000 value Dim SensorType() As String = {"UV", "", "" , "Volt", "LM35", "TSIC501"} ' For each sensor the calculated value can be trimmed with following values Dim SensorTrim() As Single = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00} ' For each sensor the calculated value (UV, Temperature or Voltage) ' can be moltiplied by a number slighly more or less then one. Dim SensorMultiplier() As Single = {1.20, 1.00, 1.00, 1.00, 1.00, 1.00} ' ================================================================================================ ' CONFIGURATION END ' ================================================================================================ Sub Initialize Timer1.Interval = CInt(TimerSeconds * 1000) End Sub Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Dim file As System.IO.StreamWriter file = My.Computer.FileSystem.OpenTextFileWriter(FileName, True, New System.Text.ASCIIEncoding()) Dim s As String 's = Replace(Date.Now.tostring, ".", ":") & Date.Now.Milliseconds.ToString s = Date.Now.tostring("yyyy/MM/dd HH:mm:ss.ff", Globalization.CultureInfo.InvariantCulture) For i As Int32 = 0 To SensorSlot.Length - 1 s &= "," & ConvertSensorValue(i).ToString("0.000", Globalization.CultureInfo.InvariantCulture) Next Label1.Text = s file.WriteLine(s) file.Close() End Sub Function ConvertSensorValue(ByVal SensorIndex As Int32) As Single Dim v As Single = ReadSlot(SensorSlot(SensorIndex)) Select Case SensorType(SensorIndex) Case "UV" ' --------------------------------------- UV index (0 to 11) with module 7300-UVM-30A v = v * 3.3f If v < 227 Then v = v / 227 Else v = 1 + 10 * (v - 227) / (1170 - 227) End If Case "ML" ' ------------------------------------------- UV from 0 a 15 mW/cmq with module ML8511 v = v * 3.3f v = v - 1000 ' subtract 1 Volt (see data sheet) v = v * 15 / 1.8f ' remaining 1.8 volt (range from 1 Volt to 2.8 Volt) v = v / 1000 ' to mW/cmq from 0 to 15 Case "Volt" ' --------------------------------------- Volt from 0 to 3.3 v = v * 3.3f / 1000 Case "Millivolt" ' --------------------------------------- Millivolt from 0 to 3300 v = v * 3.3f Case "LM35" ' --------------------------------------- Temperature in centigrade degree v = v * 0.33f Case "TSIC501" ' --------------------------------------- Temperature in centigrade degree v = v / 333 * (60 - 10) - 10 Case Else ' --------------------------------------- Unconverted 0.1000 value Return v End Select ' ----------------------------------------------- Here trimming and multiplere are applied v = v + SensorTrim(SensorIndex) v = v * SensorMultiplier(SensorIndex) Return v End Function ' ================================================================================================ ' - ENG - THE SIMPLIFIED MANAGEMENT ENDS HER - MODIFY THE FOLLOWING CAREFULLY ' ------------------------------------------------------------------------------------------------ ' - ITA - LA GESTIONE SEMPLIFICATA FINISCE QUI - MODIFICARE LA PARTE SEGUENTE CON ATTENZIONE ' ================================================================================================ Sub Main(ByVal s() As String) If Form1 IsNot Nothing Then Return Form1 = New Form InitializeComponents MemoryMappedFile_Init Initialize While Form1.Visible Application.DoEvents Threading.Thread.Sleep(10) End While End Sub Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Form1.Closing Timer1.Stop End Sub ' ---------------------------------------------------------------------- User Interface Components WithEvents Form1 As Form WithEvents Timer1 As Timer = New Timer Dim Label1 As Label = New Label Sub InitializeComponents() Application.EnableVisualStyles form1.SuspendLayout ' ------------------------------------------------------------------ Form Form1.Text = "Theremino Script - Data Logger" Form1.StartPosition = FormStartPosition.Manual Form1.ClientSize = New System.Drawing.Size(640, 40) Form1.MinimumSize = Form1.Size Form1.MaximizeBox = False Form1.FormBorderStyle = FormBorderStyle.Fixed3D ' ------------------------------------------------------------------ Label 1 Label1.BorderStyle = BorderStyle.Fixed3D Label1.Location = New Point(10, 10) Label1.Font = New Font("Arial", 12 ) Label1.Size = New Size(620, 21) Label1.Anchor = AnchorStyles.top Or AnchorStyles.Left Or AnchorStyles.right Form1.Controls.Add(Label1) ' ------------------------------------------------------------------ Timer 1 Timer1.Interval = 100 Timer1.Start ' ------------------------------------------------------------------ Form1.ResumeLayout Form1.PerformLayout() Form1.show End Sub