Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Get any/all VISA-USB Addresses

Solved!
Go to solution

I currently use:

Try
myInstr.IO = IoMgr.Open("USB0::0x05E6::0x2636::4351628::INSTR")
Catch ex As Exception
MsgBox("could not connect", vbOKOnly, "error opening connection")
myerror = True
End Try

0 Kudos
Message 1 of 24
(8,763 Views)
0 Kudos
Message 2 of 24
(8,735 Views)

Yes. Before trying any of the examples in VB.Net,  the manual says I need to add a reference to visa32.dll. Visual Studio won't let me do this. BTW, I'm using a 64 bit machine.

0 Kudos
Message 3 of 24
(8,727 Views)

Why are you unable to reference the visa32.dll, we would need more info about what specifically you are seeing to see what recommendations we can provide. 

0 Kudos
Message 4 of 24
(8,720 Views)

Thanks. Sure, here's what happens. See attached.

 

0 Kudos
Message 5 of 24
(8,716 Views)

This seems to be an issue calling the library itself and most cases I've seen with this message seem to require calling the library with DLLimport, below are some examples and documentation for this.

 

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

 

https://docs.microsoft.com/en-us/dotnet/framework/interop/platform-invoke-examples

 

0 Kudos
Message 6 of 24
(8,699 Views)

Hi,

 

In the project properties page set the target CPU to x86

 

Curt

0 Kudos
Message 7 of 24
(8,693 Views)

I've heard about changing the target to x86. I've tried it and it doesn't work for me. Thanks, though.

0 Kudos
Message 8 of 24
(8,685 Views)

I've checked out the pages mentioned and I should tell you that I find Microsoft's Developer website totally unfriendly to beginners. Their explanations are cryptic to me (at best).

I would very much appreciate an example, if possible. I have found that NI does provide some examples, but they are for VB6 and C#. I loved VB6 but it appears to be dying and I can't find it anymore, so I'm trying to learn VB.NET. Here's a header title for NI's C# example:

// Title : MainForm.cs
// Purpose : This application shows the user how to use ResourceManager to
// find all of the available resources on their system. In the example,
// they can select between several filters to narrow the list. Public
// property ResourceName contains the resource name selected in tvwResourceTree
//
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Ivi.Visa;
using NationalInstruments.Visa;

......................

It's kinda like VB but, of course, calls to VISA functions don't work. Any examples VB.NET?

0 Kudos
Message 9 of 24
(8,684 Views)

Hi,

 

Set a reference to the NI Common and VisaNS libraries. Make sure the versions match.

 

SetReference.png

 

Then try something like the code below. An you still need to go to the properties page and set the target to x86!

Good luck

 

Curt

 

Imports NationalInstruments.VisaNS

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim id As String
        Dim resourcename As String

        Dim usbsession As UsbSession


        Try

            ' Add your resource string here
            resourcename = "USB0::0x05E6::0x2601::4018686::INSTR"
            usbsession = New UsbSession(resourcename)

            usbsession.Write("*CLS")
            usbsession.Write("*RST")

            usbsession.Write("*IDN?")
            id = usbsession.ReadString()
            MessageBox.Show("ID = " + id)



        Catch ex As Exception

        End Try
    End Sub
End Class
0 Kudos
Message 10 of 24
(8,679 Views)