ETS-Lindgren 2090 Controller User Manual
Page 93

Model 2090 Multi-Device Controller
'
' This function handles service requests detected during writes.
' The GPIB card must be configured for Auto Serial Polls in order
' for this function to work properly.
'
Sub ibwrite(device%, data$)
ibwrt device%, data$ ' Write data to GPIB port
If (ibsta And RQS) Then ServiceRequest device% ' Handle any request for service
End Sub
'
' This function performs a seek to reach a particular position.
' It waits until the seek is completed and updates the display.
' It will attempt to get within one cm/degree of the target value
' and retry up to five times if it fails.
'
Sub SeekPosition(Position As Single, device%, DeviceEdit)
Dim count As Integer
count = 0
While count < 5
ibwrite device%, "SK " + Str$(Position) ' Send seek command
WaitForStop device%, DeviceEdit ' Wait for completion of seek
If Abs(GetCurrentPosition(device%) - Position) < 1 Then Exit Sub
count = count + 1
Wend
MsgBox "The device failed to reach its target position after five tries.", 0, "Seek Error"
'
' Note that code could be added to this routine to handle any errors
' generated (such as trying to seek outside of the current limits)
'
End Sub
'
' This function responds to a service request by performing a serial poll of
' the affected device and then determining and reporting the cause of the
' service request. This process also clears the error condition from the
' controller.
'
Sub ServiceRequest(device%)
Read$ = Space$(20)
ibrsp device%, spr% ' Serial poll the device to clear RQS
' and determine what caused the SRQ
If (spr% And 32) Then ' A bit in the Event Status Register is set
ibwrt device%, "*ESR?" ' Query the Event Status Register
ibrd device%, Read$ ' Read response
ESR = Val(Read$) ' And get value
If (ESR And 32) Then ' Command Error
Msg$ = "The previous command was invalid. This error" + Chr$(13)
Msg$ = Msg$ + "is normally caused by a mistake in the program."
©ETS-Lindgren, April 2006
93
Revision G– P#399199