Lake Shore Model 642 Electromagnet Power Supply User’s Manual
5-18
Computer Interface Operation
Table 5-5. Visual Basic IEEE-488 Interface Program
Public gSend As Boolean 'Global used for Send button state
Private Sub cmdSend_Click() 'Routine to handle Send button press
gSend = True 'Set Flag to True
End Sub
Private Sub Form_Load() 'Main code section
Dim strReturn As String 'Used to return response
Dim term As String 'Terminators
Dim strCommand As String 'Data string sent to instrument
Dim intDevice As Integer 'Device number used with IEEE
frmIEEE.Show 'Show main window
term = Chr(13) & Chr(10) 'Terminators are <CR><LF>
strReturn = "" 'Clear return string
Call ibdev(0, 12, 0, T10s, 1, &H140A, intDevice) 'Initialize the IEEE device
Call ibconfig(intDevice, ibcREADDR,1) 'Setup Repeat Addressing
Do
Do 'Wait loop
DoEvents 'Give up processor to other events
Loop Until gSend = True 'Loop until Send button pressed
gSend = False 'Set Flag as False
strCommand = frmIEEE.txtCommand.Text 'Get Command
strReturn = "" 'Clear response display
strCommand = UCase(strCommand) 'Set all characters to upper case
If strCommand = "EXIT" Then 'Get out on EXIT
End
End If
Call ibwrt(intDevice, strCommand & term) 'Send command to instrument
If (ibsta And EERR) Then 'Check for IEEE errors
'do error handling if needed 'Handle errors here
End If
If InStr(strCommand, "?") <> 0 Then 'Check to see if query
strReturn = Space(100) 'Build empty return buffer
Call ibrd(intDevice, strReturn) 'Read back response
If (ibsta And EERR) Then 'Check for IEEE errors
'do error handling if needed 'Handle errors here
End If
If strReturn <> "" Then 'Check if empty string
strReturn = RTrim(strReturn) 'Remove extra spaces and Terminators
Do While Right(strReturn, 1) = Chr(10) Or Right(strReturn, 1) = Chr(13)
strReturn = Left(strReturn, Len(strReturn) - 1)
Loop
Else
strReturn = "No Response" 'Send No Response
End If
frmIEEE.txtResponse.Text = strReturn 'Put response in text on main form
End If
Loop
End Sub