RIGOL Technologies

Welcome, Guest Login

Support Center

VB.Net DG1022 example program: Load and run an Arbitrary Waveform

Last Updated: Dec 30, 2015 02:24PM PST
VB.NET 2010 example: DG1Arb

We have created a small example to show how to remotely program the Rigol DG1022.
This example allows you to establish a message-based VISA session with the instrument, load an aribitrary waveform into volatile memory, enable/disable the outputs, and save the waveform to nonvolatile memory.
It utilizes .NET framwork 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 6 Buttons:   
btnOpen - Opens VISA session
btnClose - Close VISA session
btnLoadArb   VISA session
btnOutpOn – Enables instrument output
btnOutpOff - Disables instrument output
btnSaveArb – Saves named arbitrary waveform to nonvolatile memory Qty 1 Text box
txtSaveFileName – Nonvolatile waveform name to save

Code:


Imports NationalInstruments.VisaNS
'DG1Arb is a small application created to give
'users a VB.Net example of loading and saving an arbitrary waveform
'into the Rigol  DG1022 Arbitrary Waveform Generator.
'
'The commands are also highlighted in the Arb Load example of the DG1022 Programming 'manual.
'
'This app utilizes .NET Framework 4.0 and the associated National Instruments VISA Common
'and VISANS references.
'
'1) Enter VISA resource ID.
'
'NOTE: A USB instrument resource ID will look like this:
'USB0::XXXX::YYYY::SSSSSS::INSTR
'where XXXX is the Vendor ID (VID), YYYYY is the Product ID (PID), and SSSS is the
'product identifier. Typically, Serial Number.
'
' See your VISA documentation for more information on valid VISA resource ID formats.
'
'2) Press Open button to created new message based VISA session
'3) Press Load Arb to load the predefined arbitrary points into the instruments volatile
'memory.
'4) Press Output On/Off to control the instrument output state.
'5) Enter the desired filename and press Save if you would like to save the waveform to
'nonvolatile memory.
'6) Press Close to end the VISA session prior to closing the active window.
'
'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 DG1Arb
    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         Try
            mbSession.Dispose() 'Close VISA session
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub btnLoadArb_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoadArb.Click         Try
            mbSession.Write("FUNC USER") 'Select User Defined Waveform             wait(10)
            mbSession.Write("FREQ 1000") 'Set repetition frequency             wait(10)
            mbSession.Write("VOLT:UNIT VPP") 'Set voltage amplitude units             wait(10)
            mbSession.Write("VOLT:HIGH 4") 'Set amplitude high             wait(20)
            mbSession.Write("VOLT:LOW -4") 'Set amplitude low             wait(20)
            mbSession.Write("DATA:DAC VOLATILE,8192,16383,8192,0") 'Set amplitude of
     'waveform points using bit value/point.
            'NOTE: This example is a 4 point arbitrary waveform.             wait(10)             mbSession.Write("FUNC:USER VOLATILE") 'Enable the volatile waveform.             Wait(10)
        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
    'Loops for a specificied period of time (milliseconds)
    'From Tom Reynard @ www.developerfusion.com
    Private Sub wait(ByVal interval As Integer)
        Dim sw As New Stopwatch
        sw.Start()
        Do While sw.ElapsedMilliseconds < interval
            ' Allows UI to remain responsive
            Application.DoEvents()         Loop         sw.Stop()     End Sub
    Private Sub btnOutpOn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOutpOn.Click         Try
            mbSession.Write("OUTP ON") 'Enable output
            wait(10)         Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub btnOutpOff_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOutpOff.Click         Try
            mbSession.Write("OUTP OFF") 'Disable output             wait(10)         Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub btnSaveArb_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSaveArb.Click         Try
            mbSession.Write("DATA:COPY " & txtSaveFileName.Text) 'Save waveform to nonvolatile memory             wait(10)         Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class


'END CODE



Figure 1:  References for use in VB.net 2010 for framework 4.
 
Login above for personalized content

RIGOL USA Web Site

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