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.