Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

asynchonous gpib calls in visual basic

Dose anyone have any example code of a gpib call in visual basic , I am trying to use the IBRDA command to read from a device, and then resynchonise it to the rest of the program, this is beacuse when I want to read from the device, it takes a second or so to read, and with a normal read the entire program just hangs untill the read is finnished.
0 Kudos
Message 1 of 2
(3,143 Views)
Hi Beamer,
A couple of questions on this. First, what version of visual basic?

You could use code smilar to this:
Sub ibrda(ByVal ud As Integer, buf As String)
Dim cnt As Long

' Check to see if GPIB Global variables are registered
If (GPIBglobalsRegistered = 0) Then
Call RegisterGPIBGlobals
End If

cnt = CLng(Len(buf))

Call ibrda32(ud, ByVal buf, cnt)

Call copy_ibvars
End Sub


However there may be some issues with this. With older versions of Visual basic, there was a buffer remaping issue that would make all ibrda calls work likd ibrd calls.

I was unable to determine if this issue has been resolved in VB 6.0 however I can offer a possible workaround if you determine that the same thing is occurring.

One possible workaround is t
o use direct Win32 API functions to lock the buffers being used by these calls. GlobalLock is one function that allows a user to lock the buffer. You might be able to lock the buffer before making a call to ibrda so that Visual Basic cannot change it. Then when the ibrda call completes (that is, ibsta returns a status of CMPL, or ibstop is called, or some error occurs), you can unlock the buffer.

This is quite in depth, and you may want to try spawning threads in VB. To look into this more check out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconapartmentmodelmultithreadinginvisualbasic.asp

Hope this helps out Beamer,

Aaron K.
Application Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,143 Views)