Author Topic: Excel - Visual Basic - Tektronix data transfer via USB  (Read 6362 times)

0 Members and 3 Guests are viewing this topic.

Offline JesterTopic starter

  • Frequent Contributor
  • **
  • Posts: 887
  • Country: ca
Excel - Visual Basic - Tektronix data transfer via USB
« on: October 02, 2016, 12:52:11 am »
I'm attempting to talk with various instruments (tektronix, Agilent etc.) using VB in excel, using this as a starting point:



I have no problem communicating with the scope using the Tektronix excel add-in, to send and receive data, however the

Agilent VB code hangs during initialization.  I want to be able to communicate with other instruments so need a more

generic and flexible method, so I'm giving VB a try.

Using the Agilent code in the spreadsheet (2nd version below), I'm getting the following error when I click the Start button "An IO error occured: HRESULT =

80040011"  This code appears to be a "OLE_E_CANTCONVERT code meaning Not able to convert object.
 

In the Agilent/Youtube example shown in the video the init code is as follows:

Public Sub Intialize_Click()

On Error GoTo ioError
   
    instrAddress = Range("B4").Value
   
    Set ioMgr = New VisaComLib.ResourceManager
    Set instrAny = New VisaComLib.FormattedIO488
    Set instrAny.IO = ioMgr.Open(instrAddress)
 
    Exit Sub

ioError:
    MsgBox "An IO error occured:" & vbCrLf & Err.Description

End Sub


and the code in the supplied spreadsheet is slightly different:

Public Sub Intialize_Click()

On Error GoTo ioError
   
    instrAddress = Range("B4").Value
   
    Set ioMgr = New VisaComLib.ResourceManager
    Set instrAny = New VisaComLib.FormattedIO488
    Set instrAny.IO = ioMgr.Open("DMM3")
     
    Exit Sub

ioError:
    MsgBox "An IO error occured:" & vbCrLf & Err.Description

End Sub


The 3rd Set instruction is the one causing the error.

The 2nd version creates the HRESULT = 80040011 error, and the first version, causes excel to outright crash requiring a restart.

Does anyone have any insight or have experience communicating with an USB based Tektronix instrument from

excel using VB?

The excel file is available here:  https://community.keysight.com/thread/21917
 

Offline Jeff_Birt

  • Regular Contributor
  • *
  • Posts: 198
  • Country: us
Re: Excel - Visual Basic - Tektronix data transfer via USB
« Reply #1 on: October 02, 2016, 02:52:26 am »
The third instruction takes a argument that is the device address. The string "DMM3" can be converted to an understandable address. The variable 'instAddress' is probably not initialized, that is set to a real address, so it is causing an error.
 

Offline JesterTopic starter

  • Frequent Contributor
  • **
  • Posts: 887
  • Country: ca
Re: Excel - Visual Basic - Tektronix data transfer via USB
« Reply #2 on: October 02, 2016, 03:34:44 am »
The third instruction takes a argument that is the device address. The string "DMM3" can be converted to an understandable address. The variable 'instAddress' is probably not initialized, that is set to a real address, so it is causing an error.

I changed:

Set instrAny.IO = ioMgr.Open("DMM3") to Set instrAny.IO = ioMgr.Open("USBInstrument1") and it now works

USBInstrument1 is the VISA Alias from the Keysight connection expert.

Thanks for your help

 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5200
  • Country: nl
Re: Excel - Visual Basic - Tektronix data transfer via USB
« Reply #3 on: October 02, 2016, 10:21:47 am »
Did you notice that the instrument address is pasted in cell B4 on the spreadsheet?
After that it is read by the VB program here:

instrAddress = Range("B4").Value

Then the variable instrAddress is used to open the connection.

So if you put "USBInstrument1" in cell B4 the example should work unmodified.
Keyboard error: Press F1 to continue.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf