Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

How to get VISA GPIB to work in Excel, Excel VBA, VB6 or Visual Basic 6

' VISA GPIB driver methods using NI or Agilent GPIB drivers.
' For visual basic 6, VB6 or ExcelVBA or Excel VBA
Private Sub cmdRUN_Click()
' How to get the visacom driver working with the latest IVIfoundation
' drivers.
' ******************************************************************
' In project reference do not forget to add as a project reference
' VISA COM 3.0 Type Library
' ******************************************************************
' Using this method you get very fine grain control
Dim Result As String
Dim VGaddress As String
Dim ioMgr As VisaComLib.ResourceManager
Set ioMgr = New VisaComLib.ResourceManager
Dim VGb As VisaComLib.FormattedIO488
Set VGb = New VisaComLib.FormattedIO488
Rem VGaddress =
Rem VGadress = "visa://192.168.3.25/GPIB0::22::INSTR" ' Or
Rem VGadress = "GPIB0::2::INSTR"
Rem not valid for RS232 serial GPIB connections
VGaddress = Trim(Text_input.Text)
' trim the result from the text box to remove spaces
Label_output.Caption = "Talking to address :: " + VGaddress + vbLf
Set VGb.IO = ioMgr.Open(VGaddress)
VGb.IO.Timeout = 10000
VGb.WriteString ("*IDN?") ' write SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Sending IEC bus command *IDN? " + vbLf
Result = VGb.ReadString ' READ SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Information return by instrument " + vbLf
Label_output.Caption = Label_output.Caption + Result + vbLf
VGb.IO.Close
End Sub

Private Sub cmdOther_method_click()
' This is the other method of access the VISA GPIB devices has less control
' but easier to work with in VB
' ******************************************************************
' In project reference do not forget to add as a project reference
' VISA COM 3.0 Type Library
' ******************************************************************
Dim rm As IResourceManager
Dim msg As IMessage
Dim Result As String
Dim VisaAddress As String
Rem VisaAdress = "visa://192.168.3.25/GPIB0::22::INSTR" ' Or
Rem VisaAdress = "GPIB0::2::INSTR"
Rem not valid for RS232 serial GPIB connections

VisaAddress = Trim(Text_input.Text)
' trim the result from the text box to remove spaces
Label_output.Caption = "Talking to address :: " + VisaAddress + vbLf
Set rm = CreateObject("VISA.GlobalRM")' Set visagpib connection
Set msg = rm.Open(VisaAdress, NO_LOCK, 2000, "") ' Timeout=2000mS max 3000mS
msg.Clear
msg.WriteString "*IDN?" & vbLf ' write SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Sending IEC bus command *IDN? " + vbLf
Result = msg.ReadString(256) ' READ SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Information return by instrument " + vbLf
Label_output.Caption = Label_output.Caption + Result + vbLf
End Sub


This is just posting to help other learn. No answer is required

0 Kudos
Message 1 of 3
(15,742 Views)

do I need to add any resources to allow below commands.

Dim rm As IResourceManager
Dim msg As IMessage

 

I'm using Windows XP and Windows 2010 Excel to run this VB script but encounter many errors.

0 Kudos
Message 2 of 3
(14,687 Views)

Could you provide the same for RS232, or USB in excel VBA, or is there a way to view the whole library for quick adaptation.

Any help would be greatly appreciated.

Thanks

0 Kudos
Message 3 of 3
(13,485 Views)