902 Keysight InfiniiVision DSOX1204A/G Oscilloscopes Programmer's Guide
36 Programming Examples
Dim VISA_ADDRESS As String = "USB0::0x2A8D::0x1797::CN56240004::0:
:INSTR"
' Create a connection (session) to the instrument
Dim session As IMessageBasedSession
Try
session = TryCast(GlobalResourceManager.Open(VISA_ADDRESS), _
IMessageBasedSession)
Catch visaException As NativeVisaException
Console.WriteLine("Couldn't connect.")
Console.WriteLine("Error is:" & vbCr & vbLf & "{0}" _
& vbCr & vbLf, visaException)
Console.WriteLine("Press any key to exit...")
Console.ReadKey()
Return
End Try
' Create a formatted I/O object which will help us format the
' data we want to send/receive to/from the instrument
Dim myScope As New MessageBasedFormattedIO(session)
' For Serial and TCP/IP socket connections enable the read
' Termination Character, or read's will timeout
If session.ResourceName.Contains("ASRL") OrElse _
session.ResourceName.Contains("SOCKET") Then
session.TerminationCharacterEnabled = True
End If
session.TimeoutMilliseconds = 20000
' Initialize - start from a known state.
' ==============================================================
Dim strResults As String
Dim fStream As FileStream
' Get and display the device's *IDN? string.
myScope.WriteLine("*IDN?")
strResults = myScope.ReadLine()
Console.WriteLine("*IDN? result is: {0}", strResults)
' Clear status and load the default setup.
myScope.WriteLine("*CLS")
myScope.WriteLine("*RST")
' Capture data.
' ==============================================================
' Use auto-scale to automatically configure oscilloscope.
myScope.WriteLine(":AUToscale")
' Set trigger mode (EDGE, PULSe, PATTern, etc., and input source.
myScope.WriteLine(":TRIGger:MODE EDGE")
myScope.WriteLine(":TRIGger:MODE?")
strResults = myScope.ReadLine()
Console.WriteLine("Trigger mode: {0}", strResults)
' Set EDGE trigger parameters.
myScope.WriteLine(":TRIGger:EDGE:SOURce CHANnel1")