' GeneratorGatedBurst.vb
'
' This example generates a 100 kHz square waveform, 25% duty cycle, 0..5 V, 20 periods, this waveform is triggered by the external trigger.
' Connect the external trigger to GND to trigger the burst.
'
' Find more information on http://www.tiepie.com/LibTiePie .
Imports System
Imports TiePie.LibTiePie
Module GeneratorGatedBurstExample
Sub Main()
' Print library information:
PrintLibraryInfo()
' Enable network search:
Network.AutoDetectEnabled = True
' Update device list:
DeviceList.Update()
' Try to open a generator with gated burst support:
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()
' Check for gated burst support:
If (gen.ModesNative And Constants.GM_GATED_PERIODS) <> 0 And gen.TriggerInputs.Count > 0 Then
Exit For
Else
gen.Dispose()
gen = Nothing
End If
End If
Next
End If
If Not IsNothing(gen) Then
Try
' Set signal type:
gen.SignalType = SignalType.Square
' Set frequency:
gen.Frequency = 10000.0 ' 10 kHz
' Set amplitude:
gen.Amplitude = 5.0 ' 5 V
' Set offset:
gen.Offset = 0.0 ' 0 V
' Set mode:
gen.Mode = GeneratorMode.BurstCount
' Locate trigger input:
Dim triggerInput As TriggerInput = gen.TriggerInputs.GetById(Constants.TIID_EXT1)
If (IsNothing(triggerInput)) Then
triggerInput = gen.TriggerInputs.GetById(Constants.TIID_EXT2)
End If
If (IsNothing(triggerInput)) Then
Throw New System.Exception("Unknown trigger input!")
End If
' Enable trigger input:
triggerInput.Enabled = True
' 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 with gated burst support!")
Environment.Exit(1)
End If
Environment.Exit(0)
End Sub
End Module