Public Class MainForm
    Dim flag As Boolean = False 'flag du sélecteur 2 positions
    Dim valeur As String
    Dim result As Integer
    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        

        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    '***************************************************************
    '* .NET does not close hidden forms, so do it here
    '* to make sure forms are disposed and drivers close
    '***************************************************************
    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim index As Integer
        ModbusTCPCom1.Write(40021, 0) 'STOP the system when close main form
        While index < My.Application.OpenForms.Count
            If My.Application.OpenForms(index) IsNot Me Then

                My.Application.OpenForms(index).Close()
            End If
            index += 1
        End While
    End Sub
    Private Sub SelectorSwitch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectorSwitch.Click
        'pour un mode toggle avec des sémaphores
        If (flag) Then
            SelectorSwitch.BackgroundImage = My.Resources.ResourceManager.GetObject("btDROIT")
            ModbusTCPCom1.Write(40051, 0)
            flag = False
        Else
            SelectorSwitch.BackgroundImage = My.Resources.ResourceManager.GetObject("btGAUCHE")
            ModbusTCPCom1.Write(40051, 1)
            flag = True
        End If
    End Sub
    Private Sub Button1_MouseUp(sender As Object, e As EventArgs) Handles Button1.MouseUp
        Button1.BackgroundImage = My.Resources.ResourceManager.GetObject("bpjaune")
        ModbusTCPCom1.Write(40031, 0)
    End Sub

    Private Sub Button1_MouseDown(sender As Object, e As EventArgs) Handles Button1.MouseDown
        Button1.BackgroundImage = My.Resources.ResourceManager.GetObject("bpjauneON")
        ModbusTCPCom1.Write(40031, 1)
    End Sub

    Private Sub PilotLight4_ValueChanged(sender As Object, e As EventArgs) Handles PilotLight4.ValueChanged

        If PilotLight4.Value = "1" Then
            PictureBox1.BackgroundImage = My.Resources.ResourceManager.GetObject("VbleuON")
        Else
            PictureBox1.BackgroundImage = My.Resources.ResourceManager.GetObject("VbleuOFF")
        End If
    End Sub

    Private Sub SquareIlluminatedButton1_Invalidated(sender As Object, e As EventArgs) Handles SquareIlluminatedButton1.Invalidated
        valeur = ModbusTCPCom1.Read(40131)
        DigitalPanelMeterBlue1.Value = valeur
        valeur = ModbusTCPCom1.Read(40141)
        DigitalPanelMeterBlue2.Value = valeur

    End Sub
    ' Private Sub Form_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    ' valeur = ModbusTCPCom1.Read(40092)
    ' DigitalPanelMeterBlue1.Value = valeur
    ' End Sub

    
    Private Sub DigitalPanelMeterBlue1_Click(sender As Object, e As EventArgs) Handles DigitalPanelMeterBlue1.Click

    End Sub

    Private Sub Meter21_Click(sender As Object, e As EventArgs) Handles Meter21.Click

    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub PilotLight1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub PilotLight4_Click(sender As Object, e As EventArgs) Handles PilotLight4.Click

    End Sub
End Class