'Programme de démonstration du module TC/USB-48IO VB.NET 2010 Express
'V1.0 : 04/11/2014: 3CC-DB : Release

Public Class FrmTCUSB48IO
    Dim D_output As UInt16 = 0
    Dim err As Integer = 0
    Dim ModuleOpened As Boolean = False
    Private Sub buttonOpen_Click(sender As System.Object, e As System.EventArgs) Handles buttonOpen.Click
        Dim NumeroSeries As UInteger = 0
        Dim Num As Integer = 1
        Dim DllVersion As Byte = 0
        Dim FwVersion As Byte = 0
        NumeroSeries = CType(TextBoxSN.Text, UInteger)

        'ouverture du module
        err = TCUSB48IO.TCUSB48IO_OpenN(Num, NumeroSeries)

        If (err = 0) Then

            ModuleOpened = True
            TextBoxSN.Text = NumeroSeries.ToString("00000000")
            'Actualisation des données du module
            TCUSB48IO.TCUSB48IO_Refresh(1)
            timer1.Enabled = True
            buttonOpen.Enabled = False

        Else
            ModuleOpened = False
            If (err = 1) Then MessageBox.Show("Numero de serie incorrect")
            If (err = 2) Then MessageBox.Show("N° de module incorrect")
            If (err = 3) Then MessageBox.Show("Pas de module TC/USB-48IO détecté")
            If (err = 4) Then MessageBox.Show("Module non initialisé")
            Close()
        End If
    End Sub

    Private Sub Btn_S1_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S1.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H1)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S1.BackColor = Color.Lime) Then
            Btn_S1.BackColor = Color.Green
        Else
            Btn_S1.BackColor = Color.Lime
        End If
    End Sub

    Private Sub Btn_S2_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S2.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H2)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S2.BackColor = Color.Lime) Then
            Btn_S2.BackColor = Color.Green
        Else
            Btn_S2.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S3_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S3.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H4)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S3.BackColor = Color.Lime) Then
            Btn_S3.BackColor = Color.Green
        Else
            Btn_S3.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S4_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S4.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H8)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S4.BackColor = Color.Lime) Then
            Btn_S4.BackColor = Color.Green
        Else
            Btn_S4.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S5_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S5.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H10)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S5.BackColor = Color.Lime) Then
            Btn_S5.BackColor = Color.Green
        Else
            Btn_S5.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S6_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S6.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H20)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S6.BackColor = Color.Lime) Then
            Btn_S6.BackColor = Color.Green
        Else
            Btn_S6.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S7_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S7.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H40)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S7.BackColor = Color.Lime) Then
            Btn_S7.BackColor = Color.Green
        Else
            Btn_S7.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S8_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S8.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H80)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S8.BackColor = Color.Lime) Then
            Btn_S8.BackColor = Color.Green
        Else
            Btn_S8.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S9_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S9.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H100)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S9.BackColor = Color.Lime) Then
            Btn_S9.BackColor = Color.Green
        Else
            Btn_S9.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S10_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S10.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H200)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S10.BackColor = Color.Lime) Then
            Btn_S10.BackColor = Color.Green
        Else
            Btn_S10.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S11_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S11.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H400)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S11.BackColor = Color.Lime) Then
            Btn_S11.BackColor = Color.Green
        Else
            Btn_S11.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S12_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S12.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H800)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S12.BackColor = Color.Lime) Then
            Btn_S12.BackColor = Color.Green
        Else
            Btn_S12.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S13_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S13.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H1000)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S13.BackColor = Color.Lime) Then
            Btn_S13.BackColor = Color.Green
        Else
            Btn_S13.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S14_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S14.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H2000)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S14.BackColor = Color.Lime) Then
            Btn_S14.BackColor = Color.Green
        Else
            Btn_S14.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S15_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S15.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H4000)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S15.BackColor = Color.Lime) Then
            Btn_S15.BackColor = Color.Green
        Else
            Btn_S15.BackColor = Color.Lime
        End If

    End Sub

    Private Sub Btn_S16_Click(sender As System.Object, e As System.EventArgs) Handles Btn_S16.Click
        D_output = System.Convert.ToUInt16(D_output Xor &H8000)
        err = TCUSB48IO.TCUSB48IO_Output(1, D_output)
        TCUSB48IO.TCUSB48IO_Refresh(1)
        If (Btn_S16.BackColor = Color.Lime) Then
            Btn_S16.BackColor = Color.Green
        Else
            Btn_S16.BackColor = Color.Lime
        End If

    End Sub

    Private Sub timer1_Tick(sender As System.Object, e As System.EventArgs) Handles timer1.Tick
        Dim D_input As UInt32 = 0
        Dim D_Temp As Byte = 0

        TCUSB48IO.TCUSB48IO_Refresh(1)
        TCUSB48IO.TCUSB48IO_Input(1, D_input)

        TCUSB48IO.TCUSB48IO_Counter(1, 1, D_Temp)
        Txt_E1.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 2, D_Temp)
        Txt_E2.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 3, D_Temp)
        Txt_E3.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 4, D_Temp)
        Txt_E4.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 5, D_Temp)
        Txt_E5.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 6, D_Temp)
        Txt_E6.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 7, D_Temp)
        Txt_E7.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 8, D_Temp)
        Txt_E8.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 9, D_Temp)
        Txt_E9.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 10, D_Temp)
        Txt_E10.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 11, D_Temp)
        Txt_E11.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 12, D_Temp)
        Txt_E12.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 13, D_Temp)
        Txt_E13.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 14, D_Temp)
        Txt_E14.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 15, D_Temp)
        Txt_E15.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 16, D_Temp)
        Txt_E16.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 17, D_Temp)
        Txt_E17.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 18, D_Temp)
        Txt_E18.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 19, D_Temp)
        Txt_E19.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 20, D_Temp)
        Txt_E20.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 21, D_Temp)
        Txt_E21.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 22, D_Temp)
        Txt_E22.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 23, D_Temp)
        Txt_E23.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 24, D_Temp)
        Txt_E24.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 25, D_Temp)
        Txt_E25.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 26, D_Temp)
        Txt_E26.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 27, D_Temp)
        Txt_E27.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 28, D_Temp)
        Txt_E28.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 29, D_Temp)
        Txt_E29.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 30, D_Temp)
        Txt_E30.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 31, D_Temp)
        Txt_E31.Text = System.Convert.ToString(D_Temp)
        TCUSB48IO.TCUSB48IO_Counter(1, 32, D_Temp)
        Txt_E32.Text = System.Convert.ToString(D_Temp)

        If ((D_input And &H1) > 0) Then Btn_E1.BackColor = Color.Lime Else Btn_E1.BackColor = Color.Green
        If ((D_input And &H2) > 0) Then Btn_E2.BackColor = Color.Lime Else Btn_E2.BackColor = Color.Green
        If ((D_input And &H4) > 0) Then Btn_E3.BackColor = Color.Lime Else Btn_E3.BackColor = Color.Green
        If ((D_input And &H8) > 0) Then Btn_E4.BackColor = Color.Lime Else Btn_E4.BackColor = Color.Green
        If ((D_input And &H10) > 0) Then Btn_E5.BackColor = Color.Lime Else Btn_E5.BackColor = Color.Green
        If ((D_input And &H20) > 0) Then Btn_E6.BackColor = Color.Lime Else Btn_E6.BackColor = Color.Green
        If ((D_input And &H40) > 0) Then Btn_E7.BackColor = Color.Lime Else Btn_E7.BackColor = Color.Green
        If ((D_input And &H80) > 0) Then Btn_E8.BackColor = Color.Lime Else Btn_E8.BackColor = Color.Green

        If ((D_input And &H100) > 0) Then Btn_E9.BackColor = Color.Lime Else Btn_E9.BackColor = Color.Green
        If ((D_input And &H200) > 0) Then Btn_E10.BackColor = Color.Lime Else Btn_E10.BackColor = Color.Green
        If ((D_input And &H400) > 0) Then Btn_E11.BackColor = Color.Lime Else Btn_E11.BackColor = Color.Green
        If ((D_input And &H800) > 0) Then Btn_E12.BackColor = Color.Lime Else Btn_E12.BackColor = Color.Green
        If ((D_input And &H1000) > 0) Then Btn_E13.BackColor = Color.Lime Else Btn_E13.BackColor = Color.Green
        If ((D_input And &H2000) > 0) Then Btn_E14.BackColor = Color.Lime Else Btn_E14.BackColor = Color.Green
        If ((D_input And &H4000) > 0) Then Btn_E15.BackColor = Color.Lime Else Btn_E15.BackColor = Color.Green
        If ((D_input And &H8000) > 0) Then Btn_E16.BackColor = Color.Lime Else Btn_E16.BackColor = Color.Green

        If ((D_input And &H10000) > 0) Then Btn_E17.BackColor = Color.Lime Else Btn_E17.BackColor = Color.Green
        If ((D_input And &H20000) > 0) Then Btn_E18.BackColor = Color.Lime Else Btn_E18.BackColor = Color.Green
        If ((D_input And &H40000) > 0) Then Btn_E19.BackColor = Color.Lime Else Btn_E19.BackColor = Color.Green
        If ((D_input And &H80000) > 0) Then Btn_E20.BackColor = Color.Lime Else Btn_E20.BackColor = Color.Green
        If ((D_input And &H100000) > 0) Then Btn_E21.BackColor = Color.Lime Else Btn_E21.BackColor = Color.Green
        If ((D_input And &H200000) > 0) Then Btn_E22.BackColor = Color.Lime Else Btn_E22.BackColor = Color.Green
        If ((D_input And &H400000) > 0) Then Btn_E23.BackColor = Color.Lime Else Btn_E23.BackColor = Color.Green
        If ((D_input And &H800000) > 0) Then Btn_E24.BackColor = Color.Lime Else Btn_E24.BackColor = Color.Green

        If ((D_input And &H1000000) > 0) Then Btn_E25.BackColor = Color.Lime Else Btn_E25.BackColor = Color.Green
        If ((D_input And &H2000000) > 0) Then Btn_E26.BackColor = Color.Lime Else Btn_E26.BackColor = Color.Green
        If ((D_input And &H4000000) > 0) Then Btn_E27.BackColor = Color.Lime Else Btn_E27.BackColor = Color.Green
        If ((D_input And &H8000000) > 0) Then Btn_E28.BackColor = Color.Lime Else Btn_E28.BackColor = Color.Green
        If ((D_input And &H10000000) > 0) Then Btn_E29.BackColor = Color.Lime Else Btn_E29.BackColor = Color.Green
        If ((D_input And &H20000000) > 0) Then Btn_E30.BackColor = Color.Lime Else Btn_E30.BackColor = Color.Green
        If ((D_input And &H40000000) > 0) Then Btn_E31.BackColor = Color.Lime Else Btn_E31.BackColor = Color.Green
        If ((D_input And &H80000000) > 0) Then Btn_E32.BackColor = Color.Lime Else Btn_E32.BackColor = Color.Green

    End Sub
End Class
