Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
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 YrAdrBox As System.Windows.Forms.ComboBox
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Frame2 As System.Windows.Forms.GroupBox
	Public WithEvents Exit_Renamed As System.Windows.Forms.Button
	Public WithEvents Initialize As System.Windows.Forms.Button
	Public WithEvents DelRet As System.Windows.Forms.Button
	Public WithEvents TextRet As System.Windows.Forms.TextBox
	Public WithEvents DelSts As System.Windows.Forms.Button
	Public WithEvents Polling As System.Windows.Forms.Button
	Public WithEvents PollSts As System.Windows.Forms.TextBox
	Public WithEvents MyAddress As System.Windows.Forms.TextBox
	Public WithEvents Label1 As System.Windows.Forms.Label
	Public WithEvents Frame1 As System.Windows.Forms.GroupBox
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label3 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.Frame2 = New System.Windows.Forms.GroupBox()
        Me.YrAdrBox = New System.Windows.Forms.ComboBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Exit_Renamed = New System.Windows.Forms.Button()
        Me.Initialize = New System.Windows.Forms.Button()
        Me.DelRet = New System.Windows.Forms.Button()
        Me.TextRet = New System.Windows.Forms.TextBox()
        Me.DelSts = New System.Windows.Forms.Button()
        Me.Polling = New System.Windows.Forms.Button()
        Me.PollSts = New System.Windows.Forms.TextBox()
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.MyAddress = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Frame2.SuspendLayout()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Frame2
        '
        Me.Frame2.BackColor = System.Drawing.SystemColors.Control
        Me.Frame2.Controls.AddRange(New System.Windows.Forms.Control() {Me.YrAdrBox, Me.Label2})
        Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame2.Location = New System.Drawing.Point(274, 4)
        Me.Frame2.Name = "Frame2"
        Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame2.Size = New System.Drawing.Size(259, 47)
        Me.Frame2.TabIndex = 12
        Me.Frame2.TabStop = False
        Me.Frame2.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(136, 16)
        Me.YrAdrBox.Name = "YrAdrBox"
        Me.YrAdrBox.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.YrAdrBox.Size = New System.Drawing.Size(49, 21)
        Me.YrAdrBox.TabIndex = 13
        '
        '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(56, 20)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(79, 19)
        Me.Label2.TabIndex = 14
        Me.Label2.Text = "Address  ="
        '
        '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(390, 174)
        Me.Exit_Renamed.Name = "Exit_Renamed"
        Me.Exit_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Exit_Renamed.Size = New System.Drawing.Size(145, 25)
        Me.Exit_Renamed.TabIndex = 6
        Me.Exit_Renamed.Text = "E&xit"
        '
        '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(10, 174)
        Me.Initialize.Name = "Initialize"
        Me.Initialize.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Initialize.Size = New System.Drawing.Size(145, 23)
        Me.Initialize.TabIndex = 4
        Me.Initialize.Text = "&Initialize"
        '
        '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(296, 110)
        Me.DelRet.Name = "DelRet"
        Me.DelRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelRet.Size = New System.Drawing.Size(101, 25)
        Me.DelRet.TabIndex = 2
        Me.DelRet.Text = "Del &Return"
        '
        '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(8, 142)
        Me.TextRet.MaxLength = 0
        Me.TextRet.Name = "TextRet"
        Me.TextRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextRet.Size = New System.Drawing.Size(525, 24)
        Me.TextRet.TabIndex = 3
        Me.TextRet.Text = ""
        '
        'DelSts
        '
        Me.DelSts.BackColor = System.Drawing.SystemColors.Control
        Me.DelSts.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelSts.ForeColor = System.Drawing.SystemColors.ControlText
        Me.DelSts.Location = New System.Drawing.Point(186, 110)
        Me.DelSts.Name = "DelSts"
        Me.DelSts.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelSts.Size = New System.Drawing.Size(103, 25)
        Me.DelSts.TabIndex = 0
        Me.DelSts.Text = "Del &Status"
        '
        'Polling
        '
        Me.Polling.BackColor = System.Drawing.SystemColors.Control
        Me.Polling.Cursor = System.Windows.Forms.Cursors.Default
        Me.Polling.Enabled = False
        Me.Polling.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Polling.Location = New System.Drawing.Point(414, 104)
        Me.Polling.Name = "Polling"
        Me.Polling.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Polling.Size = New System.Drawing.Size(121, 35)
        Me.Polling.TabIndex = 5
        Me.Polling.Text = "&Polling"
        '
        'PollSts
        '
        Me.PollSts.AcceptsReturn = True
        Me.PollSts.AutoSize = False
        Me.PollSts.BackColor = System.Drawing.SystemColors.Window
        Me.PollSts.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.PollSts.ForeColor = System.Drawing.SystemColors.WindowText
        Me.PollSts.Location = New System.Drawing.Point(8, 76)
        Me.PollSts.MaxLength = 0
        Me.PollSts.Name = "PollSts"
        Me.PollSts.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.PollSts.Size = New System.Drawing.Size(525, 24)
        Me.PollSts.TabIndex = 1
        Me.PollSts.Text = ""
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.MyAddress, Me.Label1})
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(10, 4)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(267, 47)
        Me.Frame1.TabIndex = 8
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "Information"
        '
        'MyAddress
        '
        Me.MyAddress.AcceptsReturn = True
        Me.MyAddress.AutoSize = False
        Me.MyAddress.BackColor = System.Drawing.SystemColors.Window
        Me.MyAddress.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.MyAddress.ForeColor = System.Drawing.SystemColors.WindowText
        Me.MyAddress.Location = New System.Drawing.Point(156, 16)
        Me.MyAddress.MaxLength = 0
        Me.MyAddress.Multiline = True
        Me.MyAddress.Name = "MyAddress"
        Me.MyAddress.ReadOnly = True
        Me.MyAddress.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.MyAddress.Size = New System.Drawing.Size(31, 24)
        Me.MyAddress.TabIndex = 7
        Me.MyAddress.Text = ""
        Me.MyAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        '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(56, 20)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(97, 19)
        Me.Label1.TabIndex = 9
        Me.Label1.Text = "My Address ="
        '
        '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(10, 124)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(87, 15)
        Me.Label4.TabIndex = 11
        Me.Label4.Text = "Return value"
        '
        '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, 58)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(93, 17)
        Me.Label3.TabIndex = 10
        Me.Label3.Text = "Polling status"
        '
        'Form1
        '
        Me.ClientSize = New System.Drawing.Size(544, 206)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Frame2, Me.Exit_Renamed, Me.Initialize, Me.DelRet, Me.TextRet, Me.DelSts, Me.Polling, Me.PollSts, Me.Frame1, Me.Label4, Me.Label3})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Location = New System.Drawing.Point(54, 146)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "Polling (Serial Poll)"
        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 Pstb(15) As Integer             'An array of status byte
    Dim Adrs As Integer                 'It is used at the time of address making
    Dim ErrText As String               'Text for display
    Dim gChCmd As GCHandle              'GCHandle for cmd array
    Dim gChPstb As GCHandle             'GCHandle for Pstb array
    Dim pPstb As IntPtr                 'IntPtr for Pstb array
	
	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

        YrAdrBox.Text = CStr(1)         'Initial setting

        'Specify Pinned handle to Cmd
        If gChCmd.IsAllocated = False Then
            gChCmd = GCHandle.Alloc(Cmd, GCHandleType.Pinned)
        End If
        'Specify Pinned handle to Pstb
        If gChPstb.IsAllocated = False Then
            gChPstb = GCHandle.Alloc(Pstb, GCHandleType.Pinned)
        End If
        'Get address object by Pinned handle
        pCmd = gChCmd.AddrOfPinnedObject()
        pPstb = gChPstb.AddrOfPinnedObject()
		
	End Sub
	
	Private Sub Initialize_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Initialize.Click '[ Initialize ]
		
        Ret = GpibInit(ErrText)         'SubClass.bas
		If Ret = 1 Then GoTo Err_Renamed
		
		MyAddress.Text = CStr(MyAddr)
		Polling.Enabled = True
		
		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
		
		If Mode = 1 Then ErrText = "This device is not a master."
		GoTo Err_Renamed
		
Err_Renamed: 'If an error was detected, it is displayed.
		TextRet.Text = ErrText
		
	End Sub
	
	Private Sub Polling_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Polling.Click '[ Polling ]
		
        For Cnt = 0 To 15               'Initialization of parameter
            Pstb(Cnt) = 0
        Next

        PollSts.Text = ""
        TextRet.Text = "Polling..."
        TextRet.Refresh()

        Cmd(0) = 1
        Cmd(1) = YrAddr
        Ret = GpPoll(pCmd, pPstb)   'Serial-poll performance
        If CheckRet("GpPoll", Ret, ErrText) = 1 Then
            GoTo Err_Renamed
        ElseIf CheckRet("GpPoll", Ret, ErrText) = 2 Then
            ErrText = "There was not [SRQ]."
            GoTo Err_Renamed
        End If
        PollSts.Text = "Talker address = [ " & Cmd(Pstb(0)) & " ] StatusByte = [" & Hex(Pstb(Pstb(0))) & " ] H"
        TextRet.Text = "[SRQ] was confirmation."
Err_Renamed:
        TextRet.Text = ErrText
		
	End Sub
	
    Private Sub yradrbox_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles YrAdrBox.SelectedIndexChanged '[ Change of Address of device address ]

        YrAddr = CInt(YrAdrBox.Text)

    End Sub

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

        TextRet.Text = ""

    End Sub

    Private Sub DelSts_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelSts.Click '[ An erase of polling status ]

        PollSts.Text = ""

    End Sub

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

        Ret = GpibExit()                'SubClass.bas
        Me.Close()

    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

    End Sub
End Class