Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read from a gpib device in Visual Basic

Solved!
Go to solution

I'm having trouble reading from my device. Can anyone give me an example so I can correct my code?POWER METER READ.jpg

0 Kudos
Message 1 of 13
(7,244 Views)
I think that all you have to do is write a command to the instrument to perform a measurement before you do a read. You do not mention the make and model of the instrument so you will have to study the manual. If the instrument uses SCPI, then the command will terminate with a '?'. This tells the instrument to read and place the results in the output buffer. Until you do something like that, the output buffer is empty.
0 Kudos
Message 2 of 13
(7,242 Views)

Hi,

 

I don't know what type of instrument you're using, but you probably need to send it a read or measure command, then wait for the command to to be processed and then get the data.

 

maybe something like...

 

PowerMeter.Write("Read?")

PowerMeter.WaitForCommandComplete

PowerMeter.ReadString(strData)

 

Try that

 

Curt

 

0 Kudos
Message 3 of 13
(7,240 Views)

Thanks for your help, I have been working with this some more. The device is a Hewlett Packard model 431B microwave power meter. The signal source is the reference (calibration) oscillator which is turned on by “OC1”. At this time the device is in remote-LISTEN. As soon as the PowerMeter.ReadString (PowerLevel) cmd is sent the device switches to TALK but when the MsgBox comes up the power level string is not displayed. I have been through the manual and reviewed the command set. There is no actual “READ” command that I can discover. If I try to send PowerMeter.Write (“READ”) the device thinks it’s the REsolution command and responds accordingly.

 

I have addressed the device in the Interactive Control mode of the NI488.2 with the  ibrd 11 command  and the display string is returned perfectly, so that works. I just don’t know what is different.

 

The PowerMeter.Wait command causes problems. I can’t get the syntax right so I left it out. Please see example.POWER METER READ-2.jpg

0 Kudos
Message 4 of 13
(7,215 Views)

Hi,

 

You need to send some sort of trigger command to the device to start a measurement and load data into the output buffer so you can then read it.

 

Try writing one of these commands before you use the ReadString method...

 

"GET"

"GT1"

"GT2"

 

or

"TR1"

"TR2"

"TR3"

 

Hope this helps

 

Curt

0 Kudos
Message 5 of 13
(7,212 Views)
What you could also do is perform NI-Spy captures of your interactive session and the VB code. You can attach them here.
0 Kudos
Message 6 of 13
(7,209 Views)

Hi – I have followed your advice.

The power meter does have trigger commands. TR0 is standby, TR1 is trigger immediate, TR2 is trigger with delay and TR3 is trigger free run.  According to the manual when TR1 or TR2 is called a measurement is taken and the display and the HP-IB bus data are updated. When TR3 is called the power meter makes continuous measurements and updates the display until placed back in standby. I placed the trigger command in the line before the PowerMeter.ReadString(PowerLevel) is called and tried each one (including GET) but the string is still not returned in the MsgBox. I also ran a short version through NI-SPY (attached) but am unable to understand why the VB version doesn’t work. Do you have any other suggestions?

 

POWER METER READ SPY.jpg

0 Kudos
Message 7 of 13
(7,184 Views)
All you did was attach some images. Please attach the actual NI-Spy files like I originally said (both of them).
0 Kudos
Message 8 of 13
(7,182 Views)

Sorry.

I have the files of course but being new to the forum concept I don't know how to attach them.

Can you tell me how? 

0 Kudos
Message 9 of 13
(7,176 Views)

Hi,

 

I should have caught this on your first post

 

Try

 

 

Dim strRead as String

 

strRead = PowerMeter.ReadString()

 

MessageBox.Show(strRead)

 

or

 

MessageBox.Show(PowerMeter.ReadString())

 

 

Curt

 

 

0 Kudos
Message 10 of 13
(7,172 Views)