JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
is it possible to control a device through GPIB interface using excel VBA?
thanks for answering my question^^
National Instruments website has an example spreadsheet that can accomplish this:
http://zone.ni.com/devzone/cda/epd/p/id/798
I've expanded the ni-488.2_in_excel.xls spreadsheet from this website to do just about anything you want to with test equipment over GPIB.
-Brian
National Instruments website has an example spreadsheet that can accomplish this:
Calling NI-488.2 Functions Directly in Excel - Developer Zone - National Instruments
I've expanded the ni-488.2_in_excel.xls spreadsheet from this website to do just about anything you want to with test equipment over GPIB.
-Brian
Brian
any chance I could get a copy of your code -- I was unable to get NI's spreadsheet to load..
I realize this is a very old thread, but thinking my recent experience may benefit someone...
I'm pretty green with VBA. I have some work that may benefit from it so I decided to see if I could get from point A to point B. Unfortunately, point B is a very, very long way from point A. I know even less about GPIB control so it's been tough slogging.
I tried to run the linked code as well, with no success. I have Office 2010/Win 7 and when trying to open the .xls file, I received the following window: "Opening the VBA project in this file requires a component that is not currently installed. This file will be opened without the VBA project. For more information, search Microsoft Office Online for "VBA converters." ". I went to the website and because it's changed over time, was not able to find what I needed.
I was just about ready to throw in the towel when I Googled for "office.com VBA converters", which led me to:
https://support.microsoft.com/en-us/kb/926430
Follow the instructions and you will be able to load the .xls file and the offending .bas files.
With one annoying problem...
In my case, two of the VBA modules refused to load. "SampleCode.bas" would load. "vbib-32.bas" and "niglobal.bas" would not.
As I said, I have no experience with this stuff so I'm still fumbling about. Through trial and error, I was able to look over "SampleCode.bas" and make alterations that worked for the other two files.
First, change the name of "vbib-32.bas" to "vbib_32.bas" or similar. For some reason, Excel does not like the hyphen.
Next, open each of the two files with Notebook and change the first lines, eliminating ".bas". Also, make sure the name on that first line matches the filename. For example, if your filename is changed to "vbib_32.bas", the first line of that file should be " Attribute VB_Name = "vbib_32" " (eliminate outside double quote marks).
If you follow the instructions on the link I've provided, you'll at least be able to get the modules reloaded and can begin trying to make them work. That's where I am at this point so I really can't tell you anything else.
I just wanted to help anyone, who like me, is frustrated trying to use the ni example.
-Grub
Grub,
Since my initial post, I have started using a method of controlling GPIB that doesn't need to use any of National Instruments libraries. It only requires that the National Instrumments 488.2 software be installed and the "VISA COM 3.0 Type Library" added as a reference. Agilent (Keysight) has some good examples of how to use the VISA COM Library also.
Below is some example code that I used to get the max trace value from an FSU spectrum analyzer:
Dim ioMgr As VisaComLib.ResourceManager
Dim Equip As VisaComLib.FormattedIO488
Set ioMgr = New VisaComLib.ResourceManager
Set Equip = New VisaComLib.FormattedIO488
'set mouse to hourglass when making measurement
Screen.MousePointer = vbHourglass
Set Equip.IO = ioMgr.Open("GPIB0::" & gpib_address & "::INSTR")
'set timeout
Equip.IO.Timeout = 100000 '100 seconds
Equip.WriteString "SYST:DISP:UPD ON" 'keep the display ON while in remote mode
'Turn off any existing markers
Equip.WriteString "CALC:MARK1 OFF"
Equip.WriteString "CALC:MARK2 OFF"
Equip.WriteString "CALC:MARK3 OFF"
Equip.WriteString "CALC:MARK4 OFF"
'Measure Max Trace Value
'Clear the trace
Equip.WriteString "DISP:TRAC:CLE"
'turn OFF continuous sweep
Equip.WriteString "INIT:CONT OFF"
'Max Hold the trace
Equip.WriteString "DISP:TRAC:MODE MAXH"
'Wait 5 seconds for trace to max hold
'Wait (5)
Equip.WriteString "CALC:MARK1 ON" 'turn on Marker 1
Equip.WriteString "INIT;*OPC?" 'wait until sweep is finished
Equip.WriteString "CALC:MARK1:MAX" 'find maximum value
Equip.WriteString "CALC:MARK1:X?" 'measure the marker y value
'read response and store in sBuffer
sBuffer = Equip.ReadString
data_array = Split(sBuffer, Chr(10))
yvalue = data_array(0)
Equip.WriteString "CALC:MARK1:Y?" 'measure the marker y value
'read response and store in sBuffer
sBuffer = Equip.ReadString
data_array = Split(sBuffer, Chr(10))
xvalue = data_array(0)
max_trace_value = Array(xvalue, yvalue)
'close equipment
Equip.IO.Close
'set mouse back to default
Screen.MousePointer = vbDefault
Exit Function
ProcError:
MsgBox "The following error occured in ATELIB.DLL FSU module: " & Err.Description
End Function
Grub,
Since my initial post, I have started using a method of controlling GPIB that doesn't need to use any of National Instruments libraries. It only requires that the National Instrumments 488.2 software be installed and the "VISA COM 3.0 Type Library" added as a reference. Agilent (Keysight) has some good examples of how to use the VISA COM Library also.
Below is some example code that I used to get the max trace value from an FSU spectrum analyzer:
@bhenard,
Thank you for the response. I'd been wondering how VISA might be used. I hadn't tripped over anything yet (that I understood), explaining it. I will look over your code to see if it might work better. Expect me to come back with some very noobish questions.
Are there any drawbacks to using VISA, compared to the NI Libraries?
-Grub
Thank you for the response. I'd been wondering how VISA might be used. I hadn't tripped over anything yet (that I understood), explaining it. I will look over your code to see if it might work better. Expect me to come back with some very noobish questions.
Are there any drawbacks to using VISA, compared to the NI Libraries?
-Grub
The NI VB modules that are included in NI's example spreadsheet are visual basic wrappers for VISA. Since the VISA COM library now has all of that functionality included, there is no need to use a wrapper for those functions. Basically, it is 2 different ways to use the same VISA library. I would rather not include a wrapper in all of my spreadsheets if it is not needed, so I would recommend just using the VISA COM reference library directly when issuing GPIB commands.