Goal:
I have a Keysight E4980AL LCR meter that I am trying to get to read and record data into an Excel spreadsheet.Ideally, I would like to do this using VBA (I believe this is the easiest way to do this; i.e. requiring the least amount of setup). I have a test program already written in Excel using VBA (Visual Basic for Applications). The LCR meter is connected to my workstation using a GPIB-to-USB interface cable. I have the latest Keysight IO Library Suite installed (downloaded from here: .html), and the LCR meter is showing up under "Connection Expect" and displaying no issues. Finally, I have VISA-COM 5.14 Type Library enabled under Tools > References. Everything sounds good and well (at least so far).
Unfortunately, when I run my VBA test code, I get the following error message from Excel: "A connect error occurred: HRESULT = 80040011".
The dreaded error message.
I did some digging around on Excel's documentation and found that the 80040011 code meant that Excel was not able to convert the object in question
I did a whole bunch of F8's (debugging by stepping into the code) and pinpointed the error to this line:
Set instrAny.IO = ioMgr.Open(resourceString)
Here is the code that I am testing and running into the error message in:
Option Explicit
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Dim ioMgr As VisaComLib.ResourceManager
Dim instrAny As VisaComLib.FormattedIO488
Dim vba_version As String
Public Sub connect()
Dim resourceString As String
' address of instrument
resourceString = "GPIB0::17::INSTR"
vba_version = "8" 'vba version
On Error GoTo ioError
Control_flag = 1
Set ioMgr = New VisaComLib.ResourceManager
Set instrAny = New VisaComLib.FormattedIO488
Set instrAny.IO = ioMgr.Open(resourceString)
instrAny.WriteString ("*IDN?"), True
instrQuery = instrAny.ReadString
MsgBox "Connected to " & instrQuery & vbCrLf & "VBA version:" & vba_version & vbCrLf & "Interface:" & InterfaceIndex
Exit Sub
ioError:
MsgBox "A connect error occured:" & vbCrLf & Err.Description & vbCrLf & "Interface:" & InterfaceIndex & vbCrLf & "VBA version:" & vba_version
End Sub
So, when I run this connect()
macro, the earlier error message comes up. I want the actual result to be the MsgBox message.
I am not experienced in VISACOMLIB
, or Keysight's product line at all. However, I suspect there is a deeper, hidden issue here. I just don't have enough documentation, information, or knowledge to troubleshoot/debug this. It also doesn't help that there is barely any documentation to VisaComLib
on the internet at all. If someone can figure this out, they will have my eternal gratitude.
At this point, I'm not sure if this is an Excel problem, a VBA problem, or an issue with VisaComLib/Keysight driver problems. It might be something as simple as my VBA logic, which I hope is the case, as this would imply an easy fix. If it is a driver issue or something that I am missing, I can simply download it. The worst case scenario would be if VBA and/or GPIB functionality is no longer supported, in which case I would need to completely redo my approach (I hope to only do this as a last resort). As you can see, I need any and all help I can get from the programming gurus here at StackOverflow. Please help. Thanks.