Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

error handling with VB.NET 2005

I am pretty new to .NET and I am trying to write an error handling loop to make sure my reads and writes to my instruments  are ok.

Does anyone have some examples of code on how to do this? 

 

Here is a copy of the read function I am creating:

 

Public Function Read(ByVal strInstrument As String) As String
        Dim strRead As String
        Dim strerr As String

        Try
            mbSession = CType(ResourceManager.GetLocalManager().Open(strInstrument), MessageBasedSession)
            strRead = mbSession.ReadString()
        Catch exp As Exception
            strerr = exp.ToString
            MessageBox.Show(exp.Message & strInstrument, "GPIB READ ERROR")
        End Try
        mbSession.Dispose()
        Return (strRead)

End Function

 

Thanks in advance,

Michael

0 Kudos
Message 1 of 2
(3,492 Views)

Mike,

 

When you install the NI-VISA driver, examples are installed by default to C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples .  I was able to find a SimpleReadWrite example in the DotNET3.5\SimpleReadWrite\VB folder that shows how to read/write and handle errors properly.  The code you posted looks good...is it able to run properly?

Eric B.
National Instruments
0 Kudos
Message 2 of 2
(3,473 Views)