Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Friend Class MainDlg
	Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'For the start-up form, the first instance created is the default instance.
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'This call is required by the Windows Form Designer.
		InitializeComponent()
	End Sub
	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer
	Public ToolTip1 As System.Windows.Forms.ToolTip
	Public WithEvents DelimBox As System.Windows.Forms.ComboBox
	Public WithEvents Frame5 As System.Windows.Forms.GroupBox
	Public WithEvents Exit_Renamed As System.Windows.Forms.Button
	Public WithEvents Set_Renamed As System.Windows.Forms.Button
	Public WithEvents Label11 As System.Windows.Forms.Label
	Public WithEvents Frame4 As System.Windows.Forms.GroupBox
	Public WithEvents WfmStart As System.Windows.Forms.Button
	Public WithEvents Label8 As System.Windows.Forms.Label
	Public WithEvents Frame2 As System.Windows.Forms.GroupBox
	Public WithEvents AddrNo As System.Windows.Forms.ComboBox
	Public WithEvents Label1 As System.Windows.Forms.Label
	Public WithEvents Frame3 As System.Windows.Forms.GroupBox
	Public WithEvents TextSecDiv As System.Windows.Forms.TextBox
	Public WithEvents TextVolts As System.Windows.Forms.TextBox
	Public WithEvents Start As System.Windows.Forms.Button
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label3 As System.Windows.Forms.Label
	Public WithEvents Frame1 As System.Windows.Forms.GroupBox
	Public WithEvents Label5 As System.Windows.Forms.Label
	Public WithEvents Label10 As System.Windows.Forms.Label
	Public WithEvents Label7 As System.Windows.Forms.Label
	Public WithEvents Label2 As System.Windows.Forms.Label
	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Frame5 = New System.Windows.Forms.GroupBox()
        Me.DelimBox = New System.Windows.Forms.ComboBox()
        Me.Exit_Renamed = New System.Windows.Forms.Button()
        Me.Frame4 = New System.Windows.Forms.GroupBox()
        Me.Set_Renamed = New System.Windows.Forms.Button()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.Frame2 = New System.Windows.Forms.GroupBox()
        Me.WfmStart = New System.Windows.Forms.Button()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Frame3 = New System.Windows.Forms.GroupBox()
        Me.AddrNo = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.TextSecDiv = New System.Windows.Forms.TextBox()
        Me.TextVolts = New System.Windows.Forms.TextBox()
        Me.Start = New System.Windows.Forms.Button()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Frame5.SuspendLayout()
        Me.Frame4.SuspendLayout()
        Me.Frame2.SuspendLayout()
        Me.Frame3.SuspendLayout()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Frame5
        '
        Me.Frame5.BackColor = System.Drawing.SystemColors.Control
        Me.Frame5.Controls.AddRange(New System.Windows.Forms.Control() {Me.DelimBox})
        Me.Frame5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame5.Location = New System.Drawing.Point(133, 21)
        Me.Frame5.Name = "Frame5"
        Me.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame5.Size = New System.Drawing.Size(153, 41)
        Me.Frame5.TabIndex = 20
        Me.Frame5.TabStop = False
        Me.Frame5.Text = "Delimiter"
        '
        'DelimBox
        '
        Me.DelimBox.BackColor = System.Drawing.SystemColors.Window
        Me.DelimBox.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelimBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.DelimBox.ForeColor = System.Drawing.SystemColors.WindowText
        Me.DelimBox.Items.AddRange(New Object() {"None", "CR+LF", "CR", "LF"})
        Me.DelimBox.Location = New System.Drawing.Point(13, 14)
        Me.DelimBox.Name = "DelimBox"
        Me.DelimBox.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelimBox.Size = New System.Drawing.Size(128, 21)
        Me.DelimBox.TabIndex = 21
        '
        'Exit_Renamed
        '
        Me.Exit_Renamed.BackColor = System.Drawing.SystemColors.Control
        Me.Exit_Renamed.Cursor = System.Windows.Forms.Cursors.Default
        Me.Exit_Renamed.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Exit_Renamed.Location = New System.Drawing.Point(6, 286)
        Me.Exit_Renamed.Name = "Exit_Renamed"
        Me.Exit_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Exit_Renamed.Size = New System.Drawing.Size(274, 28)
        Me.Exit_Renamed.TabIndex = 18
        Me.Exit_Renamed.Text = "End(&X)"
        '
        'Frame4
        '
        Me.Frame4.BackColor = System.Drawing.SystemColors.Control
        Me.Frame4.Controls.AddRange(New System.Windows.Forms.Control() {Me.Set_Renamed, Me.Label11})
        Me.Frame4.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Frame4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame4.Location = New System.Drawing.Point(6, 224)
        Me.Frame4.Name = "Frame4"
        Me.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame4.Size = New System.Drawing.Size(284, 54)
        Me.Frame4.TabIndex = 15
        Me.Frame4.TabStop = False
        '
        'Set_Renamed
        '
        Me.Set_Renamed.BackColor = System.Drawing.SystemColors.Control
        Me.Set_Renamed.Cursor = System.Windows.Forms.Cursors.Default
        Me.Set_Renamed.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Set_Renamed.Location = New System.Drawing.Point(189, 16)
        Me.Set_Renamed.Name = "Set_Renamed"
        Me.Set_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Set_Renamed.Size = New System.Drawing.Size(89, 28)
        Me.Set_Renamed.TabIndex = 17
        Me.Set_Renamed.Text = "Start(&C)"
        '
        'Label11
        '
        Me.Label11.BackColor = System.Drawing.SystemColors.Control
        Me.Label11.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label11.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label11.Location = New System.Drawing.Point(10, 9)
        Me.Label11.Name = "Label11"
        Me.Label11.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label11.Size = New System.Drawing.Size(154, 40)
        Me.Label11.TabIndex = 16
        Me.Label11.Text = "It is made to indicate amplitude in the display of oscilloscope."
        '
        'Frame2
        '
        Me.Frame2.BackColor = System.Drawing.SystemColors.Control
        Me.Frame2.Controls.AddRange(New System.Windows.Forms.Control() {Me.WfmStart, Me.Label8})
        Me.Frame2.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame2.Location = New System.Drawing.Point(6, 146)
        Me.Frame2.Name = "Frame2"
        Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame2.Size = New System.Drawing.Size(284, 53)
        Me.Frame2.TabIndex = 11
        Me.Frame2.TabStop = False
        '
        'WfmStart
        '
        Me.WfmStart.BackColor = System.Drawing.SystemColors.Control
        Me.WfmStart.Cursor = System.Windows.Forms.Cursors.Default
        Me.WfmStart.ForeColor = System.Drawing.SystemColors.ControlText
        Me.WfmStart.Location = New System.Drawing.Point(188, 16)
        Me.WfmStart.Name = "WfmStart"
        Me.WfmStart.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.WfmStart.Size = New System.Drawing.Size(89, 28)
        Me.WfmStart.TabIndex = 13
        Me.WfmStart.Text = "Acquired(&A)"
        '
        'Label8
        '
        Me.Label8.BackColor = System.Drawing.SystemColors.Control
        Me.Label8.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label8.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label8.Location = New System.Drawing.Point(10, 9)
        Me.Label8.Name = "Label8"
        Me.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label8.Size = New System.Drawing.Size(170, 42)
        Me.Label8.TabIndex = 12
        Me.Label8.Text = "Wave shape data (WFM_DATA.csv) are recorded by a current drive. "
        '
        'Frame3
        '
        Me.Frame3.BackColor = System.Drawing.SystemColors.Control
        Me.Frame3.Controls.AddRange(New System.Windows.Forms.Control() {Me.AddrNo, Me.Label1})
        Me.Frame3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame3.Location = New System.Drawing.Point(6, 21)
        Me.Frame3.Name = "Frame3"
        Me.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame3.Size = New System.Drawing.Size(111, 41)
        Me.Frame3.TabIndex = 2
        Me.Frame3.TabStop = False
        Me.Frame3.Text = "Device"
        '
        'AddrNo
        '
        Me.AddrNo.BackColor = System.Drawing.SystemColors.Window
        Me.AddrNo.Cursor = System.Windows.Forms.Cursors.Default
        Me.AddrNo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.AddrNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.AddrNo.ForeColor = System.Drawing.SystemColors.WindowText
        Me.AddrNo.Location = New System.Drawing.Point(62, 14)
        Me.AddrNo.Name = "AddrNo"
        Me.AddrNo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.AddrNo.Size = New System.Drawing.Size(40, 23)
        Me.AddrNo.TabIndex = 3
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(6, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(54, 13)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Address ="
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextSecDiv, Me.TextVolts, Me.Start, Me.Label4, Me.Label3})
        Me.Frame1.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(6, 73)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(284, 51)
        Me.Frame1.TabIndex = 0
        Me.Frame1.TabStop = False
        '
        'TextSecDiv
        '
        Me.TextSecDiv.AcceptsReturn = True
        Me.TextSecDiv.AutoSize = False
        Me.TextSecDiv.BackColor = System.Drawing.SystemColors.Window
        Me.TextSecDiv.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextSecDiv.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextSecDiv.Location = New System.Drawing.Point(92, 23)
        Me.TextSecDiv.MaxLength = 0
        Me.TextSecDiv.Name = "TextSecDiv"
        Me.TextSecDiv.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextSecDiv.Size = New System.Drawing.Size(77, 22)
        Me.TextSecDiv.TabIndex = 7
        Me.TextSecDiv.Text = ""
        '
        'TextVolts
        '
        Me.TextVolts.AcceptsReturn = True
        Me.TextVolts.AutoSize = False
        Me.TextVolts.BackColor = System.Drawing.SystemColors.Window
        Me.TextVolts.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextVolts.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextVolts.Location = New System.Drawing.Point(10, 23)
        Me.TextVolts.MaxLength = 0
        Me.TextVolts.Name = "TextVolts"
        Me.TextVolts.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextVolts.Size = New System.Drawing.Size(77, 22)
        Me.TextVolts.TabIndex = 6
        Me.TextVolts.Text = ""
        '
        'Start
        '
        Me.Start.BackColor = System.Drawing.SystemColors.Control
        Me.Start.Cursor = System.Windows.Forms.Cursors.Default
        Me.Start.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Start.Location = New System.Drawing.Point(186, 14)
        Me.Start.Name = "Start"
        Me.Start.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Start.Size = New System.Drawing.Size(89, 28)
        Me.Start.TabIndex = 1
        Me.Start.Text = "Start(&S)"
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(94, 11)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(53, 13)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "SEC/DIV"
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(11, 11)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(64, 13)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "VOLTS/DIV"
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.SystemColors.Control
        Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label5.Location = New System.Drawing.Point(6, 7)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(141, 15)
        Me.Label5.TabIndex = 19
        Me.Label5.Text = "Tektronix TDS3000"
        '
        'Label10
        '
        Me.Label10.BackColor = System.Drawing.SystemColors.Control
        Me.Label10.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label10.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label10.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label10.Location = New System.Drawing.Point(8, 207)
        Me.Label10.Name = "Label10"
        Me.Label10.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label10.Size = New System.Drawing.Size(292, 17)
        Me.Label10.TabIndex = 14
        Me.Label10.Text = "<<< The amplitude of the wave shape is indicated >>>"
        '
        'Label7
        '
        Me.Label7.BackColor = System.Drawing.SystemColors.Control
        Me.Label7.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label7.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label7.Location = New System.Drawing.Point(10, 134)
        Me.Label7.Name = "Label7"
        Me.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label7.Size = New System.Drawing.Size(208, 17)
        Me.Label7.TabIndex = 10
        Me.Label7.Text = "<<< Wave form data are acquired >>>"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 61)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(114, 17)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "<<< Auto set scale >>>"
        '
        'MainDlg
        '
        Me.ClientSize = New System.Drawing.Size(319, 326)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Frame5, Me.Exit_Renamed, Me.Frame4, Me.Frame2, Me.Frame3, Me.Frame1, Me.Label5, Me.Label10, Me.Label7, Me.Label2})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(454, 134)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "MainDlg"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "TDS3000 Series sample"
        Me.Frame5.ResumeLayout(False)
        Me.Frame4.ResumeLayout(False)
        Me.Frame2.ResumeLayout(False)
        Me.Frame3.ResumeLayout(False)
        Me.Frame1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "Upgrade Support "
	Private Shared m_vb6FormDefInstance As MainDlg
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As MainDlg
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New MainDlg()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
	
	' Global ///////////////////////////////////////////////////////////////////
	Dim i As Short
	Dim Ret, Ret2 As Integer
	Dim MyAddr As Integer
	Dim Fstb(32) As Integer
    Dim MsgText, ErrText As String
    Dim Delim As Integer
    Dim gChFstb As GCHandle                 'GCHandle for Fstb array
    Dim pFstb As IntPtr                     'IntPtr for Fstb array
    Dim gChCmd As GCHandle                  'GCHandle for Cmd array
   
    Private Sub DelimBox_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelimBox.SelectedIndexChanged

        Eoi = 1

        Delim = DelimBox.SelectedIndex
        Ret = GpDelim(Delim, Eoi)

    End Sub


    ' Form Load ////////////////////////////////////////////////////////////////////
    Private Sub MainDlg_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        'Specify Pinned handle to Cmd
        If gChCmd.IsAllocated = False Then
            gChCmd = GCHandle.Alloc(Cmd, GCHandleType.Pinned)
        End If
        'Specify Pinned handle to Fstb
        If gChFstb.IsAllocated = False Then
            gChFstb = GCHandle.Alloc(Fstb, GCHandleType.Pinned)
        End If
        'Get address object by Pinned handle
        pCmd = gChCmd.AddrOfPinnedObject()
        pFstb = gChFstb.AddrOfPinnedObject()

        DelimBox.Text = "CR+LF"

        Ret = GpibInit(MsgText)
        If (Ret = 1) Then
            Ret2 = MsgBox(MsgText, MsgBoxStyle.OKOnly, "Error")
            Exit Sub
        End If
        '***** GpDelim(X, Y) X -> 0:Non,1:CR/LF,2:CR,3:LF Y -> 0:Non,1:Use *****
        Ret = GpDelim(3, 1)

        Ret = GpDevFind(pFstb)
        Ret = GpBoardsts(&H8S, MyAddr)

        For i = 0 To 30
            If (MyAddr <> Fstb(0)) Then
                AddrNo.Items.Add(CStr(i))
            End If
        Next
        If Fstb(0) = 255 Then
            AddrNo.SelectedIndex = 0
        Else
            AddrNo.SelectedIndex = Fstb(0)
        End If

        Fstb(0) = AddrNo.SelectedIndex

        Call DelimBox_SelectedIndexChanged(DelimBox, New System.EventArgs())

    End Sub

    ' AutoSet ////////////////////////////////////////////////////////////////////
    Private Sub Start_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Start.Click
        Dim ReadVolts As String
        Dim ReadHoriz As String

        If AddrNo.SelectedIndex <> Fstb(0) Then Fstb(0) = AddrNo.SelectedIndex

        Ret = GpibPrint(Fstb(0), "CLEARMENU")
        If (Ret = 1) Then Exit Sub
        Ret = GpibPrint(Fstb(0), "FACTORY")
        If (Ret = 1) Then Exit Sub
        Ret = GpibPrint(Fstb(0), "LOCK ALL")
        If (Ret = 1) Then
            Exit Sub
        Else
            Ret = MsgBox("Connect it to probe of the channel 1. ", MsgBoxStyle.OKOnly)
            Call WaitOPC(Fstb(0))
        End If

        Ret = GpibPrint(Fstb(0), "HEADER 0")
        If (Ret = 1) Then Exit Sub

        Ret = GpibPrint(Fstb(0), "AUTOSET EXECUTE")
        If (Ret = 1) Then Exit Sub
        Ret = MsgBox("WaveForm of the channel 1 was set up automatically. ", MsgBoxStyle.OKOnly, "TDS3000 -> Run")

        Ret = GpibPrint(Fstb(0), "CH1:SCALE?")
        If (Ret = 1) Then Exit Sub
        ReadVolts = Space(128)
        Ret = GpibInput(Fstb(0), ReadVolts)
        If (Ret = 1) Then Exit Sub
        Ret = GpibPrint(Fstb(0), "HORIZONTAL:MAIN:SCALE?")
        If (Ret = 1) Then Exit Sub
        ReadHoriz = Space(128)
        Ret = GpibInput(Fstb(0), ReadHoriz)
        If (Ret = 1) Then Exit Sub

        TextVolts.Text = ReadVolts
        TextSecDiv.Text = ReadHoriz

        Ret = GpibPrint(Fstb(0), "UNLOCK ALL")
        If (Ret = 1) Then Exit Sub

    End Sub

    ' Wave form data are acquired.  //////////////////////////////////////////////////////////////////
    Private Sub WfmStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WfmStart.Click
        Dim ByteData(1000) As Byte
        Dim gChByteData As GCHandle                                 'GCHandle for ByteData array
        Dim pByteData As IntPtr                                     'IntPtr for ByteData array
        Dim IntData(1000) As Short
        Dim DATSRC As String
        Dim StrData As String
        Dim DataMax As Short
        Dim RD As String
        Dim DSTART As Short
        Dim DSTOP As Short
        Dim WFPOINTS As Short
        Dim RLPREAM As String
        Dim IARRDIM As Short
        Dim CURBYTES As Short
        Dim YOFF As Single
        Dim YMULT As Single
        Dim YUNIT As String
        Dim PtOff As Single
        Dim XINCR As Single
        Dim XUNIT As String
        Dim WAVEFL As String

        'Specify Pinned handle to ByteData
        If gChByteData.IsAllocated = False Then
            gChByteData = GCHandle.Alloc(ByteData, GCHandleType.Pinned)
        End If
        'Get address object by Pinned handle
        pByteData = gChByteData.AddrOfPinnedObject()

        ' Ret = GpibInit(ErrText)                                    'Initialize
        Ret = GpibPrint(1, "HEADER OFF")
        If (Ret = 1) Then Exit Sub

        DATSRC = "CH1"
        StrData = "DATA:SOURCE " & DATSRC
        Ret = GpibPrint(Fstb(0), StrData)
        If (Ret = 1) Then Exit Sub
        Ret = GpibPrint(Fstb(0), "DATA:ENCDG RIBINARY;WIDTH 1")
        If (Ret = 1) Then Exit Sub
        DataMax = 500

        StrData = "HORIZONTAL:RECORDLENGTH " & Str(DataMax)
        Ret = GpibPrint(Fstb(0), StrData)
        If (Ret = 1) Then Exit Sub

        DSTART = 1 : DSTOP = DataMax
        WFPOINTS = DSTOP - DSTART + 1

        StrData = "DATA:START " & Str(DSTART)
        Ret = GpibPrint(Fstb(0), StrData)
        If (Ret = 1) Then Exit Sub

        StrData = "DATA:STOP " & Str(DSTOP)
        Ret = GpibPrint(Fstb(0), StrData)
        If (Ret = 1) Then Exit Sub

        StrData = "HEADER OFF"
        Ret = GpibPrint(Fstb(0), StrData)
        If (Ret = 1) Then Exit Sub

        Ret = GpibPrint(Fstb(0), "ACQUIRE:STATE RUN")
        If (Ret = 1) Then
            Exit Sub
        Else
            Call WaitOPC(Fstb(0))
        End If
        Ret = GpibPrint(Fstb(0), "CURVE?")
        If (Ret = 1) Then Exit Sub
        RLPREAM = Space(Len(Str(WFPOINTS)) + 1)
        IARRDIM = Int(WFPOINTS / 2) + 1
        CURBYTES = WFPOINTS + 1
        Dim IARR(IARRDIM) As Object
        Ret = GpibListenB(Fstb(0), pByteData, Srlen)
        If (Ret = 1) Then Exit Sub

        For i = 0 To Srlen
            IntData(i) = ByteData(i)
            If IntData(i) > 128 Then IntData(i) = -(256 - IntData(i))
        Next

        StrData = "WFMPRE:" & DATSRC & ":YOFF?"
        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        RD = Space(20)
        Ret = GpibInput(1, RD)
        If (Ret = 1) Then Exit Sub
        YOFF = Val(RD)

        StrData = "WFMPRE:" & DATSRC & ":YMULT?"
        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        RD = Space(20)
        Ret = GpibInput(1, RD)
        If (Ret = 1) Then Exit Sub
        YMULT = Val(RD)

        StrData = "WFMPRE:" & DATSRC & ":YUNIT?"
        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        YUNIT = Space(20)
        Ret = GpibInput(1, YUNIT)
        If (Ret = 1) Then Exit Sub

        StrData = "WFMPRE:" & DATSRC & ":PT_Off?"

        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        RD = Space(20)
        Ret = GpibInput(1, RD)
        If (Ret = 1) Then Exit Sub
        PtOff = Val(RD)

        StrData = "WFMPRE:" & DATSRC & ":XINCR?"
        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        RD = Space(20)
        Ret = GpibInput(1, RD)
        If (Ret = 1) Then Exit Sub
        XINCR = Val(RD)

        StrData = "WFMPRE:" & DATSRC & ":XUNIT?"
        Ret = GpibPrint(1, StrData)
        If (Ret = 1) Then Exit Sub
        XUNIT = Space(20)
        Ret = GpibInput(1, XUNIT)
        If (Ret = 1) Then Exit Sub

        WAVEFL = ".\WFM_DATA.CSV"
        FileOpen(1, WAVEFL, OpenMode.Output)
        Print(1, XUNIT)
        Print(1, YUNIT)
        PrintLine(1, "CH1")

        Dim VOLTARR(WFPOINTS) As Object
        Dim TIMEARR(WFPOINTS) As Object
        For i = 0 To WFPOINTS - 1
            TIMEARR(i) = (i - PtOff) * XINCR
            VOLTARR(i) = (IntData(i) - YOFF) * YMULT
            PrintLine(1, TIMEARR(i), ",", VOLTARR(i))
        Next i

        MsgBox("It was kept in the current drive. ")
        FileClose()

        'GCHandle free
        If gChByteData.IsAllocated = True Then
            gChByteData.Free()
        End If

    End Sub

    ' The amplitude of the wave shape is indicated. //////////////////////////////////////////////
    Private Sub Set_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Set_Renamed.Click
        Dim MEASSRC, WRT, MEASTYPE As String

        Ret = MsgBox("Connect the signal which it wants to acquire in ch1. ", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "Check probe")

        Ret = GpibPrint(Fstb(0), "HEADER OFF")
        If (Ret = 1) Then Exit Sub

        WRT = ":CH1:VOLTS 2E-1;POSITION 0;OFFSET 0;COUPLING AC"
        Ret = GpibPrint(Fstb(0), WRT)
        If (Ret = 1) Then Exit Sub
        WRT = ":CH1:IMPEDANCE MEG;BANDWIDTH FULL"
        Ret = GpibPrint(Fstb(0), WRT)
        If (Ret = 1) Then Exit Sub
        WRT = ":HORIZONTAL:MAIN:SCALE 2E-2"
        Ret = GpibPrint(Fstb(0), WRT)
        If (Ret = 1) Then Exit Sub
        WRT = ":SELECT:CH1 1"
        Ret = GpibPrint(Fstb(0), WRT)
        If (Ret = 1) Then Exit Sub

        MEASSRC = "CH1" : MEASTYPE = "AMPLITUDE"
        WRT = ":MEASUREMENT:MEAS1:SOURCE1 " & MEASSRC & ";TYPE " & MEASTYPE & ";STATE 1"
        Ret = GpibPrint(Fstb(0), WRT)
        If (Ret = 1) Then
            Exit Sub
        Else
            Call WaitOPC(Fstb(0))
        End If

        Ret = MsgBox("Amplitude was set on the display. ", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "Message")

        Ret = GpibPrint(Fstb(0), "UNLOCK ALL")
        If (Ret = 1) Then Exit Sub

    End Sub

    ' End //////////////////////////////////////////////////////////////////////////////////////
    Private Sub Exit_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Exit_Renamed.Click
        Ret = GpibExit()
        End
    End Sub

    Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed

        'GCHandle free
        If gChCmd.IsAllocated = True Then
            gChCmd.Free()
        End If
        If gChFstb.IsAllocated = True Then
            gChFstb.Free()
        End If

    End Sub
End Class