From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Read trace data from spectrum analyser using NI-VISA in Excel 2010

I am trying to update a trace-capture function into Excel 2010 (VBA7) and am fairly close... I can find and connect to the instrument and query to get string results. But can't seem to get a nice implementation that replaces the old ilrdi function from NI-488.  I am using a reasonably up-to-date set of NI-VISA drivers (5.3?) as I am also developing code in VS2012 - I can't even confirm whether these are compatible with VBA7.  Please be patient, I started coding in the days of DOS and last updated the code using VB6 and NI-GPIB488 - the world has changed since then!  I had effectively the same problem with NI-488.2 where I couldn't work out how to use the 488.2 function to read the results directly into an array...

 

In my mind I guess that something like:

Dim sglYData() as Single

...

sglYData = ...ReadNumber()

 

but I can't seem to crack it.

 

My code snippets are shown below:

 

This works to read the data in as a string which I then have to decode byte-by-byte and is not elegant.  I would rather read straight into an array of real (Single) numbers as you used to be able to do with using sglYdata()=ildri(....).

 

        If gErr = False Then gErr = Eqpt_Write("FORM REAL,32;FORM:BORD SWAP", VGb)
        If gErr = False Then gErr = Eqpt_Write("TRACE:DATA? TRACE1", VGb)
        'Read the number of bytes point
        'strResult = Eqpt_Read(2, VGb)
        If gErr = False Then iDigits = Val(Mid(Eqpt_Read(2, VGb), 2, 1))
        'Get the total number of bytes
        If gErr = False Then lngTraceBytes = Val(Eqpt_Read(iDigits, VGb))
        'Read the trace data from the analyser as a string...
        If gErr = False Then strResult = Eqpt_Read(CInt(lngTraceBytes), VGb)
        Debug.Print strResult

 

For reference, the Eqpt_Read function just does this:

Function Eqpt_Read(iLen As Integer, VGb As VisaComLib.FormattedIO488, Optional blnNoEOICheck As Boolean) As String
    Dim strData As String
'    strData = Space(iLen)
   
    strData = VGb.IO.ReadString(iLen)
    If gErr = False And strData <> "" Then
        If blnNoEOICheck = False And InStr(strData, Chr(10)) > 1 Then
            Eqpt_Read = Left(strData, InStr(strData, Chr(10)) - 1)
        ElseIf strData <> "" Then
            Eqpt_Read = strData
        Else
            Eqpt_Read = ""
        End If
    Else
        Eqpt_Read = ""
    End If
End Function

0 Kudos
Message 1 of 3
(4,561 Views)

Hi EMCMan,

 

Sorry for the delay in a reply to your question, Im just posting to let you know that I'll be looking into this for you now. Hopefully I can help you find a solution to your problem if you haven't already. First I'll look into the compatibility.

 

If you have any information to add please feel free to post it. I'll be monitoring this thread and will pick up on anything thats posted.

 

Kind regards,

Matt H
Applications Engineer
National Instruments UK
0 Kudos
Message 2 of 3
(4,465 Views)

Hi EMCMan,

 

Do you have access to Labview or Measurement Studio? In particular measurement studio, our add on for Visual Studio would allow you to perform this function. 

 

Kind regards,

Matt H
Applications Engineer
National Instruments UK
0 Kudos
Message 3 of 3
(4,443 Views)