Visual Basic 2005 Sample Program
Sample program of settings and queries 'Create VISA ResourceManager object Dim rm As New VisaComLib.ResourceManager Dim accessMode As VisaComLib.AccessMode = VisaComLib.AccessMode.NO_LOCK 'Serial number of the programmable AC/DC power source Dim serial As String = "0123456" Dim timeOut As Integer = 0 Dim optionString As String = "" 'Connect with the device Dim msg As VisaComLib.IMessage = CType( _ rm.Open("USB0::0x0D4A::12::" & serial & "::INSTR", _ accessMode, _ timeOut, _ optionString), _ VisaComLib.IMessage) 'Set the frequency as 50.0Hz, and ask the value msg.WriteString(":FREQ 50.0;:FREQ?" & vbLf) Console.WriteLine(msg.ReadString(256)) 'Close the device msg.Close()
Sample program of transferring ARB data 'Create VISA ResourceManager object Dim rm As VisaComLib.ResourceManager = New VisaComLib.ResourceManager Dim accessMode As VisaComLib.AccessMode = VisaComLib.AccessMode.NO_LOCK 'Serial number of the programmable AC/DC power source Dim serial As String = "0123456" Dim timeOut As Integer = 0 Dim optionString As String = "" 'Connect with the device Dim msg As VisaComLib.IMessage = CType( _ rm.Open("USB0::0x0D4A::12::" & serial & "::INSTR", _ accessMode, _ timeOut, _ optionString), _ VisaComLib.IMessage) 'Create the waveform data Dim buff(4095) As Integer Dim p As Double = 2 * Math.PI / 4096 For i As Integer = 0 To 4095 buff(i) = CType(Math.Sin(p * i) * 16383, Integer) Next 'Convert the message and the waveform data into byte data Dim data(9000) As Byte Dim j As Integer Dim arbCmd As String = ":TRACe ARB1,#48192" For j = 0 To Len(arbCmd) - 1 data(j) = Asc(Mid(arbCmd, j + 1, 1)) Next For i As Integer = 0 To 4095 Dim b As Byte = CType(((buff(i) \ &H100&) And &HFF), Byte) data(j) = b j = j + 1 b = CType((buff(i) And &HFF), Byte) data(j) = b j = j + 1 Next 'Transfer the data msg.Write(data, Len(arbCmd) + 8192) 'Close the device msg.Close()