Attribute VB_Name = "StartProject"
Sub Main()

    'initialize variables
    InitializeVariables

    'Open Device
    Result = sdSearchDevice(DeviceIndex) 'if you connect several devices,for example four devices
                                        'device1    DeviceIndex = 0
                                        'device2    DeviceIndex = 1
                                        'device3    DeviceIndex = 2
                                        'device4    DeviceIndex = 3
                                        '.......    ................
    If Result = 0 Then
        MsgBox ("DSO not found!")
        End
    End If
    
    'Main Form display
    MainForm.Visible = True
    
    'initialize hardware
    Result = sdGetLevel(DeviceIndex, level(0))
    Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, ETS, Controlstate, PulseTrigger, PulseTriggerMode, PulseWidth)
    Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
    Result = sdSetVoltageAndCoupling(DeviceIndex, Ch2Voltage, Ch1Voltage, Ch2_ACDC, Ch1_ACDC, Controlstate)
    Result = sdSetOffset(DeviceIndex, levers, Ch2Voltage, Ch1Voltage, TriggerSource, level(0))
    Result = sdCaptureStart(DeviceIndex)
    Result = sdTriggerEnabled(deivceindex, Controlstate.Timebase)
    
    Initialization = False
    MainForm.GetDataLoop.Enabled = True
End Sub
Public Sub InitializeVariables()
    
    Initialization = True
    DeviceIndex = 0
    Ch1Enabled = True
    Ch2Enabled = True
    Ch1Voltage = 6
    Ch2Voltage = 6
    InterpolationLineMode = 2
    Ch1Position = 128
    Ch2Position = 384
    Ch1TriggerLevel = Ch1Position
    Ch2TriggerLevel = Ch2Position
    ExtTriggerLevel = 256
    TriggerSlope = 0
    TriggerSource = 0
    TriggerPosition = 50
    TriggerMode = 0
    PointOrLine = 1
    StartCapture = 1
    GridOn = True
    XYMode = False
    ScrollMode = 0
    TimeState.ScrollStart = 1
    FFTOn = False
    
    Controlstate.BufferSize = 10
    Controlstate.DataLength = 1
    Controlstate.IsAlt = 0
    Controlstate.SelectedChannel = 2
    Controlstate.Timebase = 13
    Controlstate.TriggerPosition = 50
    Controlstate.TriggerSource = 0
    
    levers.Ch1Position = Ch1Position
    levers.Ch2Position = Ch2Position
    levers.Ch1TriggerLevel = Ch1TriggerLevel
    levers.Ch2TriggerLevel = Ch2TriggerLevel
    levers.ExtTriggerLevel = ExtTriggerLevel
    
    FiltAndTrigger.Ch1Filt = 0
    FiltAndTrigger.Ch2Filt = 0
    FiltAndTrigger.TriggerFilt = 0
    FiltAndTrigger.TriggerMode = 0
    FiltAndTrigger.TriggerSlope = 0
    
    AutosetData.Ch1Enabled = 1
    AutosetData.Ch2Enabled = 1
    AutosetData.Ch1InGND = 0
    AutosetData.Ch2InGND = 0
    
    Ch1_ACDC = 1
    Ch2_ACDC = 1
    
    CH1_color.R = 0
    CH1_color.G = 255
    CH1_color.B = 0
    CH2_color.R = 255
    CH2_color.G = 255
    CH2_color.B = 0
    
    PulseWidth = 2
    PulseTriggerMode = 0
    PulseTrigger = 0
    ETS = 0
    
End Sub
