Generator.vb

' Generator.vb
'
' This example generates a 100 kHz triangle waveform, 4 Vpp.
'
' Find more information on http://www.tiepie.com/LibTiePie .

Imports System
Imports TiePie.LibTiePie

Module GeneratorExample

    Sub Main()
        ' Print library information:
        PrintLibraryInfo()

        ' Enable network search:
        Network.AutoDetectEnabled = True

        ' Update device list:
        DeviceList.Update()

        ' Try to open a generator:
        Dim gen As Generator = Nothing

        If DeviceList.Count <> 0 Then
            For i As UInt32 = 0 To DeviceList.Count - 1
                Dim item As DeviceListItem = DeviceList.GetItemByIndex(i)
                If item.CanOpen(DeviceType.Generator) Then
                    gen = item.OpenGenerator()
                    Exit For
                End If
            Next
        End If

        If Not IsNothing(gen) Then
            Try
                ' Set signal type:
                gen.SignalType = SignalType.Triangle

                ' Set frequency:
                gen.Frequency = 100000.0  ' 100 kHz

                ' Set amplitude:
                gen.Amplitude = 2.0 ' 2 V

                ' Set offset:
                gen.Offset = 0.0 ' 0 V

                ' Enable output:
                gen.OutputOn = True

                ' Print Generator info:
                PrintDeviceInfo(gen)

                ' Start signal generation
                gen.Start()

                ' Wait for keystroke:
                Console.WriteLine("Press Enter to stop signal generation...")
                Console.ReadLine()

                ' Stop generator:
                gen.Stop()

                ' Disable output:
                gen.OutputOn = False

            Catch e As System.Exception
                Console.WriteLine("Exception: " + e.Message)
                Environment.Exit(1)
            End Try

            ' Close generator:
            gen.Dispose()
            gen = Nothing
        Else
            Console.WriteLine("No generator available!")
            Environment.Exit(1)
        End If

        Environment.Exit(0)
    End Sub

End Module