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 = sdInitLevelRange(DeviceIndex)
    Result = sdGetChannelLevel(DeviceIndex, level(0), 62)
    Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate, FiltAndTrigger.TriggerFilt)
    Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
    Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)
    Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
    
    Result = sdCaptureStart(DeviceIndex)
    Result = sdGetDataSleep(Controlstate)
    Result = sdTriggerEnabled(DeviceIndex)
    Initialization = False
    MainForm.GetDataLoop.Enabled = True
    
End Sub
Public Sub InitializeVariables()
    
    Initialization = True
    DeviceIndex = 0
    Ch1Enabled = True
    Ch2Enabled = True
    Ch1Voltage = 6
    Ch2Voltage = 6
    InterpolationLineMode = 1
    Ch1Position = 64
    Ch2Position = 192
    Ch1TriggerLevel = 64
    Ch2TriggerLevel = 192
    ExtTriggerLevel = 128
    TriggerSlope = 0
    TriggerSource = 0
    TriggerPosition = 50
    TriggerMode = 0
    PointOrLine = 1
    StartCapture = 1
    GridOn = True
    XYMode = False
    ScrollMode = 0
    TimeState.ScrollStart = 0
    FFTOn = False
    
    Controlstate.BufferSize = 10
    Controlstate.IsAlt = 0
    Controlstate.SelectedChannel = 2
    Controlstate.TIMEBASE = 12
    Controlstate.TriggerPosition = 50
    Controlstate.TriggerSource = 0
    
    levers.Ch1Position = 64
    levers.Ch2Position = 192
    levers.Ch1TriggerLevel = 64
    levers.Ch2TriggerLevel = 192
    levers.ExtTriggerLevel = 128
    
    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
    
    
End Sub
