12-10-2013 06:50 PM
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.
Solved! Go to Solution.
12-11-2013 05:05 PM
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.
12-12-2013 04:16 PM
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.