Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot access a disposed object- Visual Studio Express 2010 .net GPIB Commands

Solved!
Go to solution

I am using the 488.2 examples for VS2010. This example is the SimpleAsynchronousReadWrite template.

 

I can run the template fine and and I can write to my instrument without any issues. I'm trying to move the commands over to a sequence to emulate what I would normally do using the front panel of the VNA.

 

My Goal:

1. OPEN

2. Write *din?\n

3. String Read

4. CLOSE

 

Keep in mind, I simply pasted all the commands into a sequence with 500ms pauses.

 

4. Returns the error "Cannot access disposed object'

 

 

Private Sub sequenceButton_Click(sender As System.Object, e As System.EventArgs) Handles sequenceButton.Click

        Threading.Thread.Sleep(500)

        '******************************************
        'OPEN SESSION
        Try
            Windows.Forms.Cursor.Current = Cursors.WaitCursor
            Dim currentSecondaryAddress As Integer

            If secondaryAddressComboBox.SelectedIndex <> 0 Then
                currentSecondaryAddress = secondaryAddressComboBox.SelectedItem
            Else
                currentSecondaryAddress = 0
            End If

            GpibDevice = New Device(CInt(boardIdNumericUpDown.Value), CByte(primaryAddressNumericUpDown.Value), CByte(currentSecondaryAddress))

#If NETFX2_0 Then
            'For .NET Framework 2.0, use SynchronizeCallbacks to specify that the object 
            'marshals callbacks across threads appropriately.
            GpibDevice.SynchronizeCallbacks = True
#Else
                'For .NET Framework 1.1, set SynchronizingObject to the Windows Form to specify 
                'that the object marshals callbacks across threads appropriately.
                GpibDevice.SynchronizingObject = Me
#End If


            SetupControlState(True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            Windows.Forms.Cursor.Current = Cursors.Default
        End Try
        '***********************************************
        'OPEN SESSION IS DONE

        GpibDevice.Write("*idn?")

        Threading.Thread.Sleep(500)

        'READ AND PRINT TO MESSAGE BOX
        Try
            GpibDevice.BeginRead(New AsyncCallback(AddressOf OnReadComplete), Nothing)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        'READ AND PRINT TO MESSAGE BOX - END

        Threading.Thread.Sleep(500)
        GpibDevice.Dispose()


        'CLOSE THE SESSION
        Try
            GpibDevice.Dispose()
            SetupControlState(False)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        'CLOSE THE SESSION -END


    End Sub

 I'm pretty sure this is a syntax problem.

 

Thanks for any help.

 

Download All
0 Kudos
Message 1 of 3
(7,200 Views)

Hello High-Q

 

I just found a couples of differences between the original example and this post. You removed "ByVal" from the parameters and you are implementing the writing different (GpibDevice.write instead of GpibDevice.BeginWrite). Is there any special reason for that? What debugging methods are you trying or what have you found? Have you tried to modify just one line and test the little change immediately?

 

Regards

Frank R.

0 Kudos
Message 2 of 3
(7,173 Views)
Solution
Accepted by topic author high-Q

I found the problem. It is related to Visual Studio Express 2010. I was using 'CTRL+C' and 'CTRL+V' from an existing button. The compiler does not like that. At the end, creating this sub routine in a new button from the tool box fixed the problem.

0 Kudos
Message 3 of 3
(7,164 Views)