Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare GPIB device in VB.NET??

Hi I have a small sample code that I am trying to read and write to a source meter throught GPIB.  It gives an error "type not defined" for NationalInstruments where I am declaring GPIB variable in the public form.  Anyone know how to do this?  I can communicate no problem in VB6, the examples for VB6 that come with the NI488.2 drivers are descent to follow and they have an explanation of the code for each section.  The .NET examples are complete garbage, they don't explain anything at all as far as what they are doing in the code unlike the VB6 examples.  Also the help manual for NI488.2 .NET is not nearly as well written or easy to follow as the non .NET manual is.  If anyone has any ideas that would be great.  It would be nice to actually be able to set up the meter to communicate.  Once I can do that then I can actually trying some things.  This has me going in circles.  NationalInstruments.NI4882 is referenced in my project.  Thanks for your help. 

 

Imports NationalInstruments.NI4882

 

Public
Class Form1

 

Public Keithley_ID As Integer

 Public GPIB As NationalInstruments = New NationalInstruments

Public GPIBCard As Integer

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

Dim Ket_Channel As Integer

Ket_Channel = 26

GPIBCard = 0

Keithley_ID = GPIB.ildev(GPIBCard, Ket_Channel, 0, 10, 1, 0)

 

Dim Command As String

Dim Results As String = ""

 Dim MaxDataToRead As Integer = 200

 

Command = "*IDN?"

GPIB.ilwrt(Keithley_ID, Command, Len(Command))

GPIB.ibrd(Keithley_ID, Results, MaxDataToRead) '

MsgBox(Results)

 

End Sub

End Class

0 Kudos
Message 1 of 6
(8,638 Views)

Looks like you want to decalre your GPIB variable as a "Device" not "NationalInstruments". There are some shipping examples that should help get you on your feet. They are located here:

Win 7/Vista - C:\Users\Public\Documents\National Instruments\NI-488.2\Examples\DotNET3.5\

Win XP - C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\DotNET3.5\

 

 Let me know if this helps.

 

Regards,

Message Edited by Support on 01-07-2010 03:02 PM
---

Peter Flores
Applications Engineer
0 Kudos
Message 2 of 6
(8,614 Views)

it it also giving error to

Private GpibDevice As Device and

GpibDevice = New Device(CInt(boardIdNumericUpDown.Value), CByte(primaryAddressNumericUpDown.Value), CByte(currentSecondaryAddress))

please give me better solution for this.

0 Kudos
Message 3 of 6
(7,683 Views)

@143143143 wrote:

it it also giving error to

Private GpibDevice As Device and

GpibDevice = New Device(CInt(boardIdNumericUpDown.Value), CByte(primaryAddressNumericUpDown.Value), CByte(currentSecondaryAddress))

please give me better solution for this.


What exactly is the error you are getting?

 

0 Kudos
Message 4 of 6
(7,677 Views)

this code give error 

 

Imports NationalInstruments.NI4882

Public Class Form1

Public Keithley_ID As Integer
Public GPIB As NationalInstruments = New NationalInstruments
Public GPIBCard As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Ket_Channel As Integer
Ket_Channel = 26
GPIBCard = 0
Keithley_ID = GPIB.ildev(GPIBCard, Ket_Channel, 0, 10, 1, 0)

Dim Command As String
Dim Results As String = ""
Dim MaxDataToRead As Integer = 200

Command = "*IDN?"
GPIB.ilwrt(Keithley_ID, Command, Len(Command))
GPIB.ibrd(Keithley_ID, Results, MaxDataToRead) '
MsgBox(Results)

End Sub
End Class

 

error in this line

 

Public GPIB As NationalInstruments = New NationalInstruments

 

error is 

 

Type expected.

 

please give solution

 

Thanks

0 Kudos
Message 5 of 6
(7,664 Views)

error in this line

 

Public GPIB As NationalInstruments = New NationalInstruments

 

error is 

 

Type expected.

 

please give solution

 

Thanks


That gives an error because that is wrong. Why do you insist on doing something that you were told is wrong?


Did you try the examples linked by pflores?

 

Did you try the solution suggested by pflores?

 

 

0 Kudos
Message 6 of 6
(7,653 Views)