' ================================================================================================ ' Questo Logger trasforma i valori dei sensori in: Indice UV, Temperature, Volt e Millivolt ' I sensori attualmente implementati sono: ' - Modulo UV 7300-UVM-30A ' - Modulo UV ML8511 ' - Sensore temperatura LM35 ' - Sensore temperatura TSIC501 ' ================================================================================================ ' ================================================================================================ ' CONFIGURAZIONE - MODIFICARE PER PERSONALIZZARE IL FUNZIONAMENTO ' ================================================================================================ Dim FileName As String = "LOG.csv" ' Nome del file (può essere un file "txt" o "csv") Dim TimerSeconds As Single = 0.1 ' Intervallo di LOG (per esempio 0.1 significa 10 per secondo) ' Il numero di canali è determinato dal numero di SensorSlot che si scrivono tra le parentesi ' Ci devono essere lo stesso numero di SensorSlot, SensorType e SensorTrim ' ora sono sei, ma si possono aumentare di numero o ridurre anche a uno solo. ' Lo Slot può essere lo stesso anche per più canali ' In questo modo è possibile registrare più colonne per lo stesso sensore ' anche in formati diversi, ad esempio sia Temperatura che Millivolt Dim SensorSlot() As Int32 = {1, 2, 3, 4, 5, 6} ' Il tipo di può essere: "UV", "LM35", "TSIC501", "Volt", "Millivolt" o "" ' Un SensorType = "" significa di loggare il valore grezzo (da 0 a 1000) Dim SensorType() As String = {"UV", "", "" , "Volt", "LM35", "TSIC501"} ' Per ciascun sensore il valore calcolato (Indice UV, Temperatura o Tensione) ' può essere tarato con precisione, aggiungendogli un numero positivo o negativo. Dim SensorTrim() As Single = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00} ' Per ciascun sensore il valore calcolato (Indice UV, Temperatura o Tensione) ' può essere tarato con maggiore precisione, moltiplicandolo per un numero maggiore o minore di uno. Dim SensorMultiplier() As Single = {1.20, 1.00, 1.00, 1.00, 1.00, 1.00} ' ================================================================================================ ' FUNZIONI DI TEMPORIZZAZIONE, SALVATAGGIO DEL FILE E CONVERSIONE VALORI ' ================================================================================================ 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)) ' --------------------------------------------------- A seconda del tipo... Select Case SensorType(SensorIndex) Case "UV" ' ------------------------------------------- Indice UV (da 0 a 11) con modulo 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 da 0 a 15 mW/cmq con modulo ML8511 v = v * 3.3f v = v - 1000 ' sottraggo un volt (vedere grafico) v = v * 15 / 1.8f ' riporto gli 1.8 volt (range da 1 Volt a 2.8 Volt) v = v / 1000 ' in mW/cmq da 0 a 15 Case "Volt" ' ------------------------------------------- Volt da 0 a 3.3 v = v * 3.3f / 1000 Case "Millivolt" ' ------------------------------------------- Millivolt da 0 a 3300 v = v * 3.3f Case "LM35" ' ------------------------------------------- Temperatura in gradi centigradi v = v * 0.33f Case "TSIC501" ' ------------------------------------------- Temperatura in gradi centigradi v = v / 333 * (60 - 10) - 10 Case "" ' ------------------------------------------- Valore da 0.1000 non convertito ' End Select ' --------------------------------------------------- Qui si applica il valore di taratura 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