using VBA to control a device

kit00

New Member
Joined
Jun 21, 2006
Messages
2
is it possible to control a device through GPIB interface using excel VBA?

thanks for answering my question^^

kit
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
and i also want to ask if it does, where can i find more info about it?

thanks again^^

kit
 
Upvote 0
Upvote 0
You will need to install 488.2 libraries from National Instrument (GPIB is also called IEEE 488.2). These libraries are utilized using the spreadsheet so you can communicated with the instrument.
 
Upvote 0
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
 
Upvote 0
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:

Code:
Function max_trace_value(gpib_address As String) As Variant
On Error GoTo ProcError

Dim sBuffer As String
Dim data_array As Variant
Dim xvalue As Variant
Dim yvalue As Variant
Dim i As Integer

    'check for missing arguments
    If gpib_address = "" Then
        Err.Raise (448)
    End If

    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
 
Upvote 0
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:

Code:
.
.
.

@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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,224,191
Messages
6,177,052
Members
452,757
Latest member
2010excel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top