⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 一个用vb编写的gpib例子,希望对大家编程有帮助
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    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

    '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.
    Friend WithEvents label6 As System.Windows.Forms.Label
    Friend WithEvents CWGPIB1 As AxCWInstrumentControlLib.AxCWGPIB
    Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents writeButton As System.Windows.Forms.Button
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents sendString As System.Windows.Forms.TextBox
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents label3 As System.Windows.Forms.Label
    Friend WithEvents label4 As System.Windows.Forms.Label
    Friend WithEvents label5 As System.Windows.Forms.Label
    Friend WithEvents configureButton As System.Windows.Forms.Button
    Friend WithEvents receivedString As System.Windows.Forms.TextBox
    Friend WithEvents readButton As System.Windows.Forms.Button
    Friend WithEvents label2 As System.Windows.Forms.Label
    Friend WithEvents PAD As AxCWUIControlsLib.AxCWNumEdit
    Friend WithEvents SAD As AxCWUIControlsLib.AxCWNumEdit
    Friend WithEvents Board As AxCWUIControlsLib.AxCWNumEdit
    Friend WithEvents ClearButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.label6 = New System.Windows.Forms.Label()
        Me.CWGPIB1 = New AxCWInstrumentControlLib.AxCWGPIB()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.writeButton = New System.Windows.Forms.Button()
        Me.label1 = New System.Windows.Forms.Label()
        Me.sendString = New System.Windows.Forms.TextBox()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.Board = New AxCWUIControlsLib.AxCWNumEdit()
        Me.SAD = New AxCWUIControlsLib.AxCWNumEdit()
        Me.PAD = New AxCWUIControlsLib.AxCWNumEdit()
        Me.label3 = New System.Windows.Forms.Label()
        Me.label4 = New System.Windows.Forms.Label()
        Me.label5 = New System.Windows.Forms.Label()
        Me.configureButton = New System.Windows.Forms.Button()
        Me.receivedString = New System.Windows.Forms.TextBox()
        Me.readButton = New System.Windows.Forms.Button()
        Me.label2 = New System.Windows.Forms.Label()
        Me.ClearButton = New System.Windows.Forms.Button()
        CType(Me.CWGPIB1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.groupBox2.SuspendLayout()
        Me.groupBox1.SuspendLayout()
        CType(Me.Board, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.SAD, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PAD, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'label6
        '
        Me.label6.Location = New System.Drawing.Point(16, 8)
        Me.label6.Name = "label6"
        Me.label6.Size = New System.Drawing.Size(248, 56)
        Me.label6.TabIndex = 15
        Me.label6.Text = "Select the Board, Primary Address (PAD), and Secondary Address (PAD) of your GPIB" & _
        " device and press the Configure button."
        '
        'CWGPIB1
        '
        Me.CWGPIB1.Enabled = True
        Me.CWGPIB1.Location = New System.Drawing.Point(288, 8)
        Me.CWGPIB1.Name = "CWGPIB1"
        Me.CWGPIB1.OcxState = CType(resources.GetObject("CWGPIB1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.CWGPIB1.Size = New System.Drawing.Size(32, 32)
        Me.CWGPIB1.TabIndex = 16
        '
        'groupBox2
        '
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.writeButton, Me.label1, Me.sendString})
        Me.groupBox2.Location = New System.Drawing.Point(8, 200)
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(352, 72)
        Me.groupBox2.TabIndex = 18
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "Writing"
        '
        'writeButton
        '
        Me.writeButton.Enabled = False
        Me.writeButton.Location = New System.Drawing.Point(256, 24)
        Me.writeButton.Name = "writeButton"
        Me.writeButton.Size = New System.Drawing.Size(72, 32)
        Me.writeButton.TabIndex = 4
        Me.writeButton.Text = "Write"
        '
        'label1
        '
        Me.label1.Location = New System.Drawing.Point(16, 24)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(80, 16)
        Me.label1.TabIndex = 2
        Me.label1.Text = "Send String"
        '
        'sendString
        '
        Me.sendString.Location = New System.Drawing.Point(112, 24)
        Me.sendString.Name = "sendString"
        Me.sendString.Size = New System.Drawing.Size(120, 20)
        Me.sendString.TabIndex = 1
        Me.sendString.Text = "*IDN?"
        '
        'groupBox1
        '
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Board, Me.SAD, Me.PAD, Me.label3, Me.label4, Me.label5, Me.configureButton})
        Me.groupBox1.Location = New System.Drawing.Point(8, 72)
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(352, 112)
        Me.groupBox1.TabIndex = 17
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Configuration"
        '
        'Board
        '
        Me.Board.ContainingControl = Me
        Me.Board.Location = New System.Drawing.Point(56, 28)
        Me.Board.Name = "Board"
        Me.Board.OcxState = CType(resources.GetObject("Board.OcxState"), System.Windows.Forms.AxHost.State)
        Me.Board.Size = New System.Drawing.Size(81, 24)
        Me.Board.TabIndex = 15
        '
        'SAD
        '
        Me.SAD.ContainingControl = Me
        Me.SAD.Location = New System.Drawing.Point(240, 64)
        Me.SAD.Name = "SAD"
        Me.SAD.OcxState = CType(resources.GetObject("SAD.OcxState"), System.Windows.Forms.AxHost.State)
        Me.SAD.Size = New System.Drawing.Size(81, 24)
        Me.SAD.TabIndex = 14
        '
        'PAD
        '
        Me.PAD.ContainingControl = Me
        Me.PAD.Location = New System.Drawing.Point(240, 28)
        Me.PAD.Name = "PAD"
        Me.PAD.OcxState = CType(resources.GetObject("PAD.OcxState"), System.Windows.Forms.AxHost.State)
        Me.PAD.Size = New System.Drawing.Size(81, 24)
        Me.PAD.TabIndex = 13
        '
        'label3
        '
        Me.label3.Location = New System.Drawing.Point(8, 32)
        Me.label3.Name = "label3"
        Me.label3.Size = New System.Drawing.Size(48, 16)
        Me.label3.TabIndex = 10
        Me.label3.Text = "Board"
        '
        'label4
        '
        Me.label4.Location = New System.Drawing.Point(152, 32)
        Me.label4.Name = "label4"
        Me.label4.Size = New System.Drawing.Size(88, 16)
        Me.label4.TabIndex = 11
        Me.label4.Text = "Instrument PAD"
        '
        'label5
        '
        Me.label5.Location = New System.Drawing.Point(152, 68)
        Me.label5.Name = "label5"
        Me.label5.Size = New System.Drawing.Size(88, 16)
        Me.label5.TabIndex = 12
        Me.label5.Text = "Instrument SAD"
        '
        'configureButton
        '
        Me.configureButton.Location = New System.Drawing.Point(64, 64)
        Me.configureButton.Name = "configureButton"
        Me.configureButton.Size = New System.Drawing.Size(72, 32)
        Me.configureButton.TabIndex = 3
        Me.configureButton.Text = "Configure"
        '
        'receivedString
        '
        Me.receivedString.Location = New System.Drawing.Point(128, 312)
        Me.receivedString.Multiline = True
        Me.receivedString.Name = "receivedString"
        Me.receivedString.Size = New System.Drawing.Size(136, 88)
        Me.receivedString.TabIndex = 20
        Me.receivedString.Text = ""
        '
        'readButton
        '
        Me.readButton.Enabled = False
        Me.readButton.Location = New System.Drawing.Point(32, 288)
        Me.readButton.Name = "readButton"
        Me.readButton.Size = New System.Drawing.Size(72, 32)
        Me.readButton.TabIndex = 19
        Me.readButton.Text = "Read"
        '
        'label2
        '
        Me.label2.Location = New System.Drawing.Point(128, 288)
        Me.label2.Name = "label2"
        Me.label2.Size = New System.Drawing.Size(96, 16)
        Me.label2.TabIndex = 21
        Me.label2.Text = "String Received"
        '
        'ClearButton
        '
        Me.ClearButton.Location = New System.Drawing.Point(32, 336)
        Me.ClearButton.Name = "ClearButton"
        Me.ClearButton.Size = New System.Drawing.Size(72, 32)
        Me.ClearButton.TabIndex = 22
        Me.ClearButton.Text = "Clear"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(376, 429)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ClearButton, Me.receivedString, Me.readButton, Me.label2, Me.groupBox2, Me.groupBox1, Me.CWGPIB1, Me.label6})
        Me.Name = "Form1"
        Me.Text = "Simple GPIB Communication"
        CType(Me.CWGPIB1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.groupBox2.ResumeLayout(False)
        Me.groupBox1.ResumeLayout(False)
        CType(Me.Board, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.SAD, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PAD, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub configureButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles configureButton.Click

        ' Set the board number, the primary address, and the secondary address.
        ' Notice you must convert the data to the correct data type for the CWGPIB control.
        CWGPIB1.Reset()
        CWGPIB1.BoardNumber = Board.Value
        CWGPIB1.PrimaryAddress = PAD.Value
        CWGPIB1.SecondaryAddress = SAD.Value

        ' Now configure the GPIB system.
        CWGPIB1.Configure()

        ' Now that it's enabled, allow the user to write and read.
        writeButton.Enabled = True
        readButton.Enabled = True

    End Sub

    Private Sub writeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeButton.Click
        ' Write to the GPIB instrument.  Write the text in the sendString field.
        CWGPIB1.Write(sendString.Text)
    End Sub

    Private Sub readButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles readButton.Click
        ' Read 100 bytes from the instrument and place the string in
        ' the receivedString field.
        receivedString.Text = CWGPIB1.Read(100)
    End Sub

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
        ' Clear the contents of the receivedString field.
        receivedString.Clear()
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -