Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Imports VB = Microsoft.VisualBasic
Friend Class Form1
	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 Picture1 As System.Windows.Forms.PictureBox
	Public WithEvents TextRet As System.Windows.Forms.TextBox
	Public WithEvents DelData As System.Windows.Forms.Button
	Public WithEvents DelRet As System.Windows.Forms.Button
	Public WithEvents InitIalize As System.Windows.Forms.Button
	Public WithEvents ReceiveData As System.Windows.Forms.TextBox
	Public WithEvents SendData As System.Windows.Forms.TextBox
	Public WithEvents OscilloList As System.Windows.Forms.ComboBox
	Public WithEvents Ascii As System.Windows.Forms.RadioButton
    Public WithEvents Binary1 As System.Windows.Forms.RadioButton
	Public WithEvents Frame2 As System.Windows.Forms.GroupBox
	Public WithEvents YrAdrBox As System.Windows.Forms.ComboBox
	Public WithEvents Label1 As System.Windows.Forms.Label
	Public WithEvents Frame1 As System.Windows.Forms.GroupBox
	Public WithEvents Exit_Renamed As System.Windows.Forms.Button
	Public WithEvents Receive As System.Windows.Forms.Button
	Public WithEvents Send As System.Windows.Forms.Button
	Public WithEvents Label6 As System.Windows.Forms.Label
	Public WithEvents Label5 As System.Windows.Forms.Label
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label3 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.DelimBox = New System.Windows.Forms.ComboBox()
        Me.Picture1 = New System.Windows.Forms.PictureBox()
        Me.TextRet = New System.Windows.Forms.TextBox()
        Me.DelData = New System.Windows.Forms.Button()
        Me.DelRet = New System.Windows.Forms.Button()
        Me.InitIalize = New System.Windows.Forms.Button()
        Me.ReceiveData = New System.Windows.Forms.TextBox()
        Me.SendData = New System.Windows.Forms.TextBox()
        Me.OscilloList = New System.Windows.Forms.ComboBox()
        Me.Frame2 = New System.Windows.Forms.GroupBox()
        Me.Ascii = New System.Windows.Forms.RadioButton()
        Me.Binary1 = New System.Windows.Forms.RadioButton()
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.YrAdrBox = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Exit_Renamed = New System.Windows.Forms.Button()
        Me.Receive = New System.Windows.Forms.Button()
        Me.Send = New System.Windows.Forms.Button()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Frame2.SuspendLayout()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        '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() {"Not Use", "CR+LF", "CR", "LF"})
        Me.DelimBox.Location = New System.Drawing.Point(432, 56)
        Me.DelimBox.Name = "DelimBox"
        Me.DelimBox.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelimBox.Size = New System.Drawing.Size(113, 21)
        Me.DelimBox.TabIndex = 21
        '
        'Picture1
        '
        Me.Picture1.BackColor = System.Drawing.SystemColors.Control
        Me.Picture1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Picture1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Picture1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Picture1.Location = New System.Drawing.Point(24, 178)
        Me.Picture1.Name = "Picture1"
        Me.Picture1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Picture1.Size = New System.Drawing.Size(400, 200)
        Me.Picture1.TabIndex = 14
        '
        'TextRet
        '
        Me.TextRet.AcceptsReturn = True
        Me.TextRet.AutoSize = False
        Me.TextRet.BackColor = System.Drawing.SystemColors.Window
        Me.TextRet.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextRet.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextRet.Location = New System.Drawing.Point(98, 146)
        Me.TextRet.MaxLength = 0
        Me.TextRet.Name = "TextRet"
        Me.TextRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextRet.Size = New System.Drawing.Size(327, 24)
        Me.TextRet.TabIndex = 12
        Me.TextRet.Text = ""
        '
        'DelData
        '
        Me.DelData.BackColor = System.Drawing.SystemColors.Control
        Me.DelData.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelData.ForeColor = System.Drawing.SystemColors.ControlText
        Me.DelData.Location = New System.Drawing.Point(432, 176)
        Me.DelData.Name = "DelData"
        Me.DelData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelData.Size = New System.Drawing.Size(115, 25)
        Me.DelData.TabIndex = 5
        Me.DelData.Text = "Del &Data"
        '
        'DelRet
        '
        Me.DelRet.BackColor = System.Drawing.SystemColors.Control
        Me.DelRet.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelRet.ForeColor = System.Drawing.SystemColors.ControlText
        Me.DelRet.Location = New System.Drawing.Point(432, 144)
        Me.DelRet.Name = "DelRet"
        Me.DelRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelRet.Size = New System.Drawing.Size(115, 25)
        Me.DelRet.TabIndex = 4
        Me.DelRet.Text = "Del R&eturn"
        '
        'InitIalize
        '
        Me.InitIalize.BackColor = System.Drawing.SystemColors.Control
        Me.InitIalize.Cursor = System.Windows.Forms.Cursors.Default
        Me.InitIalize.ForeColor = System.Drawing.SystemColors.ControlText
        Me.InitIalize.Location = New System.Drawing.Point(432, 2)
        Me.InitIalize.Name = "InitIalize"
        Me.InitIalize.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.InitIalize.Size = New System.Drawing.Size(115, 25)
        Me.InitIalize.TabIndex = 3
        Me.InitIalize.Text = "&Initialize"
        '
        'ReceiveData
        '
        Me.ReceiveData.AcceptsReturn = True
        Me.ReceiveData.AutoSize = False
        Me.ReceiveData.BackColor = System.Drawing.SystemColors.Window
        Me.ReceiveData.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.ReceiveData.ForeColor = System.Drawing.SystemColors.WindowText
        Me.ReceiveData.Location = New System.Drawing.Point(98, 116)
        Me.ReceiveData.MaxLength = 0
        Me.ReceiveData.Name = "ReceiveData"
        Me.ReceiveData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ReceiveData.Size = New System.Drawing.Size(327, 24)
        Me.ReceiveData.TabIndex = 11
        Me.ReceiveData.Text = ""
        '
        'SendData
        '
        Me.SendData.AcceptsReturn = True
        Me.SendData.AutoSize = False
        Me.SendData.BackColor = System.Drawing.SystemColors.Window
        Me.SendData.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.SendData.ForeColor = System.Drawing.SystemColors.WindowText
        Me.SendData.Location = New System.Drawing.Point(98, 86)
        Me.SendData.MaxLength = 0
        Me.SendData.Name = "SendData"
        Me.SendData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.SendData.Size = New System.Drawing.Size(327, 24)
        Me.SendData.TabIndex = 10
        Me.SendData.Text = ""
        '
        'OscilloList
        '
        Me.OscilloList.BackColor = System.Drawing.SystemColors.Window
        Me.OscilloList.Cursor = System.Windows.Forms.Cursors.Default
        Me.OscilloList.ForeColor = System.Drawing.SystemColors.WindowText
        Me.OscilloList.Location = New System.Drawing.Point(98, 58)
        Me.OscilloList.Name = "OscilloList"
        Me.OscilloList.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.OscilloList.Size = New System.Drawing.Size(327, 21)
        Me.OscilloList.TabIndex = 9
        '
        'Frame2
        '
        Me.Frame2.BackColor = System.Drawing.SystemColors.Control
        Me.Frame2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Ascii, Me.Binary1})
        Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame2.Location = New System.Drawing.Point(212, 10)
        Me.Frame2.Name = "Frame2"
        Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame2.Size = New System.Drawing.Size(213, 45)
        Me.Frame2.TabIndex = 16
        Me.Frame2.TabStop = False
        Me.Frame2.Text = "Type of receive data"
        '
        'Ascii
        '
        Me.Ascii.BackColor = System.Drawing.SystemColors.Control
        Me.Ascii.Cursor = System.Windows.Forms.Cursors.Default
        Me.Ascii.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Ascii.Location = New System.Drawing.Point(120, 16)
        Me.Ascii.Name = "Ascii"
        Me.Ascii.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Ascii.Size = New System.Drawing.Size(59, 23)
        Me.Ascii.TabIndex = 2
        Me.Ascii.TabStop = True
        Me.Ascii.Text = "&Ascii"
        '
        'Binary1
        '
        Me.Binary1.BackColor = System.Drawing.SystemColors.Control
        Me.Binary1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Binary1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Binary1.Location = New System.Drawing.Point(48, 18)
        Me.Binary1.Name = "Binary1"
        Me.Binary1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Binary1.Size = New System.Drawing.Size(65, 19)
        Me.Binary1.TabIndex = 1
        Me.Binary1.TabStop = True
        Me.Binary1.Text = "&Binary"
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.YrAdrBox, Me.Label1})
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(8, 10)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(207, 45)
        Me.Frame1.TabIndex = 13
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "Address of device"
        '
        'YrAdrBox
        '
        Me.YrAdrBox.BackColor = System.Drawing.SystemColors.Window
        Me.YrAdrBox.Cursor = System.Windows.Forms.Cursors.Default
        Me.YrAdrBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.YrAdrBox.ForeColor = System.Drawing.SystemColors.WindowText
        Me.YrAdrBox.Location = New System.Drawing.Point(112, 14)
        Me.YrAdrBox.Name = "YrAdrBox"
        Me.YrAdrBox.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.YrAdrBox.Size = New System.Drawing.Size(49, 21)
        Me.YrAdrBox.TabIndex = 0
        '
        '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(20, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(89, 21)
        Me.Label1.TabIndex = 15
        Me.Label1.Text = "Addressing ="
        '
        '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(432, 208)
        Me.Exit_Renamed.Name = "Exit_Renamed"
        Me.Exit_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Exit_Renamed.Size = New System.Drawing.Size(115, 25)
        Me.Exit_Renamed.TabIndex = 8
        Me.Exit_Renamed.Text = "E&xit"
        '
        'Receive
        '
        Me.Receive.BackColor = System.Drawing.SystemColors.Control
        Me.Receive.Cursor = System.Windows.Forms.Cursors.Default
        Me.Receive.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Receive.Location = New System.Drawing.Point(432, 116)
        Me.Receive.Name = "Receive"
        Me.Receive.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Receive.Size = New System.Drawing.Size(115, 25)
        Me.Receive.TabIndex = 7
        Me.Receive.Text = "&Receive Data"
        '
        'Send
        '
        Me.Send.BackColor = System.Drawing.SystemColors.Control
        Me.Send.Cursor = System.Windows.Forms.Cursors.Default
        Me.Send.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Send.Location = New System.Drawing.Point(432, 86)
        Me.Send.Name = "Send"
        Me.Send.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Send.Size = New System.Drawing.Size(115, 25)
        Me.Send.TabIndex = 6
        Me.Send.Text = "&Send Data"
        '
        'Label6
        '
        Me.Label6.BackColor = System.Drawing.SystemColors.Control
        Me.Label6.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label6.Location = New System.Drawing.Point(432, 32)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(89, 17)
        Me.Label6.TabIndex = 22
        Me.Label6.Text = "Delimiter"
        '
        '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(8, 152)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(81, 15)
        Me.Label5.TabIndex = 20
        Me.Label5.Text = "Return code"
        '
        '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(8, 122)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(87, 15)
        Me.Label4.TabIndex = 19
        Me.Label4.Text = "Receive Data"
        '
        '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(8, 92)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(79, 15)
        Me.Label3.TabIndex = 18
        Me.Label3.Text = "Send Data"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(81, 17)
        Me.Label2.TabIndex = 17
        Me.Label2.Text = "Oscillo Type"
        '
        'Form1
        '
        Me.ClientSize = New System.Drawing.Size(550, 387)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DelimBox, Me.Picture1, Me.TextRet, Me.DelData, Me.DelRet, Me.InitIalize, Me.ReceiveData, Me.SendData, Me.OscilloList, Me.Frame2, Me.Frame1, Me.Exit_Renamed, Me.Receive, Me.Send, Me.Label6, Me.Label5, Me.Label4, Me.Label3, Me.Label2})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Location = New System.Drawing.Point(161, 150)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "Oscillo Scope"
        Me.Frame2.ResumeLayout(False)
        Me.Frame1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "Upgrade Support "
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
    Dim SendBuf As String                   'A sending buffer
    Dim RecvBuf As New String("", 10000)    'A receiving buffer
    Dim RecvBuf2(10000) As Byte             'An array of a receiving buffer
    Dim Adrs As Integer                     'It is used at the time of address making
    Dim ErrText As String                   'Text for display
    Dim Srlen As Integer                    'A length of a character string
    Dim Delim As Integer                    'Delimiter
    Dim gChCmd As GCHandle                  'GCHandle for cmd array
    Dim gChRecvBuf2 As GCHandle             'GCHandle for RecvBuf2 array
    Dim pRecvBuf2 As IntPtr                 'IntPtr for RecvBuf2 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


    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load '[ Form load ]

        For Adrs = 0 To 30                  'Making of Address of device
            YrAdrBox.Items.Add(CStr(Adrs))
        Next Adrs

        OscilloList.Items.Add("Tektronix 2440 OscilloScope")
        OscilloList.SelectedIndex = 0       'Initial setting
        YrAddr = 2                          'Initial setting
        Binary1.Checked = True               'Initial setting
        SendData.Text = "DATA ENCDG:RPBINARY;CURVE?"

        YrAdrBox.Text = CStr(1)             'Initial setting
        DelimBox.Text = "CR+LF"             'Initial setting

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

    End Sub

    Private Sub Initialize_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles InitIalize.Click '[ Initialize ]

        InitIalize.Enabled = False

        Ret = GpibInit(ErrText)
        TextRet.Text = ErrText

        If YrAdrBox.Items.Count = 31 Then   'MyAddress is deleted from a list.
            YrAdrBox.Items.RemoveAt((MyAddr))
            If MyAddr = YrAddr Then
                YrAdrBox.SelectedIndex = 0
            End If
        End If

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

    End Sub

    Private Sub Send_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Send.Click '[ Sending ]

        TextRet.Text = "It is data in sending."
        TextRet.Refresh()

        SendBuf = SendData.Text             'Acquisition of transmit data
        Srlen = Len(SendBuf)                'A length of transmit data
        If Srlen = 0 Then
            ErrText = "There is not transmit data."
            GoTo Err_Renamed
        End If
        Cmd(0) = 2
        Cmd(1) = MyAddr
        Cmd(2) = YrAddr
        Ret = GpTalk(pCmd, Srlen, SendBuf)    'Sending
        If CheckRet("GpTalk", Ret, ErrText) = 1 Then GoTo Err_Renamed
        Cmd(0) = 2                              'The number of a command
        Cmd(1) = &H3FS                          'Unlisten/UNL
        Cmd(2) = &H5FS                          'Untalken/UNT
        Ret = GpComand(pCmd)                  'Command sending
        If CheckRet("GpComand", Ret, ErrText) = 1 Then GoTo Err_Renamed
        ErrText = "Data sending was finished."
        Send.Enabled = False
        Receive.Enabled = True

Err_Renamed:
        TextRet.Text = ErrText

    End Sub


    Private Sub Receive_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Receive.Click '[ Receiving ]

        Dim TextBuf As String               'For a text
        Dim qwef As Short                   'It is used in graph drawing
        Dim qweb As Short                   'It is used in graph drawing
        Dim IfBinary As Boolean             'Binary receiving
        Dim st As Short                     'It is used in graph drawing
        Dim ed As Short                     'It is used in graph drawing
        Dim ch As String                    'Assignment
        Dim NumBuf As String                '1 data minute of receive data
        Dim ScaleGuideV As Short            'Width of picture
        Dim ScaleGuideH As Short            'It is an amount of picture
        Dim Num(5000) As Short              'They resolved data
        Dim i As Integer                    'It is used by FOR sentence
        Dim pen As New Drawing.Pen(System.Drawing.Color.Black, 1)

        TextRet.Text = "Data is receiving."
        TextRet.Refresh()                   'Redrawing of a screen
        IfBinary = Binary1.Checked           'A binary radio button selection

        ReceiveData.Text = ""               'Initialization

        Srlen = 10000                       'A length of receive data
        Cmd(0) = 2                          'The number of a command
        Cmd(1) = YrAddr                     'Address of device
        Cmd(2) = MyAddr                     'MyAddress
        If IfBinary = True Then             'A binary selection
            Ret = GpListenBinary(pCmd, Srlen, pRecvBuf2)      'In a binary type receiving
        Else
            Ret = GpListen(pCmd, Srlen, RecvBuf)              'In an ASCII model receiving
        End If
        If CheckRet("GpListen", Ret, ErrText) = 1 Then GoTo Err_Renamed

        TextBuf = "Data was done [ " & Srlen & " ] byte receiving."
        If Ret = 2 Then
            TextRet.Text = TextBuf & " And " & ErrText
        Else
            Cmd(0) = 2                      'The number of a command
            Cmd(1) = &H3FS                  'Unlisten/UNL
            Cmd(2) = &H5FS                  'Untalken/UNT
            Ret = GpComand(pCmd)          'Command sending
            If CheckRet("GpComand", Ret, ErrText) = 1 Then GoTo Err_Renamed
            TextRet.Text = TextBuf
        End If

        If IfBinary = True Then             'A binary selection
            ReceiveData.Text = ""
        Else
            ReceiveData.Text = VB.Left(RecvBuf, Srlen)          'A display of receive data
        End If

        '******************************************************* [Graph drawing] ***
        Dim Count2 As Integer

        Picture1.CreateGraphics.Clear(Color.LightGray)          'A screen is clear.
        Picture1.CreateGraphics.DrawLine(pen, 0, 0, 400, 0)     'It is a magnitude of graph.(Scale)
        Picture1.CreateGraphics.DrawLine(pen, 0, 0, 0, 200)     'It is a magnitude of graph.(Scale)
        ScaleGuideV = 10                'Adjustment of width
        ScaleGuideH = 20                'Adjustment of height

        For Count2 = 1 To ScaleGuideV   'A vertical axis is written.
            Picture1.CreateGraphics.DrawLine(pen, 0, Convert.ToInt32(200 / ScaleGuideV * Count2), 400, Convert.ToInt32(200 / ScaleGuideV * Count2))
        Next Count2
        For Count2 = 1 To ScaleGuideH   'A horizontal axis is written.
            Picture1.CreateGraphics.DrawLine(pen, Convert.ToInt32(400 / ScaleGuideH * Count2), 0, Convert.ToInt32(400 / ScaleGuideH * Count2), 200)
        Next Count2
        pen.Width = 2
        Picture1.CreateGraphics.DrawLine(pen, 0, 100, 400, 100)
        Picture1.CreateGraphics.DrawLine(pen, 200, 0, 200, 200)

        If IfBinary = True Then         'From binary data at graph drawing
            qweb = 0
            qwef = 0
            For i = 10 To Srlen
                qweb = RecvBuf2(i)
                qweb = 200 - qweb
                qwef = RecvBuf2(i + 1)
                qwef = 200 - qwef
                pen.Width = 1
                Picture1.CreateGraphics.DrawLine(pen, (i - 10), qweb, (i - 9), qwef)
            Next i
        Else
            st = 7                      'An acquiring character string is transition on series.
            ed = 0
            Cnt = 0
            For i = 7 To Srlen
                'ch = CStr(Asc(Mid(RecvBuf, i, 1)))          'They retrieve ","
                ch = RecvBuf.Substring(i, 1)
                'If CDbl(ch) = &H2CS Then 'ch = ","
                If ch = "," Then

                    ed = i
                    NumBuf = Mid(RecvBuf, st, ed - st)
                    Num(Cnt) = Val(NumBuf)                  'At the numeral which was picked out storage
                    Cnt = Cnt + 1
                    st = ed + 1
                End If
            Next i
            Try
                NumBuf = Mid(RecvBuf, ed, Srlen - ed)
            Catch ex As Exception When ed = 0
                NumBuf = ""
            End Try
            Num(Cnt) = Val(NumBuf)

            For i = 0 To Cnt - 1
                qweb = Num(i)
                qwef = Num(i + 1)
                pen.Width = 1
                Picture1.CreateGraphics.DrawLine(pen, i, 100 - qweb, i + 1, 100 - qwef)
            Next i
        End If

        Send.Enabled = True
        Receive.Enabled = False

Err_Renamed:
        TextRet.Text = ErrText

    End Sub

    Private Sub Ascii_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ascii.CheckedChanged
        If eventSender.Checked Then                     '[ In terms of a receiving type ASCII ]

            SendData.Text = "DATA ENCDG:ASCII;CURVE?"

        End If
    End Sub

    Private Sub Binary1_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Binary1.CheckedChanged
        If eventSender.Checked Then                     '[ In terms of a receiving type binary ]

            SendData.Text = "DATA ENCDG:RPBINARY;CURVE?"

        End If
    End Sub

    Private Sub DelData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelData.Click '[ A receive data erase ]

        ReceiveData.Text = ""

    End Sub

    Private Sub DelRet_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelRet.Click '[ At a returning value an erase ]

        TextRet.Text = ""

    End Sub

    Private Sub YrAdrBox_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles YrAdrBox.SelectedIndexChanged '[ Change of Address of device ]

        YrAddr = CInt(YrAdrBox.Text)                    'Acquisition of Address of device
        InitIalize.Enabled = True                       'At initialization effectiveness

    End Sub


    Private Sub Exit_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Exit_Renamed.Click '[ Exit ]

        Ret = GpibExit()
        Me.Close()

    End Sub

    Private Sub Help_Click()                            '[ Help ]

    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 gChRecvBuf2.IsAllocated = True Then
            gChRecvBuf2.Free()
        End If

    End Sub
End Class