' ================================================================================================ ' Theremino System SLOTS operations - LED BLINK ' ================================================================================================ ' ------------------------------------------------------------------------------------------------ ' This function is executed in a separate Thread - Do here slow and paused operations ' Questa funzione e' eseguita in un thread separato - Far qui le operazioni lente o con pause ' ------------------------------------------------------------------------------------------------ Sub PausableExecution() dim n as single = ReadSlot(1) if n > 0 and n < 250 then WriteSlot(2, 1000) WriteSlot(3, 0) WriteSlot(4, 0) WriteSlot(5, 0) else if n >= 250 and n < 500 then WriteSlot(2, 0) WriteSlot(3, 1000) WriteSlot(4, 0) WriteSlot(5, 0) else if n >= 500 and n < 750 then WriteSlot(2, 0) WriteSlot(3, 0) WriteSlot(4, 1000) WriteSlot(5, 0) else if n > 750 and n < 1000 then WriteSlot(2, 0) WriteSlot(3, 0) WriteSlot(4, 0) WriteSlot(5, 1000) end if Label1.Text = "Slot1 = " + n.ToString() End Sub ' ------------------------------------------------------------------------------------------------ ' This function is executed 20 times per second (no pauses here or the whole program is locked) ' Funzione eseguita 20 volte al sec. ( niente pause qui altrimenti tutto il programma si blocca) ' ------------------------------------------------------------------------------------------------ Sub FastExecution ' ---------------- questo esempio copia continuamente il valore dello slot 2 nello slot 3 ' WriteSlot(3, ReadSlot(2)) ' ---------------- questo esempio copia il valore "invertito" dello slot 2 nello slot 3 ' WriteSlot(3, 1000 - ReadSlot(2)) End Sub ' ------------------------------------------------------------------------------------------------ ' Functions called from user controls events ' Queste funzioni vengono chiamate dagli eventi causati dai controlli utente ' ------------------------------------------------------------------------------------------------ Sub TrackBar1_Scroll(value As Single) Label2.Text = "E' stato mosso il cursore, il suo valore e': " & value.ToString("0") WriteSlot(1, value) End Sub ' ================================================================================================ ' - ENG - THE SIMPLIFIED MANAGEMENT ENDS HERE - 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 StartThread 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 objThread.Abort End Sub Sub StartThread() ' --------------------------------------------------------- asynchronously start the Thread objThread = New Threading.Thread(AddressOf ExecuteThread) ' --------------------------------------------------------- make the thread as background thread. objThread.IsBackground = True ' --------------------------------------------------------- set the Priority of the thread. objThread.Priority = Threading.ThreadPriority.AboveNormal ' --------------------------------------------------------- start the thread. objThread.Start() End Sub Sub ExecuteThread Do PausableExecution PausaMS(1) loop until false End Sub Sub PausaMS(Byval mS As Int32) Threading.Thread.Sleep(mS) End Sub Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick FastExecution End Sub ' ---------------------------------------------------------------------- User Interface Components WithEvents Form1 As Form WithEvents Timer1 As Timer = New Timer Dim objThread As Threading.Thread Dim Label1 As Label = new Label Dim Label2 As Label = new Label WithEvents TrackBar1 As TrackBar = new TrackBar Sub InitializeComponents() Application.EnableVisualStyles form1.SuspendLayout ' ------------------------------------------------------------------ Form Form1.Text = "Theremino Script - Led Meter" Form1.ClientSize = New System.Drawing.Size(640, 70) Form1.MinimumSize = Form1.Size Form1.StartPosition = FormStartPosition.CenterScreen ' ------------------------------------------------------------------ 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) ' ------------------------------------------------------------------ Label 2 Label2.BorderStyle = BorderStyle.Fixed3D Label2.Location = New Point(10, 40) Label2.Font = New Font("Arial", 12 ) Label2.Size = New Size(620, 21) Label2.Anchor = AnchorStyles.top or AnchorStyles.Left or AnchorStyles.right Form1.Controls.Add(Label2) ' ------------------------------------------------------------------ Timer 1 Timer1.Interval = 50 Timer1.Start ' ------------------------------------------------------------------ Form1.ResumeLayout Form1.PerformLayout() Form1.show End Sub