Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VB.net MessageBasedSession questions

I am trying to convert the SimpleReadWrite(located C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\.NET\SimpleReadWrite)  C code example for talking to a USB device and I am having some issues, the example work fine it just may be my conversion may be wrong any help would be apreciated.

 

This is the code I have,

 

 

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Try
            Dim rscName As String = "USB0::0x0B21::0x0025::4332514C323730353856::INSTR" 'Actaul name of resource

            Dim rm As ResourceManager = New ResourceManager()

            mbSession = DirectCast(rm.Open(rscName), MessageBasedSession)


            Dim textToWrite As String = "*IDN?\n" 'Standard ID query

            mbSession.RawIO.Write(textToWrite)

            Me.ListBox1.Items.Add(mbSession.RawIO.ReadString())


        Catch ex As Exception
            GenPrcs.ErrorHndl(ex)
        End Try
    End Sub

 

everything works fine until the mbsession.rawio.readstring and then i get this error

 

Capture4.JPG

 

again any help would be much aprriciated. Thanks and have a great day

0 Kudos
Message 1 of 10
(5,164 Views)

When running an unmodified example were you getting any errors (if so, what were they)?

 

Are you able to read and write at all with your device?

0 Kudos
Message 2 of 10
(5,122 Views)

The original runs perfect it is just coded in C and when I convert it I beleive something is missing. I am using the example that National Istruments installs which I have attached.

0 Kudos
Message 3 of 10
(5,107 Views)

What kind of USB device are you trying to connect to?

0 Kudos
Message 4 of 10
(5,080 Views)

I am using a Prologix USB to GPIB converter to communicate to a Yokogawa WT310 Power Analyzer. I don't beleive it is a hardware issue since with eh example program attacheced to the previous post it works just fine, I think I am loosing something in the conversion fron C to VB.net becuase the error is a time out error when I sent the command mbSession.RawIO.ReadString().

0 Kudos
Message 5 of 10
(5,075 Views)

Sorry the previous post is not correct, I am connecting to a Yokogawa WT310 through a USB port and sending standard IEEE GPIB command to it. Sorry for the confusion I am also working on a power supply that uses the Prologix to communicat.

0 Kudos
Message 6 of 10
(5,073 Views)

I’m assuming you have the correct drivers installed since you said the example code works fine.

 

Do you have NI Measurement Studio? If you do, you can access a SimpleReadWrite example that’s already converted.

 

Looking at the error, it appears that nothing is responding to the ReadString(). Is it possible that the instrument name is has an error in it?

0 Kudos
Message 7 of 10
(5,045 Views)

Ok problem solved, it appears that some spaces were being attached to the name of the resource for no appearent reason, so after adding a trim to the device name it works perfectly. Thank you to all that responded to this question, sometimes it takes questions from others to make youself ask questions and it can lead to the right answers. Thanks and have a great day.

0 Kudos
Message 8 of 10
(5,032 Views)

I have solved this issue can a moderator mark this as solved. Thank you to all that helped and have a great day.

0 Kudos
Message 9 of 10
(4,990 Views)

i know this is an old post but I am having the same issue converting the example to VB,net

can some one post the solution for converting the C example to VB,.net.

thanks in advance 

 

0 Kudos
Message 10 of 10
(2,582 Views)