Option Strict Off
Option Explicit On
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 End_Renamed As System.Windows.Forms.Button
	Public WithEvents SPoll As System.Windows.Forms.Button
	Public WithEvents Slave As System.Windows.Forms.Button
	Public WithEvents Master As System.Windows.Forms.Button
	Public WithEvents Init As System.Windows.Forms.Button
	Public WithEvents Poll As System.Windows.Forms.TextBox
	Public WithEvents Outp As System.Windows.Forms.TextBox
	Public WithEvents Inp As System.Windows.Forms.TextBox
	Public WithEvents Addr As System.Windows.Forms.TextBox
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label3 As System.Windows.Forms.Label
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Label1 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()
		Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
		Me.components = New System.ComponentModel.Container()
		Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
		Me.ToolTip1.Active = True
		Me.End_Renamed = New System.Windows.Forms.Button
		Me.SPoll = New System.Windows.Forms.Button
		Me.Slave = New System.Windows.Forms.Button
		Me.Master = New System.Windows.Forms.Button
		Me.Init = New System.Windows.Forms.Button
		Me.Poll = New System.Windows.Forms.TextBox
		Me.Outp = New System.Windows.Forms.TextBox
		Me.Inp = New System.Windows.Forms.TextBox
		Me.Addr = New System.Windows.Forms.TextBox
		Me.Label4 = New System.Windows.Forms.Label
		Me.Label3 = New System.Windows.Forms.Label
		Me.Label2 = New System.Windows.Forms.Label
		Me.Label1 = New System.Windows.Forms.Label
		Me.Text = "GpibTest"
		Me.ClientSize = New System.Drawing.Size(410, 194)
		Me.Location = New System.Drawing.Point(4, 23)
		Me.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation
		Me.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
		Me.ControlBox = True
		Me.Enabled = True
		Me.KeyPreview = False
		Me.MaximizeBox = True
		Me.MinimizeBox = True
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Me.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.ShowInTaskbar = True
		Me.HelpButton = False
		Me.WindowState = System.Windows.Forms.FormWindowState.Normal
		Me.Name = "Form1"
		Me.End_Renamed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.End_Renamed.Text = "Exit"
		Me.End_Renamed.Size = New System.Drawing.Size(73, 25)
		Me.End_Renamed.Location = New System.Drawing.Point(312, 152)
		Me.End_Renamed.TabIndex = 12
		Me.End_Renamed.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.End_Renamed.BackColor = System.Drawing.SystemColors.Control
		Me.End_Renamed.CausesValidation = True
		Me.End_Renamed.Enabled = True
		Me.End_Renamed.ForeColor = System.Drawing.SystemColors.ControlText
		Me.End_Renamed.Cursor = System.Windows.Forms.Cursors.Default
		Me.End_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.End_Renamed.TabStop = True
		Me.End_Renamed.Name = "End_Renamed"
		Me.SPoll.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.SPoll.Text = "SPoll"
		Me.SPoll.Size = New System.Drawing.Size(73, 25)
		Me.SPoll.Location = New System.Drawing.Point(312, 120)
		Me.SPoll.TabIndex = 11
		Me.SPoll.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.SPoll.BackColor = System.Drawing.SystemColors.Control
		Me.SPoll.CausesValidation = True
		Me.SPoll.Enabled = True
		Me.SPoll.ForeColor = System.Drawing.SystemColors.ControlText
		Me.SPoll.Cursor = System.Windows.Forms.Cursors.Default
		Me.SPoll.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.SPoll.TabStop = True
		Me.SPoll.Name = "SPoll"
		Me.Slave.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.Slave.Text = "Receive"
		Me.Slave.Size = New System.Drawing.Size(73, 25)
		Me.Slave.Location = New System.Drawing.Point(312, 88)
		Me.Slave.TabIndex = 10
		Me.Slave.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Slave.BackColor = System.Drawing.SystemColors.Control
		Me.Slave.CausesValidation = True
		Me.Slave.Enabled = True
		Me.Slave.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Slave.Cursor = System.Windows.Forms.Cursors.Default
		Me.Slave.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Slave.TabStop = True
		Me.Slave.Name = "Slave"
		Me.Master.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.Master.Text = "Send"
		Me.Master.Size = New System.Drawing.Size(73, 25)
		Me.Master.Location = New System.Drawing.Point(312, 56)
		Me.Master.TabIndex = 9
		Me.Master.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Master.BackColor = System.Drawing.SystemColors.Control
		Me.Master.CausesValidation = True
		Me.Master.Enabled = True
		Me.Master.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Master.Cursor = System.Windows.Forms.Cursors.Default
		Me.Master.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Master.TabStop = True
		Me.Master.Name = "Master"
		Me.Init.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.Init.Text = "Initialize "
		Me.Init.Size = New System.Drawing.Size(73, 25)
		Me.Init.Location = New System.Drawing.Point(312, 24)
		Me.Init.TabIndex = 8
		Me.Init.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Init.BackColor = System.Drawing.SystemColors.Control
		Me.Init.CausesValidation = True
		Me.Init.Enabled = True
		Me.Init.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Init.Cursor = System.Windows.Forms.Cursors.Default
		Me.Init.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Init.TabStop = True
		Me.Init.Name = "Init"
		Me.Poll.AutoSize = False
		Me.Poll.Size = New System.Drawing.Size(73, 25)
		Me.Poll.Location = New System.Drawing.Point(120, 128)
		Me.Poll.TabIndex = 3
		Me.Poll.Text = "Text4"
		Me.Poll.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Poll.AcceptsReturn = True
		Me.Poll.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
		Me.Poll.BackColor = System.Drawing.SystemColors.Window
		Me.Poll.CausesValidation = True
		Me.Poll.Enabled = True
		Me.Poll.ForeColor = System.Drawing.SystemColors.WindowText
		Me.Poll.HideSelection = True
		Me.Poll.ReadOnly = False
		Me.Poll.Maxlength = 0
		Me.Poll.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.Poll.MultiLine = False
		Me.Poll.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Poll.ScrollBars = System.Windows.Forms.ScrollBars.None
		Me.Poll.TabStop = True
		Me.Poll.Visible = True
		Me.Poll.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
		Me.Poll.Name = "Poll"
		Me.Outp.AutoSize = False
		Me.Outp.Size = New System.Drawing.Size(185, 25)
		Me.Outp.Location = New System.Drawing.Point(120, 96)
		Me.Outp.TabIndex = 2
		Me.Outp.Text = "Text3"
		Me.Outp.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Outp.AcceptsReturn = True
		Me.Outp.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
		Me.Outp.BackColor = System.Drawing.SystemColors.Window
		Me.Outp.CausesValidation = True
		Me.Outp.Enabled = True
		Me.Outp.ForeColor = System.Drawing.SystemColors.WindowText
		Me.Outp.HideSelection = True
		Me.Outp.ReadOnly = False
		Me.Outp.Maxlength = 0
		Me.Outp.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.Outp.MultiLine = False
		Me.Outp.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Outp.ScrollBars = System.Windows.Forms.ScrollBars.None
		Me.Outp.TabStop = True
		Me.Outp.Visible = True
		Me.Outp.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
		Me.Outp.Name = "Outp"
		Me.Inp.AutoSize = False
		Me.Inp.Size = New System.Drawing.Size(185, 25)
		Me.Inp.Location = New System.Drawing.Point(120, 64)
		Me.Inp.TabIndex = 1
		Me.Inp.Text = "Text2"
		Me.Inp.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Inp.AcceptsReturn = True
		Me.Inp.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
		Me.Inp.BackColor = System.Drawing.SystemColors.Window
		Me.Inp.CausesValidation = True
		Me.Inp.Enabled = True
		Me.Inp.ForeColor = System.Drawing.SystemColors.WindowText
		Me.Inp.HideSelection = True
		Me.Inp.ReadOnly = False
		Me.Inp.Maxlength = 0
		Me.Inp.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.Inp.MultiLine = False
		Me.Inp.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Inp.ScrollBars = System.Windows.Forms.ScrollBars.None
		Me.Inp.TabStop = True
		Me.Inp.Visible = True
		Me.Inp.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
		Me.Inp.Name = "Inp"
		Me.Addr.AutoSize = False
		Me.Addr.Size = New System.Drawing.Size(81, 25)
		Me.Addr.Location = New System.Drawing.Point(120, 32)
		Me.Addr.TabIndex = 0
		Me.Addr.Text = "Text1"
		Me.Addr.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Addr.AcceptsReturn = True
		Me.Addr.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
		Me.Addr.BackColor = System.Drawing.SystemColors.Window
		Me.Addr.CausesValidation = True
		Me.Addr.Enabled = True
		Me.Addr.ForeColor = System.Drawing.SystemColors.WindowText
		Me.Addr.HideSelection = True
		Me.Addr.ReadOnly = False
		Me.Addr.Maxlength = 0
		Me.Addr.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.Addr.MultiLine = False
		Me.Addr.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Addr.ScrollBars = System.Windows.Forms.ScrollBars.None
		Me.Addr.TabStop = True
		Me.Addr.Visible = True
		Me.Addr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
		Me.Addr.Name = "Addr"
		Me.Label4.Text = "SPoll"
		Me.Label4.Size = New System.Drawing.Size(49, 17)
		Me.Label4.Location = New System.Drawing.Point(32, 128)
		Me.Label4.TabIndex = 7
		Me.Label4.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopLeft
		Me.Label4.BackColor = System.Drawing.SystemColors.Control
		Me.Label4.Enabled = True
		Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label4.UseMnemonic = True
		Me.Label4.Visible = True
		Me.Label4.AutoSize = False
		Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.Label4.Name = "Label4"
		Me.Label3.Text = "ReceiveData"
		Me.Label3.Size = New System.Drawing.Size(73, 17)
		Me.Label3.Location = New System.Drawing.Point(32, 96)
		Me.Label3.TabIndex = 6
		Me.Label3.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label3.TextAlign = System.Drawing.ContentAlignment.TopLeft
		Me.Label3.BackColor = System.Drawing.SystemColors.Control
		Me.Label3.Enabled = True
		Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label3.UseMnemonic = True
		Me.Label3.Visible = True
		Me.Label3.AutoSize = False
		Me.Label3.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.Label3.Name = "Label3"
		Me.Label2.Text = "SendData"
		Me.Label2.Size = New System.Drawing.Size(65, 17)
		Me.Label2.Location = New System.Drawing.Point(32, 64)
		Me.Label2.TabIndex = 5
		Me.Label2.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopLeft
		Me.Label2.BackColor = System.Drawing.SystemColors.Control
		Me.Label2.Enabled = True
		Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label2.UseMnemonic = True
		Me.Label2.Visible = True
		Me.Label2.AutoSize = False
		Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.Label2.Name = "Label2"
		Me.Label1.Text = "Address"
		Me.Label1.Size = New System.Drawing.Size(49, 17)
		Me.Label1.Location = New System.Drawing.Point(32, 32)
		Me.Label1.TabIndex = 4
		Me.Label1.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopLeft
		Me.Label1.BackColor = System.Drawing.SystemColors.Control
		Me.Label1.Enabled = True
		Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label1.UseMnemonic = True
		Me.Label1.Visible = True
		Me.Label1.AutoSize = False
		Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.Label1.Name = "Label1"
		Me.Controls.Add(End_Renamed)
		Me.Controls.Add(SPoll)
		Me.Controls.Add(Slave)
		Me.Controls.Add(Master)
		Me.Controls.Add(Init)
		Me.Controls.Add(Poll)
		Me.Controls.Add(Outp)
		Me.Controls.Add(Inp)
		Me.Controls.Add(Addr)
		Me.Controls.Add(Label4)
		Me.Controls.Add(Label3)
		Me.Controls.Add(Label2)
		Me.Controls.Add(Label1)
	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 
	
	Const BDINDEX As Short = 0
	Const NO_SECONDARY_ADDR As Short = 0
	Const TIMEOUT As Short = T10s
	Const EOTMODE As Short = 1
	Const EOSMODE As Short = 0
	
    Const ARRAYSIZE As Short = 100                  ' Size of read buffer
	
	Dim ResByte As Short
	Dim Dev As Short
    Dim Valuestr As New String("", ARRAYSIZE)
	
    Dim ErrMsg As New String("", 100)
	Dim ErrorMnemonic As Object
	
	Private Sub End_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles End_Renamed.Click
		
		End
		
	End Sub
	
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		
		addr.Text = CStr(1)
		Inp.Text = "*IDN?"
		Outp.Text = ""
		Poll.Text = CStr(0)
		
	End Sub
	
	Private Sub Init_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Init.Click
		
		Dim pad As Short
		
		pad = CShort(addr.Text)
		Call ibdev(BDINDEX, pad, NO_SECONDARY_ADDR, TIMEOUT, EOTMODE, EOSMODE, Dev)
		
		If (ibsta And EERR) Then
            ErrMsg = "Unable to open device" & Chr(13) & "ibsta = &H" & Hex(ibsta) & Chr(13) & "iberr = " & iberr
            MsgBox(ErrMsg, MsgBoxStyle.Critical, "Error")
			End
		End If
		
	End Sub
	
	Private Sub Master_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Master.Click
		
		Call ibwrt(Dev, Inp.Text)
		
		If (ibsta And EERR) Then
			Call GPIBCleanup("Unable to write to device")
		End If
		
	End Sub
	
	Private Sub Slave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Slave.Click
		
        Call ibrd(Dev, Valuestr)
		
		If (ibsta And EERR) Then
			Call GPIBCleanup("Unable to read from device")
		End If
		
        Outp.Text = Mid(Valuestr, 1, ibcntl(0))
		
	End Sub
	
	Private Sub SPoll_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles SPoll.Click
		
		Call ibrsp(Dev, ResByte)
		
		If (ibsta And EERR) Then
			Call GPIBCleanup("Unable to serial poll")
		End If
		
        Poll.Text = ResByte.ToString
		
	End Sub
	
	Private Sub GPIBCleanup(ByRef msg As String)
		Dim ErrMsg As String
		
		' After each GPIB call, the application checks whether the call
		' succeeded. If an NI-488.2 call fails, the GPIB driver sets the
		' corresponding bit in the global status variable. If the call
		' failed, this procedure prints an error message, takes the device
		' offline and exits.
		
		ErrorMnemonic = New Object(){"EDVR", "ECIC", "ENOL", "EADR", "EARG", "ESAC", "EABO", "ENEB", "EDMA", "", "EOIP", "ECAP", "EFSO", "", "EBUS", "ESTB", "ESRQ", "", "", "", "ETAB"}
		
		ErrMsg = msg & Chr(13) & "ibsta = &H" & Hex(ibsta) & Chr(13) & "iberr = " & iberr & " <" & ErrorMnemonic(iberr) & ">"
		MsgBox(ErrMsg, MsgBoxStyle.Critical, "Error")
		
	End Sub
End Class