NI Home > Community > NI Discussion Forums

Instrument Control (GPIB, Serial, VISA, IVI)

Reply
Member
snwbrdr
Posts: 15
0 Kudos

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

Active Participant
pflores
Posts: 250
0 Kudos

Re: How to declare GPIB device in VB.NET??

[ Edited ]

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
Member
143143143
Posts: 2
0 Kudos

Re: How to declare GPIB device in VB.NET??

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.

Active Participant nyc
Active Participant
Posts: 1,912
0 Kudos

Re: How to declare GPIB device in VB.NET??


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?

 

Member
143143143
Posts: 2
0 Kudos

Re: How to declare GPIB device in VB.NET??

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

Active Participant nyc
Active Participant
Posts: 1,912
0 Kudos

Re: How to declare GPIB device in VB.NET??

[ Edited ]

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?