VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form MainForm 
   AutoRedraw      =   -1  'True
   Caption         =   "P-1175 USB Second Design"
   ClientHeight    =   9075
   ClientLeft      =   1110
   ClientTop       =   1755
   ClientWidth     =   7725
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   9
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H00FF8080&
   Icon            =   "MainForm.frx":0000
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   605
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   515
   Visible         =   0   'False
   Begin VB.Frame ControlPanel 
      Height          =   2655
      Left            =   0
      TabIndex        =   3
      Top             =   6120
      Width           =   7740
      Begin VB.CommandButton cmdAutoSet 
         Caption         =   "AutoSet"
         Height          =   350
         Left            =   5280
         TabIndex        =   43
         Top             =   1920
         Width           =   855
      End
      Begin VB.CommandButton cmdStop 
         Caption         =   "Stop"
         Height          =   350
         Left            =   6720
         TabIndex        =   42
         Top             =   2200
         Width           =   855
      End
      Begin VB.CommandButton cmdStart 
         Caption         =   "Start"
         Height          =   350
         Left            =   6720
         TabIndex        =   41
         Top             =   1800
         Width           =   855
      End
      Begin VB.ComboBox cboTriggerMode 
         BackColor       =   &H80000006&
         ForeColor       =   &H00FF00FF&
         Height          =   345
         Left            =   1440
         Style           =   2  'Dropdown List
         TabIndex        =   40
         Top             =   2160
         Width           =   975
      End
      Begin VB.CommandButton cmdEXTTriggerLevel 
         Caption         =   "OK"
         Height          =   330
         Left            =   4320
         TabIndex        =   38
         Top             =   2160
         Width           =   615
      End
      Begin VB.CommandButton cmdIncrease 
         BeginProperty Font 
            Name            =   "ËÎÌå"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   4250
         MaskColor       =   &H80000000&
         Picture         =   "MainForm.frx":0CCA
         Style           =   1  'Graphical
         TabIndex        =   37
         Top             =   1440
         Width           =   330
      End
      Begin VB.CommandButton cmdDecrease 
         BeginProperty Font 
            Name            =   "ËÎÌå"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   3120
         Picture         =   "MainForm.frx":1054
         Style           =   1  'Graphical
         TabIndex        =   36
         Top             =   1440
         Width           =   330
      End
      Begin VB.Frame Ch2Panel 
         Height          =   1500
         Left            =   4600
         TabIndex        =   23
         Top             =   240
         Width           =   3015
         Begin VB.CommandButton cmdCh2Coupling 
            Caption         =   "AC"
            Height          =   300
            Left            =   2310
            TabIndex        =   45
            Top             =   380
            Width           =   645
         End
         Begin VB.CommandButton cmdCh2TriggerLevel 
            Caption         =   "OK"
            Height          =   330
            Left            =   2280
            TabIndex        =   35
            Top             =   1080
            Width           =   615
         End
         Begin VB.CommandButton cmdCh2Position 
            Caption         =   "OK"
            Height          =   330
            Left            =   2280
            TabIndex        =   34
            Top             =   720
            Width           =   615
         End
         Begin VB.ComboBox cboCh2Voltage 
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FFFF&
            Height          =   345
            Left            =   1320
            Style           =   2  'Dropdown List
            TabIndex        =   27
            Top             =   340
            Width           =   975
         End
         Begin VB.TextBox txtCh2Position 
            Alignment       =   2  'Center
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FFFF&
            Height          =   330
            Left            =   1320
            TabIndex        =   26
            Top             =   720
            Width           =   855
         End
         Begin VB.TextBox txtCh2TriggerLevel 
            Alignment       =   2  'Center
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FFFF&
            Height          =   330
            Left            =   1320
            TabIndex        =   25
            Top             =   1080
            Width           =   855
         End
         Begin VB.CheckBox cekCh2 
            Caption         =   "Check1"
            Height          =   255
            Left            =   1200
            TabIndex        =   24
            Top             =   0
            Width           =   255
         End
         Begin VB.Label lblChannel2 
            Caption         =   "CH2"
            Height          =   255
            Left            =   1440
            TabIndex        =   31
            Top             =   0
            Width           =   375
         End
         Begin VB.Label lblCh2Voltage 
            Caption         =   "CH2 Voltage"
            Height          =   255
            Left            =   120
            TabIndex        =   30
            Top             =   360
            Width           =   1095
         End
         Begin VB.Label lblCh2Position 
            Caption         =   "CH2 Position"
            Height          =   255
            Left            =   120
            TabIndex        =   29
            Top             =   750
            Width           =   1095
         End
         Begin VB.Label lblCH2TriggerLevel 
            Caption         =   "Trigger Level"
            Height          =   255
            Left            =   120
            TabIndex        =   28
            Top             =   1100
            Width           =   1095
         End
      End
      Begin VB.Frame Ch1Panel 
         Height          =   1500
         Left            =   80
         TabIndex        =   14
         Top             =   240
         Width           =   3015
         Begin VB.CommandButton cmdCh1Coupling 
            Caption         =   "AC"
            Height          =   300
            Left            =   2310
            TabIndex        =   44
            Top             =   380
            Width           =   645
         End
         Begin VB.CommandButton cmdCh1TriggerLevel 
            Caption         =   "OK"
            Height          =   330
            Left            =   2280
            TabIndex        =   33
            Top             =   1080
            Width           =   615
         End
         Begin VB.CommandButton cmdCh1Position 
            Caption         =   "OK"
            Height          =   330
            Left            =   2280
            TabIndex        =   32
            Top             =   720
            Width           =   615
         End
         Begin VB.ComboBox cboCh1Voltage 
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FF00&
            Height          =   345
            Left            =   1320
            Style           =   2  'Dropdown List
            TabIndex        =   18
            Top             =   340
            Width           =   975
         End
         Begin VB.TextBox txtCh1Position 
            Alignment       =   2  'Center
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FF00&
            Height          =   330
            Left            =   1320
            TabIndex        =   17
            Top             =   720
            Width           =   855
         End
         Begin VB.TextBox txtCh1TriggerLevel 
            Alignment       =   2  'Center
            BackColor       =   &H80000006&
            ForeColor       =   &H0000FF00&
            Height          =   330
            Left            =   1320
            TabIndex        =   16
            Top             =   1080
            Width           =   855
         End
         Begin VB.CheckBox cekCh1 
            Caption         =   "Check1"
            Height          =   255
            Left            =   1080
            TabIndex        =   15
            Top             =   0
            Width           =   255
         End
         Begin VB.Label lblChannel1 
            Caption         =   "CH1"
            Height          =   255
            Left            =   1320
            TabIndex        =   22
            Top             =   0
            Width           =   375
         End
         Begin VB.Label lblCh1Voltage 
            Caption         =   "CH1 Voltage"
            Height          =   255
            Left            =   120
            TabIndex        =   21
            Top             =   360
            Width           =   1095
         End
         Begin VB.Label lblCh1Position 
            Caption         =   "CH1 Position"
            Height          =   255
            Left            =   120
            TabIndex        =   20
            Top             =   750
            Width           =   1095
         End
         Begin VB.Label lblCh1TriggerLevel 
            Caption         =   "Trigger Level"
            Height          =   255
            Left            =   120
            TabIndex        =   19
            Top             =   1100
            Width           =   1095
         End
      End
      Begin VB.TextBox txtEXTTriggerLevel 
         Alignment       =   2  'Center
         BackColor       =   &H80000006&
         ForeColor       =   &H00FF00FF&
         Height          =   330
         Left            =   3590
         TabIndex        =   13
         Top             =   2160
         Width           =   735
      End
      Begin VB.TextBox txtTriggerPosition 
         Alignment       =   2  'Center
         BackColor       =   &H80000006&
         Enabled         =   0   'False
         ForeColor       =   &H00FF00FF&
         Height          =   330
         Left            =   3480
         TabIndex        =   11
         Top             =   1440
         Width           =   735
      End
      Begin VB.ComboBox cboTriggerSlope 
         BackColor       =   &H80000006&
         ForeColor       =   &H00FF00FF&
         Height          =   345
         Left            =   3590
         Style           =   2  'Dropdown List
         TabIndex        =   9
         Top             =   1800
         Width           =   735
      End
      Begin VB.ComboBox cboTriggerSource 
         BackColor       =   &H80000006&
         ForeColor       =   &H00FF00FF&
         Height          =   345
         Left            =   1440
         Style           =   2  'Dropdown List
         TabIndex        =   7
         Top             =   1780
         Width           =   975
      End
      Begin VB.ComboBox cboTimebase 
         BackColor       =   &H80000006&
         ForeColor       =   &H00FF00FF&
         Height          =   345
         Left            =   3360
         Style           =   2  'Dropdown List
         TabIndex        =   6
         Top             =   840
         Width           =   975
      End
      Begin VB.Label lblTriggerMode 
         Caption         =   "Trigger    Mode"
         Height          =   255
         Left            =   120
         TabIndex        =   39
         Top             =   2190
         Width           =   1215
      End
      Begin VB.Label lblEXTTriggerLevel 
         Caption         =   "EXT T_Level"
         Height          =   255
         Left            =   2445
         TabIndex        =   12
         Top             =   2190
         Width           =   1095
      End
      Begin VB.Label lblTriggerPosition 
         Caption         =   "Trigger Position"
         Height          =   255
         Left            =   3225
         TabIndex        =   10
         Top             =   1200
         Width           =   1335
      End
      Begin VB.Label lblTriggerSlope 
         Caption         =   "Trigger Slope"
         Height          =   255
         Left            =   2445
         TabIndex        =   8
         Top             =   1830
         Width           =   1215
      End
      Begin VB.Label lblTriggerSource 
         Caption         =   "Trigger Source"
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   1830
         Width           =   1215
      End
      Begin VB.Label lblTimebase 
         Caption         =   "TIMEBASE"
         Height          =   255
         Left            =   3360
         TabIndex        =   4
         Top             =   600
         Width           =   975
      End
   End
   Begin VB.Timer GetDataLoop 
      Interval        =   10
      Left            =   240
      Top             =   5400
   End
   Begin VB.PictureBox BackPicture 
      BackColor       =   &H80000001&
      BeginProperty Font 
         Name            =   "ËÎÌå"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   6120
      Left            =   0
      ScaleHeight     =   6060
      ScaleWidth      =   7680
      TabIndex        =   1
      Top             =   0
      Width           =   7740
      Begin VB.PictureBox DisplayPicture 
         AutoRedraw      =   -1  'True
         BackColor       =   &H80000008&
         Height          =   5775
         Left            =   120
         ScaleHeight     =   381
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   493
         TabIndex        =   2
         Top             =   120
         Width           =   7455
      End
   End
   Begin ComctlLib.StatusBar StatusBar 
      Align           =   2  'Align Bottom
      Height          =   300
      Left            =   0
      TabIndex        =   0
      Top             =   8775
      Width           =   7725
      _ExtentX        =   13626
      _ExtentY        =   529
      SimpleText      =   ""
      _Version        =   327682
      BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
         NumPanels       =   4
         BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   7434
            MinWidth        =   26
            TextSave        =   ""
            Key             =   ""
            Object.Tag             =   ""
         EndProperty
         BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Alignment       =   1
            AutoSize        =   2
            TextSave        =   ""
            Key             =   ""
            Object.Tag             =   ""
         EndProperty
         BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Style           =   6
            AutoSize        =   2
            Bevel           =   2
            Object.Width           =   1720
            MinWidth        =   1720
            TextSave        =   "2008-1-25"
            Key             =   ""
            Object.Tag             =   ""
         EndProperty
         BeginProperty Panel4 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Style           =   5
            Alignment       =   1
            AutoSize        =   2
            Bevel           =   2
            Object.Width           =   1323
            MinWidth        =   1323
            TextSave        =   "14:56"
            Key             =   ""
            Object.Tag             =   ""
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.Menu Waveform 
      Caption         =   "Waveform"
      WindowList      =   -1  'True
      Begin VB.Menu LineOrPoint 
         Caption         =   "Point"
      End
      Begin VB.Menu Plot 
         Caption         =   "X-Y Plot"
      End
   End
   Begin VB.Menu Grid 
      Caption         =   "Grid"
      Begin VB.Menu GridOnOFF 
         Caption         =   "Grid Off"
      End
   End
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cboCh1Voltage_Click()
    Ch1Voltage = cboCh1Voltage.ItemData(cboCh1Voltage.ListIndex)
    If Initialization = False Then
        Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)
        Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
    End If
End Sub

Private Sub cboCh2Voltage_Click()
    Ch2Voltage = cboCh2Voltage.ItemData(cboCh2Voltage.ListIndex)
    If Initialization = False Then
        Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)
        Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
    End If
End Sub

Private Sub cboTimebase_Click()
    Timebase = cboTimebase.ItemData(cboTimebase.ListIndex)
    Controlstate.Timebase = Timebase
    If Controlstate.Timebase > 24 Then
        ScrollMode = 1
    Else
        ScrollMode = 0
        TimeState.ScrollStart = 0
    End If
    If Initialization = False Then
        Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
        Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
        Result = sdCaptureStart(DeviceIndex)
    End If
End Sub

Private Sub cboTriggerMode_Click()
    TriggerMode = cboTriggerMode.ItemData(cboTriggerMode.ListIndex)
    FiltAndTrigger.TriggerMode = TriggerMode
    If Initialization = False Then
        If TriggerMode = 1 And TriggerSource = 2 Then
            Result = sdCaptureStart(DeviceIndex)
            Result = sdTriggerEnabled(DeviceIndex)
        End If
    End If
    If TriggerSource <> 2 And StartCapture = 0 Then
        StartCapture = 1
    End If
End Sub

Private Sub cboTriggerSlope_Click()
    TriggerSlope = cboTriggerSlope.ItemData(cboTriggerSlope.ListIndex)
    FiltAndTrigger.TriggerSlope = TriggerSlope
    If Initialization = False Then
        Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
        Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
    End If
End Sub

Private Sub cboTriggerSource_Click()
    TriggerSource = cboTriggerSource.ItemData(cboTriggerSource.ListIndex)
    Select Case TriggerSource
        Case 0
            txtCh1TriggerLevel.Enabled = True
            cmdCh1TriggerLevel.Enabled = True
            txtCh2TriggerLevel.Enabled = False
            cmdCh2TriggerLevel.Enabled = False
            txtEXTTriggerLevel.Enabled = False
            cmdEXTTriggerLevel.Enabled = False
        Case 1
            txtCh1TriggerLevel.Enabled = False
            cmdCh1TriggerLevel.Enabled = False
            txtCh2TriggerLevel.Enabled = True
            cmdCh2TriggerLevel.Enabled = True
            txtEXTTriggerLevel.Enabled = False
            cmdEXTTriggerLevel.Enabled = False
        Case 2
            txtCh1TriggerLevel.Enabled = True
            cmdCh1TriggerLevel.Enabled = True
            txtCh2TriggerLevel.Enabled = True
            cmdCh2TriggerLevel.Enabled = True
            txtEXTTriggerLevel.Enabled = False
            cmdEXTTriggerLevel.Enabled = False
        Case 3
            txtCh1TriggerLevel.Enabled = False
            cmdCh1TriggerLevel.Enabled = False
            txtCh2TriggerLevel.Enabled = False
            cmdCh2TriggerLevel.Enabled = False
            txtEXTTriggerLevel.Enabled = True
            cmdEXTTriggerLevel.Enabled = True
    End Select
    Controlstate.TriggerSource = TriggerSource
    If Ch1Enabled = True And Ch2Enabled = True Then
        Controlstate.SelectedChannel = 2
    ElseIf Ch1Enabled = False And Ch2Enabled = True Then
        Controlstate.SelectedChannel = 3
    Else
        Controlstate.SelectedChannel = 0
    End If
    If Initialization = False Then
        If TriggerSource = 2 Then
            Controlstate.IsAlt = 1
            Result = sdCaptureStart(DeviceIndex)
            Result = sdTriggerEnabled(DeviceIndex)
        Else
            Controlstate.IsAlt = 0
        End If
        Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
        Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
    End If
End Sub

Private Sub cekCh1_Click()
    If cekCh1.Value = 1 Then
        Ch1Enabled = True
        cboCh1Voltage.Enabled = True
        txtCh1Position.Enabled = True
        cmdCh1Position.Enabled = True
        AutosetData.Ch1Enabled = 1
        If TriggerSource = 0 Then
            txtCh1TriggerLevel.Enabled = True
            cmdCh1TriggerLevel.Enabled = True
        End If
        If Ch2Enabled = True Then
            Controlstate.SelectedChannel = 2
        Else
            Controlstate.SelectedChannel = 0
            cboTriggerSource.ListIndex = 0
        End If
    Else
        Ch1Enabled = False
        cboCh1Voltage.Enabled = False
        txtCh1Position.Enabled = False
        cmdCh1Position.Enabled = False
        AutosetData.Ch1Enabled = 0
        If Ch2Enabled = True Then
            cboTriggerSource.ListIndex = 1
        End If
        If TriggerSource <> 0 Then
            txtCh1TriggerLevel.Enabled = False
            cmdCh1TriggerLevel.Enabled = False
        End If
        If Ch2Enabled = True Then
            Controlstate.SelectedChannel = 3
        Else
            Controlstate.SelectedChannel = 0
        End If
    End If
    Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
    Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
End Sub

Private Sub cekCh2_Click()
    If cekCh2.Value = 1 Then
        Ch2Enabled = True
        cboCh2Voltage.Enabled = True
        txtCh2Position.Enabled = True
        cmdCh2Position.Enabled = True
        AutosetData.Ch2Enabled = 1
        If TriggerSource = 1 Then
            txtCh2TriggerLevel.Enabled = True
            cmdCh2TriggerLevel.Enabled = True
        End If
        If Ch1Enabled = True Then
            Controlstate.SelectedChannel = 2
        Else
            Controlstate.SelectedChannel = 3
            cboTriggerSource.ListIndex = 1
        End If
    Else
        Ch2Enabled = False
        cboCh2Voltage.Enabled = False
        txtCh2Position.Enabled = False
        cmdCh2Position.Enabled = False
        If Ch1Enabled = True Then
            cboTriggerSource.ListIndex = 0
        End If
        AutosetData.Ch2Enabled = 0
        If TriggerSource <> 1 Then
            txtCh2TriggerLevel.Enabled = False
            cmdCh2TriggerLevel.Enabled = False
        End If
        Controlstate.SelectedChannel = 0
    End If
    Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
    Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
End Sub

Private Sub cmdAutoSet_Click()

    MainForm.GetDataLoop.Enabled = False
    
    If TriggerSource = 0 Then
        AutosetData.WhichChannel = 0
    Else
        AutosetData.WhichChannel = 1
    End If

    Result = sdAutoset(DeviceIndex, Controlstate, AutosetData, FiltAndTrigger, levers, level(0))
    
    Ch1Voltage = AutosetData.Ch1Voltage
    cboCh1Voltage.ListIndex = Ch1Voltage
    Ch2Voltage = AutosetData.Ch2Voltage
    cboCh2Voltage.ListIndex = Ch2Voltage
    TriggerSource = cboTriggerSource.ItemData(cboTriggerSource.ListIndex)
    
    If TriggerSource = 0 Then
        Timebase = AutosetData.Ch1Timebase
    Else
        Timebase = AutosetData.Ch2Timebase
    End If
    Controlstate.Timebase = Timebase
    cboTimebase.ListIndex = Timebase
    TriggerPosition = 50
    Controlstate.TriggerSource = TriggerSource
    Controlstate.TriggerPosition = TriggerPosition
    Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)
    Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
    Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
    Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
    Result = sdCaptureStart(DeviceIndex)
    MainForm.GetDataLoop.Enabled = True
    
End Sub

Private Sub cmdCh1Coupling_Click()
    If cmdCh1Coupling.Caption = "AC" Then
        cmdCh1Coupling.Caption = "DC"
        Ch1_ACDC = 0
        Ch1InGND = False
        AutosetData.Ch1InGND = 0
    ElseIf cmdCh1Coupling.Caption = "DC" Then
        cmdCh1Coupling.Caption = "GND"
        Ch1_ACDC = 0
        Ch1InGND = True
        AutosetData.Ch1InGND = 1
    Else
        cmdCh1Coupling.Caption = "AC"
        Ch1_ACDC = 1
        Ch1InGND = False
        AutosetData.Ch1InGND = 0
    End If
    Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)

End Sub

Private Sub cmdCh1Position_Click()
    If IsNumeric(Trim(txtCh1Position.Text)) Then
        If CDbl(txtCh1Position.Text) > 255 Then
            MsgBox ("The maximum data is 255")
        ElseIf CDbl(txtCh1Position.Text) < 0 Then
            MsgBox ("The minimum data is 0")
        Else
            Ch1Position = CDbl(txtCh1Position.Text)
            levers.Ch1Position = Ch1Position
            txtCh1TriggerLevel.Text = Ch1Position
            levers.Ch1TriggerLevel = Ch1Position
            Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
        End If
    Else
        MsgBox ("Not a number!")
    End If
End Sub

Private Sub cmdCh1TriggerLevel_Click()
    If IsNumeric(Trim(txtCh1TriggerLevel.Text)) Then
        If CDbl(txtCh1TriggerLevel.Text) > 255 Then
            MsgBox ("The maximum data is 255")
        ElseIf CDbl(txtCh1TriggerLevel.Text) < 0 Then
            MsgBox ("The minimum data is 0")
        Else
            Ch1TriggerLevel = CDbl(txtCh1TriggerLevel.Text)
            levers.Ch1TriggerLevel = Ch1TriggerLevel
            Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
        End If
    Else
        MsgBox ("Not a number!")
    End If
End Sub

Private Sub cmdCh2Coupling_Click()
    If cmdCh2Coupling.Caption = "AC" Then
        cmdCh2Coupling.Caption = "DC"
        Ch2_ACDC = 0
        Ch2InGND = False
        AutosetData.Ch2InGND = 0
    ElseIf cmdCh2Coupling.Caption = "DC" Then
        cmdCh2Coupling.Caption = "GND"
        Ch2_ACDC = 0
        Ch2InGND = True
        AutosetData.Ch2InGND = 1
    Else
        cmdCh2Coupling.Caption = "AC"
        Ch2_ACDC = 1
        Ch2InGND = False
        AutosetData.Ch2InGND = 0
    End If
    Result = sdSetVoltageAndCoupling(DeviceIndex, Ch1Voltage, Ch2Voltage, Ch1_ACDC, Ch2_ACDC, TriggerSource)
End Sub

Private Sub cmdCh2Position_Click()
    If IsNumeric(Trim(txtCh2Position.Text)) Then
        If CDbl(txtCh2Position.Text) > 255 Then
            MsgBox ("The maximum data is 255")
        ElseIf CDbl(txtCh2Position.Text) < 0 Then
            MsgBox ("The minimum data is 0")
        Else
            Ch2Position = CDbl(txtCh2Position.Text)
            levers.Ch2Position = Ch2Position
            txtCh2TriggerLevel.Text = Ch2Position
            levers.Ch2TriggerLevel = Ch2Position
            Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
        End If
    Else
        MsgBox ("Not a number!")
    End If
End Sub

Private Sub cmdCh2TriggerLevel_Click()
    If IsNumeric(Trim(txtCh2TriggerLevel.Text)) Then
        If CDbl(txtCh2TriggerLevel.Text) > 255 Then
            MsgBox ("The maximum data is 255")
        ElseIf CDbl(txtCh2TriggerLevel.Text) < 0 Then
            MsgBox ("The minimum data is 0")
        Else
            Ch2TriggerLevel = CDbl(txtCh2TriggerLevel.Text)
            levers.Ch2TriggerLevel = Ch2TriggerLevel
            Result = sdSetOffset(DeviceIndex, levers, Ch1Voltage, Ch2Voltage, TriggerSource, level(0))
        End If
    Else
        MsgBox ("Not a number!")
    End If
End Sub

Private Sub cmdDecrease_Click()
    If StartCapture = 1 Then
        TriggerPosition = TriggerPosition - 25
        If TriggerPosition < 0 Then
            TriggerPosition = 0
        End If
        Controlstate.TriggerPosition = TriggerPosition
        txtTriggerPosition.Text = TriggerPosition & "%"
        If Initialization = False Then
            Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
            Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
        End If
    End If
End Sub

Private Sub cmdFFT_Click()
    If FFTOn = False Then
        FFTOn = True
        If optCh1.Value = True Then
            FFTControl.WhichChannel = 0
            SelectCh1RealVoltage
        Else
            FFTControl.WhichChannel = 1
            SelectCh2RealVoltage
        End If
    Else
        FFTOn = False
    End If
End Sub

Private Sub cmdIncrease_Click()
    If StartCapture = 1 Then
        TriggerPosition = TriggerPosition + 25
        If TriggerPosition > 100 Then
            TriggerPosition = 100
        End If
        Controlstate.TriggerPosition = TriggerPosition
        txtTriggerPosition.Text = TriggerPosition & "%"
        If Initialization = False Then
            Result = sdSetTriggerAndSampleRate(DeviceIndex, TriggerSlope, Controlstate)
            Result = sdSetFilt(DeviceIndex, FiltAndTrigger)
        End If
    End If
End Sub

Private Sub cmdStart_Click()

    StartCapture = 1
    MainForm.GetDataLoop.Enabled = True
    
End Sub

Private Sub cmdStop_Click()
    StartCapture = 0
    MainForm.GetDataLoop.Enabled = False
    
End Sub

Private Sub Form_Load()

    InitializeMainForm
    
    cboCh1Voltage.ListIndex = 6
    cboCh2Voltage.ListIndex = 6
    cboTimebase.ListIndex = 12
    cboTriggerSlope.ListIndex = 0
    cboTriggerSource.ListIndex = 0
    cboTriggerMode.ListIndex = 0
    
    txtCh1Position.Text = "64"
    txtCh2Position.Text = "192"
    txtCh1TriggerLevel.Text = "64"
    txtCh2TriggerLevel.Text = "192"
    txtEXTTriggerLevel.Text = "128"
    txtTriggerPosition.Text = "50%"
    cekCh1.Value = 1
    cekCh2.Value = 1
    txtCh2TriggerLevel.Enabled = False
    txtEXTTriggerLevel.Enabled = False
End Sub

Private Sub GetDataLoop_Timer()
    
    DrawMainPicture     'Draw grid on  screen
    
    GetDataFromHardware 'Get the channel data form hardware
    
    DisplaySampling   'Display sampling
    
    ToDisplayData           'Display waveform
                        
End Sub
Private Sub InitializeMainForm()
'initialize combox
    cboCh1VoltageInit
    cboCh2VoltageInit
    cboTriggerSourceInit
    cboTimebaseInit
    cboTriggerSlopeInit
    cboTriggerModeInit
End Sub
Private Sub cboCh1VoltageInit()
    cboCh1Voltage.AddItem "10mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 0
    cboCh1Voltage.AddItem "20mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 1
    cboCh1Voltage.AddItem "50mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 2
    cboCh1Voltage.AddItem "100mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 3
    cboCh1Voltage.AddItem "200mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 4
    cboCh1Voltage.AddItem "500mV"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 5
    cboCh1Voltage.AddItem "1V"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 6
    cboCh1Voltage.AddItem "2V"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 7
    cboCh1Voltage.AddItem "5V"
    cboCh1Voltage.ItemData(cboCh1Voltage.NewIndex) = 8
End Sub
Private Sub cboCh2VoltageInit()
    cboCh2Voltage.AddItem "10mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 0
    cboCh2Voltage.AddItem "20mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 1
    cboCh2Voltage.AddItem "50mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 2
    cboCh2Voltage.AddItem "100mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 3
    cboCh2Voltage.AddItem "200mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 4
    cboCh2Voltage.AddItem "500mV"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 5
    cboCh2Voltage.AddItem "1V"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 6
    cboCh2Voltage.AddItem "2V"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 7
    cboCh2Voltage.AddItem "5V"
    cboCh2Voltage.ItemData(cboCh2Voltage.NewIndex) = 8
End Sub
Private Sub cboTriggerSourceInit()
    cboTriggerSource.AddItem "CH1"
    cboTriggerSource.ItemData(cboTriggerSource.NewIndex) = 0
    cboTriggerSource.AddItem "CH2"
    cboTriggerSource.ItemData(cboTriggerSource.NewIndex) = 1
    cboTriggerSource.AddItem "ALT"
    cboTriggerSource.ItemData(cboTriggerSource.NewIndex) = 2
    cboTriggerSource.AddItem "EXT"
    cboTriggerSource.ItemData(cboTriggerSource.NewIndex) = 3
    cboTriggerSource.AddItem "EXT/10"
    cboTriggerSource.ItemData(cboTriggerSource.NewIndex) = 4
End Sub
Private Sub cboTimebaseInit()
    cboTimebase.AddItem "4nS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 0
    cboTimebase.AddItem "10nS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 1
    cboTimebase.AddItem "20nS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 2
    cboTimebase.AddItem "40 nS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 3
    cboTimebase.AddItem "0.1 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 4
    cboTimebase.AddItem "0.2 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 5
    cboTimebase.AddItem "0.4 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 6
    cboTimebase.AddItem "1 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 7
    cboTimebase.AddItem "2 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 8
    cboTimebase.AddItem "4 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 9
    cboTimebase.AddItem "10 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 10
    cboTimebase.AddItem "20 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 11
    cboTimebase.AddItem "40 uS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 12
    cboTimebase.AddItem "0.1 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 13
    cboTimebase.AddItem "0.2 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 14
    cboTimebase.AddItem "0.4 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 15
    cboTimebase.AddItem "1 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 16
    cboTimebase.AddItem "2 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 17
    cboTimebase.AddItem "4 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 18
    cboTimebase.AddItem "10 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 19
    cboTimebase.AddItem "20 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 20
    cboTimebase.AddItem "40 mS"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 21
    cboTimebase.AddItem "0.1 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 22
    cboTimebase.AddItem "0.2 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 23
    cboTimebase.AddItem "0.4 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 24
    cboTimebase.AddItem "1 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 25
    cboTimebase.AddItem "2 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 26
    cboTimebase.AddItem "4 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 27
    cboTimebase.AddItem "10 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 28
    cboTimebase.AddItem "20 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 29
    cboTimebase.AddItem "40 S"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 30
    cboTimebase.AddItem "1 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 31
    cboTimebase.AddItem "2 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 32
    cboTimebase.AddItem "4 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 33
    cboTimebase.AddItem "10 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 34
    cboTimebase.AddItem "20 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 35
    cboTimebase.AddItem "40 min"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 36
    cboTimebase.AddItem "1 hour"
    cboTimebase.ItemData(cboTimebase.NewIndex) = 37
End Sub
Private Sub cboTriggerSlopeInit()
    cboTriggerSlope.AddItem "+"
    cboTriggerSlope.ItemData(cboTriggerSlope.NewIndex) = 0
    cboTriggerSlope.AddItem "-"
    cboTriggerSlope.ItemData(cboTriggerSlope.NewIndex) = 1
End Sub
Private Sub cboTriggerModeInit()
    cboTriggerMode.AddItem "AUTO"
    cboTriggerMode.ItemData(cboTriggerMode.NewIndex) = 0
    cboTriggerMode.AddItem "NORMAL"
    cboTriggerMode.ItemData(cboTriggerMode.NewIndex) = 1
    cboTriggerMode.AddItem "SINGLE"
    cboTriggerMode.ItemData(cboTriggerMode.NewIndex) = 2
End Sub
Private Sub GridOnOFF_Click()
    If GridOnOFF.Caption = "Grid On" Then
        GridOnOFF.Caption = "Grid Off"
        GridOn = True
    Else
        GridOnOFF.Caption = "Grid On"
        GridOn = False
    End If
End Sub

Private Sub LineOrPoint_Click()
    If LineOrPoint.Caption = "Point" Then
        LineOrPoint.Caption = "Line"
        PointOrLine = 0
    Else
        LineOrPoint.Caption = "Point"
        PointOrLine = 1
    End If
End Sub

Private Sub optCh1_Click()
    FFTControl.WhichChannel = 0
End Sub

Private Sub optCh2_Click()
    FFTControl.WhichChannel = 1
End Sub

Private Sub Plot_Click()
    If Plot.Caption = "Normal Plot" Then
        Plot.Caption = "X-Y Plot"
        XYMode = False
    Else
        Plot.Caption = "Normal Plot"
        XYMode = True
    End If
End Sub

Private Sub txtEXTTriggerLevel_Click()
    If IsNumeric(Trim(txtEXTTriggerLevel.Text)) Then
        If CDbl(txtEXTTriggerLevel.Text) > 255 Then
            MsgBox ("The maximum data is 255")
        ElseIf CDbl(txtEXTTriggerLevel.Text) < 0 Then
            MsgBox ("The minimum data is 0")
        Else
            ExtTriggerLevel = CDbl(txtEXTTriggerLevel.Text)
        End If
    Else
        MsgBox ("Not a number!")
    End If
End Sub
Private Sub SelectCh1RealVoltage()
    Select Case Ch1Voltage
        Case 0:
            FFTControl.Ch1RealVoltage = 0.01
        Case 1:
            FFTControl.Ch1RealVoltage = 0.02
        Case 2:
            FFTControl.Ch1RealVoltage = 0.05
        Case 3:
            FFTControl.Ch1RealVoltage = 0.1
        Case 4:
            FFTControl.Ch1RealVoltage = 0.2
        Case 5:
            FFTControl.Ch1RealVoltage = 0.5
        Case 6:
            FFTControl.Ch1RealVoltage = 1
        Case 7:
            FFTControl.Ch1RealVoltage = 2
        Case 8:
            FFTControl.Ch1RealVoltage = 5
    End Select

End Sub

Private Sub SelectCh2RealVoltage()
    Select Case Ch2Voltage
        Case 0:
            FFTControl.Ch2RealVoltage = 0.01
        Case 1:
            FFTControl.Ch2RealVoltage = 0.02
        Case 2:
            FFTControl.Ch2RealVoltage = 0.05
        Case 3:
            FFTControl.Ch2RealVoltage = 0.1
        Case 4:
            FFTControl.Ch2RealVoltage = 0.2
        Case 5:
            FFTControl.Ch2RealVoltage = 0.5
        Case 6:
            FFTControl.Ch2RealVoltage = 1
        Case 7:
            FFTControl.Ch2RealVoltage = 2
        Case 8:
            FFTControl.Ch2RealVoltage = 5
    End Select

End Sub
