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