‎06-15-2022 09:44 AM
Is there a way to find all intruments on a GPIB. I want to basically do what NI max does when you can view each instrument and then put the instuments in a array. I found this example but does not work for me. Any ideas on how I can do this.
Dim vs As NationalInstruments.VisaNS.ResourceManager Dim resources() As String vs = NationalInstruments.VisaNS.ResourceManager.GetLocalManager resources = vs.FindResources("GPIB?*INSTR")
‎06-15-2022 09:19 PM - edited ‎06-15-2022 09:20 PM
1. Reference Library
Added the following libraries (x.x depends on the version of VISA installed.)
2. Sample code
Public Sub test()
On Error Resume Next
Dim resources() As String
Dim RM_P As VisaComLib.ResourceManager
Set RM_P = New VisaComLib.ResourceManager
resources = RM_P.FindRsrc("?*")
Set RM_P = Nothing
MsgBox Join(resources, vbLf)
End Sub
‎06-16-2022 08:56 AM
Works great. thank you. How do you think I could add an IDN? to identify each intruments information?
‎06-16-2022 08:16 PM - edited ‎06-16-2022 08:43 PM
Sub communication_test1()
Dim RM As VisaComLib.ResourceManager
Dim VISACOMOBJ As VisaComLib.FormattedIO488
Dim return_string As String
Dim timeout As Long: timeout = 5000 '5000msec
Set RM = New VisaComLib.ResourceManager
Set VISACOMOBJ = New VisaComLib.FormattedIO488
Set VISACOMOBJ.IO = RM.Open("GPIB0::15::INSTR", NO_LOCK, timeout)
With VISACOMOBJ
.IO.timeout = timeout
.WriteString "*IDN?" & vbLf, True
return_string = Replace(Replace(.ReadString(), vbCr, ""), vbLf, "")
.IO.Close
End With
MsgBox return_string
End Sub
Sub communication_test2()
Dim RM As VisaComLib.ResourceManager
Dim VISACOMOBJ As VisaComLib.FormattedIO488
Dim list() As String
Dim timeout As Long: timeout = 5000 '5000msec
Set RM = New VisaComLib.ResourceManager
Set VISACOMOBJ = New VisaComLib.FormattedIO488
Set VISACOMOBJ.IO = RM.Open("GPIB0::15::INSTR", NO_LOCK, timeout)
With VISACOMOBJ
.IO.timeout = timeout
.WriteString "*IDN?" & vbLf, True
list = .ReadList(ASCIIType_BSTR, ",")
.IO.Close
End With
MsgBox Join(list, vbLf)
End Sub
Sub communication_test3()
Dim RM As VisaComLib.ResourceManager
Dim VISACOMOBJ As VisaComLib.FormattedIO488
Dim igpibDev As VisaComLib.igpib 'GPIB only
Dim list() As String
Dim timeout As Long: timeout = 5000 '5000msec
Set RM = New VisaComLib.ResourceManager
Set VISACOMOBJ = New VisaComLib.FormattedIO488
Set VISACOMOBJ.IO = RM.Open("GPIB0::15::INSTR", NO_LOCK, timeout)
Set igpibDev = VISACOMOBJ.IO
With igpibDev
.timeout = timeout
.ControlREN GPIB_REN_ADDRESS_AND_LLO
MsgBox "The measuring instrument has been locked out." & vbLf & "The instrument should be in a state where it does not accept any button operations other than the power supply." & vbLf & "Try pressing any buttons."
VISACOMOBJ.WriteString "*IDN?" & vbLf, True
list = VISACOMOBJ.ReadList(ASCIIType_BSTR, ",")
.ControlREN GPIB_REN_GTL_AND_DEASSERT
VISACOMOBJ.IO.Close
MsgBox "The lockout has been released."
End With
MsgBox Join(list, vbLf)
End Sub
‎04-03-2023 04:18 PM
Hi this is really useful - do you have a link to where you find the VisaCom Lib calls and how to use them in VBA? I understand more or less what you are doing but can't progress till I can read more general stuff. For me this is the simplest and most direct to control my instruments, which costs nothing and doesn't rely on LabVIEW!
‎04-03-2023 07:43 PM
A good reference for using VISA from VBA is Keysight's documentation. (Getting Started with Excel and VISA COM Instrument Control program)
Keysight recommends using it with VBA.
If you search with the keyword "keysight visa vba", you will find various other results, so please try it.
On the other hand, National Instruments does not expect it to be used from VBA.
Therefore, even if you search for it, you won't get many hits, but you can use VISA-COM with NI-VISA as it is by referring to Keysight's documents.
‎04-04-2023 03:18 AM
Thanks very much for your reply. This is the impression I had gained - Keysight positive and supportive, NI prefers to point users towards LabVIEW. I guess this is the corporate solution, and I do not dispute it! As well as the Keysight support I found a 'user Guide' produced by Agilent but this is 20 years old and I guess a bit out of date regarding present VISA status. But I think I can do what I need now, and I hope it will be portable (with a few mods) between most of the data acquisition PCs I use, which vary from XP to W11. Thanks again for your contribution!