Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

simple vb6 (visual basic 6) gpib example code

I am looking for sample code that shows simple communication to an instrument over GPIB
using Visual Basic 6.
 
In the code that I have inherited, the programmer does a SendIFC32() and a ibsre() to
initalize the GPIB board and that is all.  Is this all that is required or should other commands
be done?
 
I come from the world of LabVIEW where I would all I had to do was a VISA_Open.
What is the equivalent in the Visual Basic world? We don't have Measurement Studio.

Message Edited by nyc on 02-14-2006 05:10 PM

0 Kudos
Message 1 of 9
(14,076 Views)

If you are already familiar with VISA, use it from VB6 too. Especially VISA COM API is easy to use from VB6.  VISA COM will work with NI-VISA 3.x or later.

From VB6's Project | References menu, add a reference to VISA COM 3.0 Type Library (C:/VXIpnp/VisaCom/GlobMgr.DLL).   Then you can use the following VISA calls.

Private Sub Command2_Click()
    Dim rm As IResourceManager
    Dim msg As IMessage
    Dim rd As String
    
    Set rm = CreateObject("VISA.GlobalRM")
    Set msg = rm.Open("GPIB0::2::INSTR")
   
    msg.Clear
   
    msg.WriteString "*IDN?" & vbLf
    rd = msg.ReadString(100)
   
    msg.WriteString ":MEAS:VOLT?" & vbLf
    rd = msg.ReadString(100)
   
    msg.Close

End Sub

You can also hook up any I/O errors such as "No Listener" or "Timeout" errors by ON ERROR GOTO statement.

Message 2 of 9
(14,068 Views)

That is very helpful!

Can I mix the VISA with the older commands such as SendIFC() and ibsre() ?

0 Kudos
Message 3 of 9
(14,060 Views)

It is possible to mix old NI-488.2M API and VISA, but not recommended.  VISA COM has replacement methods for IEEE488.2M SendIFC() and ibsre() on the IGpibIntfc interface.

First you must create a board-level GPIB session using "GPIB0::INTFC" VISA address.  The session can be created separately with typical "GPIB0::x::INSTR" sessions at the same time.  Then, use SendIFC() and ControlREN() methods for IGpibIntfc interface.

Dim gpIntfc As IGpibIntfc
Set gpIntfc = rm.Open("GPIB0::INTFC")
gpIntfc.SendIFC
gpIntfc.ControlREN GPIB_REN_ASSERT
...
gpIntfc.Close

However, board-level functions such as sending IFC signal and/or enabling/disabling REN line are not needed for typical GPIB applications.  These mono-line messages are set up when the device driver or the I/O library DLL is being loaded. 

0 Kudos
Message 4 of 9
(14,048 Views)

I tried the example today (just letting it query the IDN) in order to help a customer trying to access our devices from within VB6. Did not work. Smiley Surprised

Customer has the same problem. Device does not respond or the response is not read with msg.ReadString(100).

 

As a comparison, I also tried this in LabView (VISA Find, Write, Read, Close) and with the NI Communicator. These both worked, but the NI Spy gave three different log result

for all three methods. Smiley Sad

 

Question now is: what is correct way to access GPIB with or without VISA?

 

 

0 Kudos
Message 5 of 9
(10,243 Views)

t operating system (version of windows) are you on. If windows 7 or 8, VB6 is running in virtual mode and will not access hardware...

0 Kudos
Message 6 of 9
(10,239 Views)
Windows 7. OK, so I can not verify this. Thanks!
0 Kudos
Message 7 of 9
(10,215 Views)

Maik,

 

What command did you send to the instrument? The NI-MAX's instrument searcher normally sends an *IDN? command with LF(0x0A) termination, and the instrument normally responds as long as it is IEEE-488.2/SCPI compliant.

 

Also what error code (or exception) was raised in the VB code? You can also see the error status by capturing the traffic with the NI-SPY program and what error log was recorded?

 

Makoto

0 Kudos
Message 8 of 9
(10,211 Views)

As I wote above, the IDN query.

I tried three different ways and logged with NI Spy. First was NI Communicator, second was LabView with VISA VIs and third was VB6 example. All gave different result in the log.

Only LabView and Communicator worked.

 

In VB6, there was no error. It just got no response from the devicse, which could also be seen in the log, but the command was sent through the driver.

 

But from the log I saw that the Communicator used "ib" commands, rather than the other two tests. Then I found a document from NI regarding GPIB access with those "ib" commands and forwarded it to the customer to use it in VB6. No response so far, but I guess it worked, rather than using those VISA objects.

0 Kudos
Message 9 of 9
(10,202 Views)