RIGOL Technologies

Welcome, Guest Login

Support Center

VB.NET basic instrument communication example

Last Updated: Dec 30, 2015 03:03PM PST
 
VB.NET 2010 example: VISABasic

We have created a small example to show how to remotely connect to an instrument using NI VISA.
This example allows you to establish a message-based VISA session with the instrument, send commands, and receive data from an instrument.
It utilizes .NET framework 4.0 and National Instruments VISA .
Here is the design of the form:

Added Controls Qty 1 Combo box: 
cboVISARsrc - Holds instrument VISA resource ID.
Qty 4 Buttons:   
btnOpen - Opens VISA session btnClose - Close VISA session btnWrite – Writes to instrument btnRead – Reads from instrument Qty 2 Text box
txtWrite– Textbox to hold command to write txtRead– Textbox to show read data
Code:

Imports NationalInstruments.VisaNS
'VISABasic is a small application created to give
'users an example of VISA based instrument communications.
'
'This app utilizes .NET Framework 4.0 and the associated National Instruments VISA Common and VISANS 'references.
'
'1) Enter VISA resource ID
'2) Press Open button to created new message based VISA session
'3) Enter instrument specific command in Command Window
'4) Press Send Button
'5) If the command is a query (terminating in a '?'), press Read to return instrument response
'
'This application is provided as-is. No support or warranty is expressed or implied.
'
'Author: JC
'Company: Rigol Technologies, North America
'Date: 09.09.2011 '
Public Class VISABasic
    Private mbSession As MessageBasedSession
    Private Sub btnOpen_Click _
        (ByVal sender As System.Object, ByVal e As System.EventArgs) _        
         Handles btnOpen.Click
        Dim strVISARsrc As String = cboVISARsrc.Text 'Set VISA resource ID
        Try
            mbSession = _
          CType(ResourceManager.GetLocalManager().Open(strVISARsrc), MessageBasedSession)             'Instantiate new message based VISA session
        Catch ex As InvalidCastException
            MessageBox.Show("Resource selected must be a message-based session")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub btnClose_Click _
        (ByVal sender As System.Object, ByVal e As System.EventArgs) _        
Handles btnClose.Click        
           mbSession.Dispose() 'Close VISA session
    End Sub
    Private Sub btnWrite_Click _
        (ByVal sender As System.Object, ByVal e As System.EventArgs) _         Handles btnWrite.Click
        Dim strWrite As String = txtWrite.Text
        Try             
              mbSession.Write(strWrite)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub btnRead_Click _
        (ByVal sender As System.Object, ByVal e As System.EventArgs) _        
        Handles btnRead.Click

        Dim strResponse As String
        Try
            strResponse = mbSession.ReadString()            
             txtRead.Text = strResponse        
         Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try     
End Sub
End Class



Figure 1: Project properties and references.

 

Login above for personalized content

Go to RIGOLna.com

License Activation

Firmware Updates

Product Registration

Contact Us

f14c465fd642ac49fa5a4bd437615e15@rigol.desk-mail.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete