LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIB Issues...

I am unfamiliar with SCPI or rather using the GPIB commands with CVI.  I don't really know what I am talking about, but that is what I am writing to the support center.  First off, I have a Tektronix DPO4034 oscilloscope that I can interface with my PC via USB.  I would like to write software in CVI that can send commands SCPI commands to the oscilloscope for test purposes.  Where do I start?  When I say this, I mean how do I write the software to open the USB port to com with the oscilloscope, what functions do I use in CVI, etc.  I need a crash course badly.  To get me started, I would like to send a generic SCPI command '*IDN?' to identify the oscilloscope just to know that I have something working.  I take it you don't use the 'OpenComConfig' function and the subsequent ComWrt and ComRd functions.  Someone, throw me a line here...  BTW, do I need some intermediate device in between the oscilloscope and PC?  I have them directly connected currently.  Maybe this is something I have done wrong initially? 
0 Kudos
Message 1 of 8
(4,792 Views)

First of all, you should download the driver for your instrument, which is available in the Instrument Driver Network. I'm not famialiar with your scope, but usually the drivers come with some documentation and a little example on how to use it, so it possibly will answer some of your questions.

 

A basic question on your instrument is the connection method between the PC and the scope, since the driver has been developed to handle the communications via GPIB, US or serial cable. In particular is not clear from your message if you are using GPIB or USB, or maybe an USB-to-GPIB adapter (if not a USB-to-serial adapter...) Smiley Surprised



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 8
(4,782 Views)
I do have the drivers for my oscilloscope installed on the computer (no device conflicts in Windows device manager - the scope is recognized by the PC).  The DPO 4034 comes with a version of NI Signal Express which works as intended.  All that I am doing to interface myself with the software and the scope is using a direct USB cable between the scope and PC.  Now, I want to take it to the next step and try to write some software routines in CVI to communicate, control, etc. with the scope via SCPI commands.  What's the first thing I should do to creating software handlers that reference the device that I am connected to using a SCPI protocol to com? 
0 Kudos
Message 3 of 8
(4,770 Views)
The instrument driver is a library of C functions, which communicate with the device using SCPI commands. So there is no need to write your own "instrument driver".  As Roberto allready pointed out, have a look at the example coming with the driver to see how to start with the instrument driver.
0 Kudos
Message 4 of 8
(4,752 Views)

Hi Chris,

 

Here is the link to the driver for your scope. It says the driver also supports connection over USB.

 

In that driver download page it also says you need IVI Compliance Package 3.1 and NI-VISA 4.2 too.

So you have to download or find them from some other CDs and install before the driver.

 

In the driver, look for an "initialize" function. It is the first function to call to initiate the communication.

It returns a handle to be used for all subsequent function calls.

The initialize function needs a "resource string" to connect to the instrument.

See here for constructing a valid resource string.

The details (ID codes) you need to put inside the resource string may be found in the advanced properties tab under Device Manager.

 

OpenComConfig, ComWrt and ComRd are functions specific to serial (RS-232 and alike) communication.

So if you are connecting the scope directly to the USB port (without a USB-to-RS232 converter) you will not need them.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 8
(4,748 Views)

Thank you for your help.  I have the example program up and running.  My intention for learning about this is for an embedded project that is under develpoment where there is a SCPI parser built into the firmware.  I am at a point where I will have to write software routines in CVI that will communicate with this module.  The only thing I have around my office is a Tektronix scope that uses can communicate using a SCPI protocol, so I figured why not look at how this device interfaces with my PC using LabWindows.  I wonder if I can create a simple generic method using some snippets of code to start a simple VI session with the DPO4034 scope.  I essentially want to use something like a viBufWrite and viBufRead function to make generic messages.  I would prefer to experiment with the scope usign my 'generic' SCPI program first before I take this somewhere else - to the module under development. 

 

The issue that I am running into trying to use a generic write or read function (viWrite..., viRead...) is that it says the my session or object is invalid.  I set up a viBufWrite command like this:

 

viBufWrite(vi,"*IDN?",outCount,&inCount);

 

... where 'vi' is a valid session when used in any other function - returned value from 'tkdpo4k_InitWithOptions' function as an output parameter, "*IDN?" is my string I would like to see what it does when written, outCount is of type ViUInt32 and initilalized to be the sizeof the string "*IDN?", and inCount is of type ViUInt32 to store the number of written bytes.  Why doesn't this work?  It seems straight forward enough.  I call this function immediately after the 'tkdpo4k_InitWithOptions' function completes execution.  Why would the session be invalid?  It is not closed, cleared, nothing.  When other CVI functions are called using this sessionID, the program doesn't seem to skio a beat, but for some reason, I can't write communication commands.  Hey, at least now I am a little more further ahead than when I last tried to get these things going thanks to the example program.  

0 Kudos
Message 6 of 8
(4,726 Views)

Chris,

 

I assume you declared "vi" like: " ViSession   vi ; " in the beginning of your code.

 

1) Does the returned value of calling this function tkdpo4k_InitWithOptions(...., &vi) == VI_SUCCESS ?

     If not, you don't have the correct session name assigned in "vi".

2) When calling tkdpo4k_InitWithOptions(....), did you use the correct resource name that looks like

    this: "USB0::0x0699::0x036A::C034102::INSTR"?  This resource name is assigned in the NI-MAX

    to identify the scope when it is successfully connected to your PC via USB cable.  If you don't have

    the correct resource name, you won't have the correct session id.  If you didn't see a resource name

    automatically assigned in NI-MAX, the scope isn't recognized by your PC.

Message Edited by dcl9000 on 03-30-2010 06:36 PM
0 Kudos
Message 7 of 8
(4,669 Views)

You have to initiate a VISA session to use those functions, I am uncertain if the handle you are getting from the driver function really is a VISA handle that you can use directly with the VISA functions.

 

If you want to get back to the very basics, you need to call the viOpenDefaultRM () to get a resource manager handle and then viOpen () to get a valid handle for a VISA session with your instrument. That is the handle to pass to the viWrite () and viRead () functions.

 

Good practice is to then call viClose () on the resource manager and session handles when you are finished communicating with the device.

 

If you want to use the driver, there usually is a pair of functions in most instrument drivers that allow you to communicate directly with the instrument. Look for functions similar to 'tkdpo4k_Read () and tkdpo4k_Write (), if they exist they are likely in a Low-Level control or miscellaneous category in the driver function tree.

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
Message 8 of 8
(4,590 Views)