06-16-2011 06:41 AM
I'm writing a vb.net program controlling a Keithly SMU via a NI gpib-usb-hs card.
One of the first steps is to locate available instruments.
I have tried using the following code:
Imports NationalInstruments
Public Class cKeithley
Public Function AvailableInstruments() As List(Of Integer)
Dim availInstr As New List(Of Integer)
Dim gpib As New NationalInstruments.NI4882.Board(1)
Dim adrLst As NationalInstruments.NI4882.AddressCollection = gpib.FindListeners
For Each adr As NationalInstruments.NI4882.Address In adrLst
availInstr.Add(adr.PrimaryAddress)
Next
Return availInstr
End Function
End Class
Several problems arise:
1. I have to specify address 1 in the constructor call to the board otherwise I get an out of range exception ("
Dim
gpib AsNew NationalInstruments.NI4882.Board(1)")
and more importantly
2. In the code above the FindListeners call gives a CIC exception.
Why isn't the gpib board CIC?. No other cards are plugged into the computer.
/mijq
06-16-2011 08:07 AM
Imports NationalInstruments
Public Class cKeithley
Private gpib As NI4882.Board
Private mDevice As NI4882.Device
Public Function AvailableInstruments() As List(Of Integer)
Dim availInstr As New List(Of Integer)
If CheckForBoards() Then
Dim adrLst As NI4882.AddressCollection = gpib.FindListeners
For Each adr As NI4882.Address In adrLst
availInstr.Add(adr.PrimaryAddress)
Next
End If
Return availInstr
End Function
Private Function CheckForBoards() As Boolean
Dim availBoards As New List(Of Integer)
For i As Integer = 0 To 5
Try
gpib = New NI4882.Board(i)
availBoards.Add(i)
Catch ex As Exception
End Try
Next
If availBoards.Count = 0 Then
MessageBox.Show("No GPIB card")
Return False
ElseIf availBoards.Count = 1 Then
gpib.PrimaryAddress = availBoards(0)
mDevice = New NI4882.Device(gpib.PrimaryAddress, 1)
Return True
ElseIf availBoards.Count > 1 Then
MessageBox.Show("More than one GPIB card!")
Return False
End If
End Function
End Class
OK, found a sort of solution myself (se code)
/mijq
08-02-2012 03:27 PM
Hi mijq , can you give a link toward the source of this code snippet? I'm hoping that they have some more examples of using ni4882.dll in .NET